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

Add support for bingo & golsp language server (#2143) #2158

Closed
wants to merge 1 commit into from

Conversation

tohjustin
Copy link

@tohjustin tohjustin commented Nov 28, 2018

Hi @ramya-rao-a, here's my attempt to add support for bingo & golsp language servers to the extension.

This Closes #2143.

Additional Notes

  • When testing the extension with bingo as the language server & I would receive <MY_PROJECT_DIR>/go.mod does not exist, please use 'go mod init' to create it errors (since bingo only supports Go Module based projects).
  • Do we want to support any language server specific flags/logic to handle cases like the example above?

@msftclas
Copy link

msftclas commented Nov 28, 2018

CLA assistant check
All CLA requirements met.

@ramya-rao-a
Copy link
Contributor

You can use the isModSupported function to figure out if the current workspace supports modules or not. Based on this, you can then decide whether to use bingo or not.

@tohjustin
Copy link
Author

tohjustin commented Nov 28, 2018

You can use the isModSupported function to figure out if the current workspace supports modules or not. Based on this, you can then decide whether to use bingo or not.

Just want to clarify a little more on this, if the user configured their vscode settings to useLanguageServer: 'bingo' and

  • if isModSupported returns true, we'll use bingo as usual
  • if isModSupported returns false, we display a message notifying the user that bingo is used since it only supports Go Module based projects & the current project/workspace isn't --> treat the session as useLanguageServer: 'none'?

@ramya-rao-a
Copy link
Contributor

Yes, thats right.

@tohjustin tohjustin force-pushed the issue-2143 branch 2 times, most recently from d62d0d2 to af37c17 Compare November 29, 2018 07:55
@tohjustin
Copy link
Author

Not sure if there's a better place to check isModSupported when using the bingo language server =S

if (activeFileUri !== null) {
const isModSupportedResult = await isModSupported(activeFileUri);
if (languageServer === 'bingo' && !isModSupportedResult) {
vscode.window.showInformationMessage('The Go language server (bingo) does not support non-go module projects. Falling back to default behavior.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this commit saibing/bingo@f9f872a
Bingo already supports non-go module projects. I tested it in GOPATH without modules and it was working fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that info @anjmao!
@saibing Can you confirm that non-go module support is ready for use?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramya-rao-a

bingo already supports non-go module project, I have done some manual test cases, it looks like everything is fine, I will add some automation test cases in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anjmao Thanks for the heads up! Kudos to @saibing for adding support for non-go module projects in such a short period of time 😅

@ramya-rao-a I guess I can remove the isModSupported checks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tohjustin Yes, I just tested it out with GOPATH, and it works. So we can remove the isModSupported checks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -40,6 +42,8 @@ const _allTools: { [key: string]: string } = {
'golangci-lint': 'github.com/golangci/golangci-lint/cmd/golangci-lint',
'revive': 'github.com/mgechev/revive',
'go-langserver': 'github.com/sourcegraph/go-langserver',
'bingo': 'github.com/saibing/bingo',
'golsp': 'golang.org/x/tools/cmd/golsp',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stamblerre Would this be the right import path to use in go get for the language server from your team?

@@ -183,6 +195,8 @@ export function installAllTools(updateExistingToolsOnly: boolean = false) {
'golangci-lint': 'Linter)',
'revive': '\t\t(Linter)',
'go-langserver': '(Language Server)',
'bingo': '(Language Server)',
'golsp': '(Language Server)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help users differentiate lets add some suffixes here like

  • Language Server by Sourcegraph
  • Language Server by Google
  • Language Server by saibing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (activeFileUri !== null) {
const isModSupportedResult = await isModSupported(activeFileUri);
if (languageServer === 'bingo' && !isModSupportedResult) {
vscode.window.showInformationMessage('The Go language server (bingo) does not support non-go module projects. Falling back to default behavior.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that info @anjmao!
@saibing Can you confirm that non-go module support is ready for use?

@ramya-rao-a
Copy link
Contributor

@tohjustin The README.md would also need an update. There is a section there on the language server usage

tools.push('go-langserver');
}

if (goConfig['useLanguageServer'] === 'bingo') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bingo is only supported from Go 1.11 onwards, so we should include that check here

Copy link
Author

@tohjustin tohjustin Dec 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah missed that out, will add the check in the following patch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tohjustin tohjustin force-pushed the issue-2143 branch 2 times, most recently from 0c0c09d to 5d21bf4 Compare December 1, 2018 07:57
@tohjustin
Copy link
Author

@tohjustin The README.md would also need an update. There is a section there on the language server usage

Reworded quite a bit of the language server section (also ran it through Grammarly), please do let me know if you think it still needs more work 😅

@tohjustin tohjustin force-pushed the issue-2143 branch 3 times, most recently from c0f4d1b to 6d65664 Compare December 2, 2018 23:31
@tohjustin
Copy link
Author

Hi @ramya-rao-a , I saw the issue opened by @stamblerre in saibing/bingo#13 & seems like the plan is to focus on golsp development.

Any updates on this PR? 😅

* Changes made to the `go.useLanguageServer` setting requires VS Code to be reloaded to take effect.
* To collect traces, set `"go.languageServerFlags": ["-trace"]`.
* To collect errors from the language server in a log file, set `"go.languageServerFlags": ["-trace", "-logfile", "path to a text file that exists"]`.
* Use the `go.languageServerExperimentalFeatures` setting to opt-in to experimental features such as Code Completion and Code Formatting.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramya-rao-a @tohjustin Can we make go.languageServerExperimentalFeatures autocomplete and code formatting to be true by default? If I'm using LSP all I want to set by default is go. useLanguageServer setting and get all the LSP features.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Dec 7, 2018

Can we make go.languageServerExperimentalFeatures autocomplete and code formatting to be true by default?

@anjmao Yes, we can do that

I saw the issue opened by @stamblerre in saibing/bingo#13 & seems like the plan is to focus on golsp development.

@tohjustin Given that there is a good likelihood of all 3 language servers merging into 1 (Sourcegraph plans to use the one from Google, @saibing and Google are planning to work together, I want to avoid changing the schema of the useLanguageServer setting.

Instead, if one wants to use another language server, they can use the go.alternateTools setting as below:

"go.alternateTools": {
     "go-langserver": "bingo"
}

This would need some changes from the extension which I have already made in ecb691c.

@anjmao, @tohjustin Can you try the latest beta version with the above setting and let me know if you see any issues?

@ramya-rao-a
Copy link
Contributor

@anjmao On second thoughts, I don't want to enable the formatting feature by the language server by default just yet. This is because the language server doesn't respect the formatFlags or the formalTool settings.

I don't want to enable the auto-completion feature by language server by default, because the language server doesn't support completions for unimported packages yet.

Once these 2 features from the language server has complete parity with what the extension does, I will turn them on by default.

@tohjustin
Copy link
Author

@ramya-rao-a Really appreciate the update!

Yup the the go.alternateTools setting is working as intended. Got bingo to work with the extension using the following settings (also needed go.useLanguageServer set as true):

  "go.alternateTools": {
    "go-langserver": "bingo",
  },
  "go.languageServerExperimentalFeatures": {
    "format": true,
    "autoComplete": true
  },
  "go.useLanguageServer": true

I guess I'll leave it up to you to close this PR or put it on hold until the new Go language server is ready. 👍

@ramya-rao-a
Copy link
Contributor

Yup the the go.alternateTools setting is working as intended.

Thanks for confirming the beta version @tohjustin!

I have updated the wiki on Go modules support in VS Code appropriately.

I guess I'll leave it up to you to close this PR or put it on hold until the new Go language server is ready.

I believe closing this PR is the right thing to do as I want to avoid changes in settings schema as much as possible.

Thanks for all your work on this @tohjustin, it is very much appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants