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 1 commit
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.useLanguageServer": { "trace": true }`
* To collect errors from language server in a logfile, set `"go.useLanguageServer": { "logfile": "path to a text file that exists" }`


### Linter
Expand Down
32 changes: 26 additions & 6 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ import { clearCacheForTools } from './goPath';
let diagnosticCollection: vscode.DiagnosticCollection;

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

updateGoPathGoRootFromConfig().then(() => {
offerToInstallTools();
let langServerAvailable = checkLanguageServer();
if (langServerAvailable) {
let langServerArgs = ['-mode=stdio'];
if (typeof langServerConfig !== 'boolean' && langServerConfig.hasOwnProperty('trace') && langServerConfig['trace'] === true) {
langServerArgs.push('-trace');
}
if (typeof langServerConfig !== 'boolean' && langServerConfig.hasOwnProperty('logfile') && typeof langServerConfig['logfile'] === 'string') {
langServerArgs.push('-logfile');
langServerArgs.push(langServerConfig['logfile']);
}
const c = new LanguageClient(
'go-langserver',
{
command: getBinPath('go-langserver'),
args: [
'-mode=stdio'
],
args: langServerArgs,
},
{
documentSelector: ['go'],
Expand Down Expand Up @@ -143,15 +149,15 @@ 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(langServerConfig, updatedGoConfig['useLanguageServer'])
&& (!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') {
vscode.commands.executeCommand('workbench.action.reloadWindow');
}
});
}
useLangServer = updatedGoConfig['useLanguageServer'];
langServerConfig = updatedGoConfig['useLanguageServer'];

// If there was a change in "toolsGopath" setting, then clear cache for go tools
if (toolsGopath !== updatedGoConfig['toolsGopath']) {
Expand Down Expand Up @@ -319,4 +325,18 @@ function sendTelemetryEventForConfig(goConfig: vscode.WorkspaceConfiguration) {
useLanguageServer: goConfig['useLanguageServer'] + '',
includeImports: goConfig['gotoSymbol'] && goConfig['gotoSymbol']['includeImports'] + ''
});
}

function didLangServerConfigChange(oldConfig: vscode.WorkspaceConfiguration, newconfig: vscode.WorkspaceConfiguration) {
let oldType = typeof oldConfig;
let newType = typeof newconfig;
if (oldType === 'boolean' && newType === 'boolean') {
return oldConfig !== newconfig;
}

if (oldType === 'boolean' || newType === 'boolean') {
return true;
}

return (oldConfig['trace'] !== newconfig['trace'] || oldConfig['logfile'] !== newconfig['logFile']) ;
}