Skip to content

Commit

Permalink
src/goMain: Add a command to copy to gopls output channel to an edito…
Browse files Browse the repository at this point in the history
…r window

Intended to be used to make looking through the gopls output channel
easier than when it is just in a panel.

There doesn't seem to be a straightforward way to give it a sensible name.

It would be nice to make the Error popup go away after some period of
time.

Change-Id: I954d6bae13b7dcefd715fac23f41a0f28a0a6a28
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/263526
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Trust: Peter Weinberger <[email protected]>
  • Loading branch information
pjweinbgo committed Oct 27, 2020
1 parent d533d37 commit 6f8699c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Generates unit tests for the selected function in the current file

Generates method stub for implementing the provided interface and inserts at the cursor.

### `Go: extract server output channel to editor`

Show the gopls (server) output channel in the editor.

### `Go: Toggle gc details`

Toggle the display of compiler optimization choices
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@
"title": "Go: Generate Interface Stubs",
"description": "Generates method stub for implementing the provided interface and inserts at the cursor."
},
{
"command": "go.extractServerChannel",
"title": "Go: extract server output channel to editor",
"description": "Show the gopls (server) output channel in the editor."
},
{
"command": "go.toggle.gc_details",
"title": "Go: Toggle gc details",
Expand Down
30 changes: 29 additions & 1 deletion src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ function daysBetween(a: Date, b: Date): number {
return msBetween(a, b) / timeDay;
}

// minutesBetween returns the number of days between a and b.
// minutesBetween returns the number of minutes between a and b.
function minutesBetween(a: Date, b: Date): number {
return msBetween(a, b) / timeMinute;
}
Expand All @@ -1156,6 +1156,34 @@ function msBetween(a: Date, b: Date): number {
return Math.abs(a.getTime() - b.getTime());
}

export function showServerOutputChannel() {
if (!languageServerIsRunning) {
vscode.window.showInformationMessage(`gopls is not running`);
return;
}
// likely show() is asynchronous, despite the documentation
serverOutputChannel.show();
let found: vscode.TextDocument;
for (const doc of vscode.workspace.textDocuments) {
if (doc.fileName.indexOf('extension-output-') !== -1) {
// despite show() above, this might not get the output we want, so check
const contents = doc.getText();
if (contents.indexOf('[Info - ') === -1) {
continue;
}
if (found !== undefined) {
vscode.window.showInformationMessage('multiple docs named extension-output-...');
}
found = doc;
// .log, as some decoration is better than none
vscode.workspace.openTextDocument({language: 'log', content: contents});
}
}
if (found === undefined) {
vscode.window.showErrorMessage('make sure "gopls (server)" output is showing');
}
}

function collectGoplsLog(): string {
serverOutputChannel.show();
// Find the logs in the output channel. There is no way to read
Expand Down
11 changes: 7 additions & 4 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ import {
} from './goInstallTools';
import {
languageServerIsRunning,
promptForLanguageServerDefaultChange,
resetSurveyConfig,
showSurveyConfig,
startLanguageServerWithFallback, watchLanguageServerConfiguration
promptForLanguageServerDefaultChange, resetSurveyConfig, showServerOutputChannel,
showSurveyConfig, startLanguageServerWithFallback,
watchLanguageServerConfiguration
} from './goLanguageServer';
import { lintCode } from './goLint';
import { logVerbose, setLogConfig } from './goLogging';
Expand Down Expand Up @@ -452,6 +451,10 @@ export function activate(ctx: vscode.ExtensionContext) {

ctx.subscriptions.push(vscode.commands.registerCommand('go.install.package', installCurrentPackage));

ctx.subscriptions.push(vscode.commands.registerCommand('go.extractServerChannel', () => {
showServerOutputChannel();
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.toggle.gc_details', () => {
if (!languageServerIsRunning) {
vscode.window.showErrorMessage('"Go: Toggle gc details" command is available only when the language server is running');
Expand Down

0 comments on commit 6f8699c

Please sign in to comment.