From 719e078ade55b7837564fa380a8946830f621152 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 5 Apr 2019 17:30:30 -0400 Subject: [PATCH] cmd/gopls/integration/vscode: log diagnostics as they are received This change will allow us to investigate golang/go#30786 more easily. Diagnostics are getting stuck even though they appear to be being sent in the correct order, so it will be helpeful to see what's happening on the VSCode side. Change-Id: I623fcd9979c05decb0a6f60da2f75af7d0ff3853 Reviewed-on: https://go-review.googlesource.com/c/tools/+/170895 Run-TryBot: Rebecca Stambler Reviewed-by: Ian Cottrell --- cmd/gopls/integration/vscode/src/extension.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/gopls/integration/vscode/src/extension.ts b/cmd/gopls/integration/vscode/src/extension.ts index 4c03b732..7898dc57 100644 --- a/cmd/gopls/integration/vscode/src/extension.ts +++ b/cmd/gopls/integration/vscode/src/extension.ts @@ -10,6 +10,11 @@ import vscode = require('vscode'); import path = require('path'); export function activate(ctx: vscode.ExtensionContext): void { + // The handleDiagnostics middleware writes to the diagnostics log, in order + // to confirm the order in which the extension received diagnostics. + let r = Math.floor(Math.random() * 100000000); + let diagnosticsLog = fs.openSync('/tmp/diagnostics' + r + '.log', 'w'); + let document = vscode.window.activeTextEditor.document; let config = vscode.workspace.getConfiguration('gopls', document.uri); let goplsCommand: string = config['command']; @@ -24,6 +29,20 @@ export function activate(ctx: vscode.ExtensionContext): void { (uri.scheme ? uri : uri.with({scheme: 'file'})).toString(), protocol2Code: (uri: string) => vscode.Uri.parse(uri), }, + middleware: { + handleDiagnostics: (uri: vscode.Uri, diagnostics: vscode.Diagnostic[], next: lsp.HandleDiagnosticsSignature) => { + let diagString = "-------------------------------------------\n"; + diagString += uri.toString(); + ": " + diagnostics.length + "\n"; + if (diagnostics.length > 0) { + diagString += "\n"; + for (const diag of diagnostics) { + diagString += diag.message + "\n"; + } + } + fs.writeSync(diagnosticsLog, diagString); + return next(uri, diagnostics); + } + }, revealOutputChannelOn: lsp.RevealOutputChannelOn.Never, }; const c = new lsp.LanguageClient('gopls', serverOptions, clientOptions);