-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completion #53
Completion #53
Conversation
// TODO: return item type. | ||
// TODO: support fetching item description. | ||
for _, wd := range workspace.Files { | ||
codePos := token.Pos(position) | ||
// current position: = wd.FileSet.Position(codePos).String() | ||
enclosingPath, _ := astutil.PathEnclosingInterval(wd.File, codePos, codePos+1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nifty! I was about to have to write this
src/go/languageservice/workspace.go
Outdated
switch x := enclosingNode.(type) { | ||
|
||
// for function declarations, get all their locals declared before codePos | ||
case *ast.FuncDecl: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still work with top level constructs like functions, types, vars, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I am handling only functions and their statements.
src/go/languageservice/workspace.go
Outdated
if(ins.Pos() >= codePos) { | ||
continue; | ||
} | ||
switch insCasted := ins.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to do this more simply with ast.Walk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks! I'll take a look at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewritten the code to use ast.Walk, currently I am supporting only variable definitions (local for current function and global), I'll work on supporting types & function definitions etc.
// TODO: take into account context. | ||
// TODO: support locals. | ||
|
||
// TODO: support other node types. | ||
// TODO: return item type. | ||
// TODO: support fetching item description. | ||
for _, wd := range workspace.Files { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this should eventually look at just the current file as opposed to looping through all files... but I was lazy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok, I'll change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do this now, just a note.
I think I found quite a good way to get names visible in a specific context. For now I added support for locals of enclosing functions, defined before current position in code.
Addresses: #49 and #50