stamblerre / gocode

An autocompletion daemon for the Go programming language
MIT License
394 stars 28 forks source link

Autocomplete/intellisense <=50% success rate with gocode-gomod #17

Closed ramya-rao-a closed 4 years ago

ramya-rao-a commented 5 years ago

From @gabstv on November 29, 2018 12:25

With the same source code, the intellisense fails to bring relevant results at least 50% of the time.

This happens with the default gocode that VSCode uses.

go version go1.11 darwin/amd64

Run 1 - no suggestions

2018/11/29 10:14:13 Got autocompletion request for '/Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go'
2018/11/29 10:14:13 Cursor at: 4122
2018/11/29 10:14:13 -------------------------------------------------------
package gcs

import (
    "image"

    "github.com/gabstv/ecs"
    "github.com/gabstv/groove/pkg/groove"
    "github.com/gabstv/groove/pkg/groove/common"
    "github.com/hajimehoshi/ebiten"
)

// AnimClipMode determines how time is treated outside of the keyframed range of an animation clip.
type AnimClipMode byte

const (
    // AnimOnce - When time reaches the end of the animation clip, the clip will automatically
    // stop playing and time will be reset to beginning of the clip.
    AnimOnce AnimClipMode = 0
    // AnimStop - When time reaches the end of the animation clip, the clip will automatically
    // stop playing and time will be locked to the last played frame.
    AnimStop AnimClipMode = 1
    // AnimLoop - When time reaches the end of the animation clip, time will continue at the beginning.
    AnimLoop AnimClipMode = 2
    // AnimPingPong - When time reaches the end of the animation clip, time will ping pong back between beginning
    // and end.
    AnimPingPong AnimClipMode = 3
    // AnimClampForever - Plays back the animation. When it reaches the end, it will keep playing the last frame
    // and never stop playing.
    //
    // When playing backwards it will reach the first frame and will keep playing that. This is useful for additive
    // animations, which should never be stopped when they reach the maximum.
    AnimClampForever AnimClipMode = 4
)

const (
    SpriteAnimationPriority int = -6
)

var (
    spriteanimationWC = &common.WorldComponents{}
)

func init() {
    groove.DefaultComp(func(e *groove.Engine, w *ecs.World) {
        //SpriteComponent(w)
    })
    groove.DefaultSys(func(e *groove.Engine, w *ecs.World) {
        //SpriteSystem(w)
    })
}

type SpriteAnimation struct {
    Enabled     bool
    Play        bool
    ActiveClip  int
    ActiveFrame int
    Clips       []SpriteAnimationClip
    T           float64
    // Default fps for clips with no fps specified
    Fps float64

    // caches
    lastClipsLen int
    clipMap      map[string]int
}

type SpriteAnimationClip struct {
    // The name of an animation is not allowed to be changed during runtime
    // but since this is part of a component (and components shouldn't have logic),
    // it is a public member.
    Name   string
    Frames []image.Rectangle
    Fps    float64
    ClipMode AnimClipMode
}

// SpriteAnimationComponent will get the registered sprite anim component of the world.
// If a component is not present, it will create a new component
// using world.NewComponent
func SpriteAnimationComponent(w *ecs.World) *ecs.Component {
    c := spriteanimationWC.Get(w)
    if c == nil {
        var err error
        c, err = w.NewComponent(ecs.NewComponentInput{
            Name: "groove.gcs.SpriteAnimation",
            ValidateDataFn: func(data interface{}) bool {
                _, ok := data.(*SpriteAnimation)
                return ok
            },
            DestructorFn: func(_ *ecs.World, entity ecs.Entity, data interface{}) {
                sd := data.(*SpriteAnimation)
                sd.Clips = nil
            },
        })
        if err != nil {
            panic(err)
        }
        spriteanimationWC.Set(w, c)
    }
    return c
}

// SpriteAnimationSystem creates the sprite system
func SpriteAnimationSystem(w *ecs.World) *ecs.System {
    sys := w.NewSystem(SpriteAnimationPriority, SpriteAnimationSystemExec, spriteanimationWC.Get(w))
    if w.Get(DefaultImageOptions) == nil {
        opt := &ebiten.DrawImageOptions{}
        w.Set(DefaultImageOptions, opt)
    }
    sys.AddTag(groove.WorldTagUpdate)
    return sys
}

// SpriteAnimationSystemExec is the main function of the SpriteSystem
func SpriteAnimationSystemExec(dt float64, v *ecs.View, s *ecs.System) {
    world := v.World()
    matches := v.Matches()
    spriteanimcomp := spriteanimationWC.Get(world)
    globalfps := ebiten.CurrentFPS()
    //engine := world.Get(groove.EngineKey).(*groove.Engine)
    for _, m := range matches {
        spranim := m.Components[spriteanimcomp].(*SpriteAnimation)
        if !spranim.Enabled || !spranim.Play {
            continue
        }
        clip := spranim.Clips[spranim.ActiveClip]
        localfps := nonzeroval(clip.Fps, spranim.Fps, globalfps)
        localdt := (dt * localfps) / globalfps
        spranim.T += localdt
        if spranim.T >= 1 {
            // next frame
            nextframe := spranim.ActiveFrame + 1
            spranim.T -= 1
            if nextframe >= len(clip.Frames) {
                // animation ended
                switch clip.ClipMode {
                    case AnimO#
                }
            }
        }
    }
}
2018/11/29 10:14:13 -------------------------------------------------------
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/sprite.go:21:6:missing function body
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:43:6:missing function body
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/transform.go:18:6:missing function body
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:137:11:undeclared name: AnimO
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/math.go:26:2:"fmt" imported but not used
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/math.go:27:2:"math" imported but not used
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/sprite.go:7:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:7:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:14:13 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/transform.go:5:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:14:13 Elapsed duration: 524.880257ms
2018/11/29 10:14:13 Offset: 0
2018/11/29 10:14:13 Number of candidates found: 0
2018/11/29 10:14:13 Candidates are:
2018/11/29 10:14:13 =======================================================

Run 2 - success

2018/11/29 10:15:46 Got autocompletion request for '/Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go'
2018/11/29 10:15:46 Cursor at: 4122
2018/11/29 10:15:46 -------------------------------------------------------
package gcs

import (
    "image"

    "github.com/gabstv/ecs"
    "github.com/gabstv/groove/pkg/groove"
    "github.com/gabstv/groove/pkg/groove/common"
    "github.com/hajimehoshi/ebiten"
)

// AnimClipMode determines how time is treated outside of the keyframed range of an animation clip.
type AnimClipMode byte

const (
    // AnimOnce - When time reaches the end of the animation clip, the clip will automatically
    // stop playing and time will be reset to beginning of the clip.
    AnimOnce AnimClipMode = 0
    // AnimStop - When time reaches the end of the animation clip, the clip will automatically
    // stop playing and time will be locked to the last played frame.
    AnimStop AnimClipMode = 1
    // AnimLoop - When time reaches the end of the animation clip, time will continue at the beginning.
    AnimLoop AnimClipMode = 2
    // AnimPingPong - When time reaches the end of the animation clip, time will ping pong back between beginning
    // and end.
    AnimPingPong AnimClipMode = 3
    // AnimClampForever - Plays back the animation. When it reaches the end, it will keep playing the last frame
    // and never stop playing.
    //
    // When playing backwards it will reach the first frame and will keep playing that. This is useful for additive
    // animations, which should never be stopped when they reach the maximum.
    AnimClampForever AnimClipMode = 4
)

const (
    SpriteAnimationPriority int = -6
)

var (
    spriteanimationWC = &common.WorldComponents{}
)

func init() {
    groove.DefaultComp(func(e *groove.Engine, w *ecs.World) {
        //SpriteComponent(w)
    })
    groove.DefaultSys(func(e *groove.Engine, w *ecs.World) {
        //SpriteSystem(w)
    })
}

type SpriteAnimation struct {
    Enabled     bool
    Play        bool
    ActiveClip  int
    ActiveFrame int
    Clips       []SpriteAnimationClip
    T           float64
    // Default fps for clips with no fps specified
    Fps float64

    // caches
    lastClipsLen int
    clipMap      map[string]int
}

type SpriteAnimationClip struct {
    // The name of an animation is not allowed to be changed during runtime
    // but since this is part of a component (and components shouldn't have logic),
    // it is a public member.
    Name   string
    Frames []image.Rectangle
    Fps    float64
    ClipMode AnimClipMode
}

// SpriteAnimationComponent will get the registered sprite anim component of the world.
// If a component is not present, it will create a new component
// using world.NewComponent
func SpriteAnimationComponent(w *ecs.World) *ecs.Component {
    c := spriteanimationWC.Get(w)
    if c == nil {
        var err error
        c, err = w.NewComponent(ecs.NewComponentInput{
            Name: "groove.gcs.SpriteAnimation",
            ValidateDataFn: func(data interface{}) bool {
                _, ok := data.(*SpriteAnimation)
                return ok
            },
            DestructorFn: func(_ *ecs.World, entity ecs.Entity, data interface{}) {
                sd := data.(*SpriteAnimation)
                sd.Clips = nil
            },
        })
        if err != nil {
            panic(err)
        }
        spriteanimationWC.Set(w, c)
    }
    return c
}

// SpriteAnimationSystem creates the sprite system
func SpriteAnimationSystem(w *ecs.World) *ecs.System {
    sys := w.NewSystem(SpriteAnimationPriority, SpriteAnimationSystemExec, spriteanimationWC.Get(w))
    if w.Get(DefaultImageOptions) == nil {
        opt := &ebiten.DrawImageOptions{}
        w.Set(DefaultImageOptions, opt)
    }
    sys.AddTag(groove.WorldTagUpdate)
    return sys
}

// SpriteAnimationSystemExec is the main function of the SpriteSystem
func SpriteAnimationSystemExec(dt float64, v *ecs.View, s *ecs.System) {
    world := v.World()
    matches := v.Matches()
    spriteanimcomp := spriteanimationWC.Get(world)
    globalfps := ebiten.CurrentFPS()
    //engine := world.Get(groove.EngineKey).(*groove.Engine)
    for _, m := range matches {
        spranim := m.Components[spriteanimcomp].(*SpriteAnimation)
        if !spranim.Enabled || !spranim.Play {
            continue
        }
        clip := spranim.Clips[spranim.ActiveClip]
        localfps := nonzeroval(clip.Fps, spranim.Fps, globalfps)
        localdt := (dt * localfps) / globalfps
        spranim.T += localdt
        if spranim.T >= 1 {
            // next frame
            nextframe := spranim.ActiveFrame + 1
            spranim.T -= 1
            if nextframe >= len(clip.Frames) {
                // animation ended
                switch clip.ClipMode {
                    case AnimO#
                }
            }
        }
    }
}
2018/11/29 10:15:46 -------------------------------------------------------
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/sprite.go:21:6:missing function body
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:43:6:missing function body
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/transform.go:18:6:missing function body
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:137:11:undeclared name: AnimO
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/math.go:26:2:"fmt" imported but not used
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/math.go:27:2:"math" imported but not used
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/sprite.go:7:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/spriteanimation.go:7:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:15:46 error in package github.com/gabstv/groove/pkg/groove/gcs: /Users/gabs/proggit/groove/pkg/groove/gcs/transform.go:5:2:"github.com/gabstv/groove/pkg/groove" imported but not used
2018/11/29 10:15:46 Elapsed duration: 523.977592ms
2018/11/29 10:15:46 Offset: 0
2018/11/29 10:15:46 Number of candidates found: 1
2018/11/29 10:15:46 Candidates are:
2018/11/29 10:15:46   const AnimOnce AnimClipMode
2018/11/29 10:15:46 =======================================================

Copied from original issue: Microsoft/vscode-go#2161

ramya-rao-a commented 5 years ago

@gabstv Does this project use Go modules?

ramya-rao-a commented 5 years ago

From @anjmao on November 30, 2018 22:5

@gabstv I suggest to look at https://github.com/saibing/bingo which already works much better that gocode.

ramya-rao-a commented 5 years ago

Yes, we are in the process of adding support to bingo as you already know via #2158

Meanwhile, I am moving this issue to the repo for gocode-gomod so that @stamblerre can help.

stamblerre commented 5 years ago

@gabstv, is this just the result of you triggering completions twice in a row or did anything change between the 2 instances?

gabstv commented 5 years ago

@stamblerre It's the result of triggering completions twice (or more until the it gets right) without changing code

stamblerre commented 5 years ago

Is your project particularly large? This might be related to https://github.com/stamblerre/gocode/issues/20.

gabstv commented 5 years ago

The issue seems to be related with go mod. This project I'm in is relatively small.
Edit: gocode works as it should with non "go mod" projects on my end.

stamblerre commented 5 years ago

@gabstv: sorry I didn't reply earlier. Are you still experiencing this issue? I've not been able to reproduce this, and I haven't heard of anyone experiencing a similar issue, so I'm not sure how to approach this. Does go list -compiled -e -json path/to/project consistently produce correct output for you / can you post the output here?

zgramana commented 5 years ago

I was having the same issue. It almost appeared as though a timeout fires before the contextual list of symbols can be built and I would instead get a generic list of tokens from across my workspace. When I would re-run a second or more time, the contextually correct list of symbols returns before the timeout (though still after an noticeable delay).

This behavior holds regardless of whether I'm trying to get autocomplete on my own code or from external packages. There were also a great many instances of guru that get spawned whenever I saved a file.

Once I opted out of every option in go.languageServerExperimentalFeatures except for format and autoComplete the number of guru instances spawned dropped very precipitously and this issue went away.

stamblerre commented 4 years ago

Closing this issue, as the current recommendation for autocompletion is to use gopls.