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

Add ability to collect traces and log errors to log file #882

Merged
merged 4 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Set `go.useLanguageServer` to `true` to use the Go language server from [Sourceg
* This is an experimental feature and is not available in Windows yet.
* If set to true, you will be prompted to install the Go language server. Once installed, you will have to reload VS Code window. The language server will then be run by the Go extension in the background to provide services needed for the above mentioned features.
* Everytime you change the value of the setting `go.useLanguageServer`, you need to reload the VS Code window for it to take effect.
* To collect traces, set `"go.languageServerFlags": ["-trace"]`
* To collect errors from language server in a logfile, set `"go.languageServerFlags": ["-trace", "-logfile", "path to a text file that exists" ]`


### Linter
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@
"default": false,
"description": "Experimental: Not available in Windows. Use Go language server from Sourcegraph for Hover, Definition, Find All References, Signature Help, File Outline and Workspace Symbol features"
},
"go.languageServerFlags": {
"type": "array",
"default": [],
"description": "Flags like -trace and -logfile to be used while running the language server."
},
"go.gotoSymbol.includeImports": {
"type": "boolean",
"default": false,
Expand Down
22 changes: 18 additions & 4 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ let diagnosticCollection: vscode.DiagnosticCollection;

export function activate(ctx: vscode.ExtensionContext): void {
let useLangServer = vscode.workspace.getConfiguration('go')['useLanguageServer'];
let langServerFlags: string[] = vscode.workspace.getConfiguration('go')['languageServerFlags'] || [];
let toolsGopath = vscode.workspace.getConfiguration('go')['toolsGopath'];

updateGoPathGoRootFromConfig().then(() => {
offerToInstallTools();
let langServerAvailable = checkLanguageServer();
if (langServerAvailable) {
let langServerFlags: string[] = vscode.workspace.getConfiguration('go')['languageServerFlags'] || [];
const c = new LanguageClient(
'go-langserver',
{
command: getBinPath('go-langserver'),
args: [
'-mode=stdio'
],
args: ['-mode=stdio', ...langServerFlags],
},
{
documentSelector: ['go'],
Expand Down Expand Up @@ -143,7 +143,7 @@ export function activate(ctx: vscode.ExtensionContext): void {

// If there was a change in "useLanguageServer" setting, then ask the user to reload VS Code.
if (process.platform !== 'win32'
&& useLangServer !== updatedGoConfig['useLanguageServer']
&& didLangServerConfigChange(useLangServer, langServerFlags, updatedGoConfig)
&& (!updatedGoConfig['useLanguageServer'] || checkLanguageServer())) {
vscode.window.showInformationMessage('Reload VS Code window for the change in usage of language server to take effect', 'Reload').then(selected => {
if (selected === 'Reload') {
Expand Down Expand Up @@ -319,4 +319,18 @@ function sendTelemetryEventForConfig(goConfig: vscode.WorkspaceConfiguration) {
useLanguageServer: goConfig['useLanguageServer'] + '',
includeImports: goConfig['gotoSymbol'] && goConfig['gotoSymbol']['includeImports'] + ''
});
}

function didLangServerConfigChange(useLangServer: boolean, langServerFlags: string[], newconfig: vscode.WorkspaceConfiguration) {
let newLangServerFlags = newconfig['languageServerFlags'] || [];
if (useLangServer !== newconfig['useLanguageServer'] || langServerFlags.length !== newLangServerFlags.length) {
return true;
}

for (let i = 0; i < langServerFlags.length; i++) {
if (newLangServerFlags[i] !== langServerFlags[i]) {
return true;
}
}
return false;
}