-
Notifications
You must be signed in to change notification settings - Fork 646
When using go-languageserver, also use code completion feature #1607
Changes from 3 commits
ad7b9f6
6554ee6
55901d3
f2d7910
f901c06
4216a5a
02ba529
00aae74
5bba166
e59e7c1
c2df1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,7 @@ function installTools(goVersion: SemVersion, missing?: string[]) { | |
outputChannel.appendLine(''); // Blank line for spacing | ||
let failures = res.filter(x => x != null); | ||
if (failures.length === 0) { | ||
if (missing.indexOf('langserver-go') > -1) { | ||
if (missing.indexOf('go-langserver') > -1) { | ||
outputChannel.appendLine('Reload VS Code window to use the Go language server'); | ||
} | ||
outputChannel.appendLine('All tools successfully installed. You\'re ready to Go :).'); | ||
|
@@ -383,8 +383,25 @@ export function checkLanguageServer(): boolean { | |
if (!langServerAvailable) { | ||
promptForMissingTool('go-langserver'); | ||
vscode.window.showInformationMessage('Reload VS Code window after installing the Go language server'); | ||
return langServerAvailable; | ||
} | ||
return langServerAvailable; | ||
|
||
// we execute the languageserver using -help so that it will fail and | ||
// print all the available flags | ||
let helpText = ''; | ||
try { | ||
helpText = cp.execFileSync(getBinPath('go-langserver'), ['-help']).toString(); | ||
} catch (err) { | ||
helpText = (<cp.SpawnSyncReturns<Buffer>>err).stderr.toString(); | ||
} | ||
let langserverSupportsCompletion = helpText.includes('-gocodecompletion'); | ||
|
||
if (!langserverSupportsCompletion) { | ||
promptForUpdatingTool('go-langserver'); | ||
vscode.window.showInformationMessage('Reload VS Code window after updating the Go language server'); | ||
} | ||
|
||
return langserverSupportsCompletion; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, Instead, create a new function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just to double check: for |
||
} | ||
|
||
function allFoldersHaveSameGopath(): boolean { | ||
|
@@ -395,8 +412,3 @@ function allFoldersHaveSameGopath(): boolean { | |
let tempGopath = getCurrentGoPath(vscode.workspace.workspaceFolders[0].uri); | ||
return vscode.workspace.workspaceFolders.find(x => tempGopath !== getCurrentGoPath(x.uri)) ? false : true; | ||
} | ||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ export function activate(ctx: vscode.ExtensionContext): void { | |
'go-langserver', | ||
{ | ||
command: getBinPath('go-langserver'), | ||
args: ['-mode=stdio', ...langServerFlags], | ||
args: ['-mode=stdio', '-gocodecompletion', ...langServerFlags], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the |
||
}, | ||
{ | ||
documentSelector: ['go'], | ||
|
@@ -110,6 +110,7 @@ export function activate(ctx: vscode.ExtensionContext): void { | |
|
||
ctx.subscriptions.push(c.start()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since its possible for users to run the older versions of the language server where completions are not supported, add the below to register the completion provider from the extension
|
||
} else { | ||
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"')); | ||
ctx.subscriptions.push(vscode.languages.registerHoverProvider(GO_MODE, new GoHoverProvider())); | ||
ctx.subscriptions.push(vscode.languages.registerDefinitionProvider(GO_MODE, new GoDefinitionProvider())); | ||
ctx.subscriptions.push(vscode.languages.registerReferenceProvider(GO_MODE, new GoReferenceProvider())); | ||
|
@@ -130,7 +131,6 @@ export function activate(ctx: vscode.ExtensionContext): void { | |
let testCodeLensProvider = new GoRunTestCodeLensProvider(); | ||
let referencesCodeLensProvider = new GoReferencesCodeLensProvider(); | ||
|
||
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(GO_MODE, new GoCompletionItemProvider(), '.', '\"')); | ||
ctx.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(GO_MODE, new GoDocumentFormattingEditProvider())); | ||
ctx.subscriptions.push(vscode.languages.registerRenameProvider(GO_MODE, new GoRenameProvider())); | ||
ctx.subscriptions.push(vscode.languages.registerCodeActionsProvider(GO_MODE, new GoCodeActionProvider())); | ||
|
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.
This is pretty terrible, but it's the best I could come up with in case we want to make sure an up-to-date version of the language server is installed.
Alternatively we could call go-langserver -version, but I don't really know what do to with the output as it would currently just print sth like v2-dev: https://github.com/sourcegraph/go-langserver/blob/dd4c619b53ae9d18c94e372d23d8710e59f0766b/main.go#L41