Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Autocompletion in declaration comment should suggest nearest declaration before others #1005

Closed
atombender opened this issue May 19, 2017 · 8 comments
Milestone

Comments

@atombender
Copy link

atombender commented May 19, 2017

If I'm writing a comment for a declaration, I expect the struct to be the first thing suggested (and I swear this used to be the case, too):

// <caret>
type HTTPResponseError struct {

I would expect autocompletion here to offer HTTPResponseError as the first option if I started typing. But I'm getting other suggestions at the top of the list:

vsc

@ramya-rao-a
Copy link
Contributor

@atombender What you see being suggested in the comments is word based completion (coming from VS Code core and not the Go extension) that has no knowledge of the language semantics.

What you are saying can be achieved if the Go extension itself figures out the right completion. Since the Go extension uses gocode to get completion items, you can log this feature request in the repo for gocode

This will also be easy to implement by a language server, which makes me think I should have a new label called "language-server-candidate" :)

@ramya-rao-a
Copy link
Contributor

When we do have a stable language server to use and which implements code completion, we can add this feature to then.

@atombender
Copy link
Author

Thanks, I created an issue.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 9, 2018

If anybody wants to give this a try from the Go extension's side, here are a few pointers

  • Completions are not triggered by default in comments as you type. Users have to manually press Ctrl+Space or enable quick suggestions in comments using the setting editor.quickSuggestions
  • Once completion does get triggered, the Go extension specifically returns empty result after determining that the cursor is in a line comment. You will need to skip this if the next line declares an exported member. Keep in mind to do this only right after // or right after the first word in the comment. If the comment already as a whitespace after the first word, we shouldn't be providing any completions

@shreyaskarnik
Copy link
Contributor

I am getting familiar with the vscode-go extension and adding this functionality. As a first pass I am experimenting with the following:

if (lineText.match(/^\s*\/\//)) {
					let nextLine = document.lineAt(position.line + 1).text;
					let part0 = nextLine.split(" ");
					if (!part0[1].match(/^[A-Z]/)) {
						return resolve([]);
					}
				}
  • If line is comment, then check if the next line has an exported member.
  • Checking for exported member by splitting the next line and checking for exported member.
  • Above is crude and needs to be optimized.

Questions:

  • Is there a function elsewhere which detects exported members?
  • I have verified this above is working with manual testing, how do I go about writing automated tests?
  • Any pointers would be greatly appreciated to explore opening an pull request for this feature.

@ramya-rao-a
Copy link
Contributor

Is there a function elsewhere which detects exported members

No

I have verified this above is working with manual testing, how do I go about writing automated tests

Pointer to existing test for completion that you can use as reference: https://github.com/Microsoft/vscode-go/blob/0.6.78/test/go.test.ts#L747

You can add another test file to https://github.com/Microsoft/vscode-go/tree/0.6.78/test/fixtures/completions for your case and test it

Any pointers would be greatly appreciated to explore opening an pull request for this feature.

When splitting text, keep in mind that there can be multiple spaces before the first word and between subsequent words

@atombender
Copy link
Author

Thank you!

@ramya-rao-a
Copy link
Contributor

This feature is now out in the latest update to the Go extension (0.6.81)

@ramya-rao-a ramya-rao-a added this to the 0.6.81 milestone Jun 4, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants