Skip to content
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

Merged
merged 4 commits into from
Jul 23, 2019
Merged

Completion #53

merged 4 commits into from
Jul 23, 2019

Conversation

kasiabulat
Copy link
Collaborator

@kasiabulat kasiabulat commented Jul 23, 2019

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

// 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)
Copy link
Owner

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

switch x := enclosingNode.(type) {

// for function declarations, get all their locals declared before codePos
case *ast.FuncDecl:
Copy link
Owner

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?

Copy link
Collaborator Author

@kasiabulat kasiabulat Jul 23, 2019

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.

if(ins.Pos() >= codePos) {
continue;
}
switch insCasted := ins.(type) {
Copy link
Owner

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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 {
Copy link
Owner

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 :)

Copy link
Collaborator Author

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.

Copy link
Owner

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.

@kasiabulat kasiabulat merged commit 849bc54 into master Jul 23, 2019
@kasiabulat kasiabulat deleted the completion branch July 24, 2019 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants