Skip to content

Commit bb05e96

Browse files
pjweinbgohyangah
authored andcommitted
[release] src/goMain: Add a command to copy to gopls output channel to an editor 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 <hyangah@gmail.com> Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Trust: Peter Weinberger <pjw@google.com> (cherry picked from commit 6f8699c) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/266578 Reviewed-by: Peter Weinberger <pjw@google.com> Run-TryBot: Peter Weinberger <pjw@google.com>
1 parent 6e0dbec commit bb05e96

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

docs/commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ Generates unit tests for the selected function in the current file
9191

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

94+
### `Go: extract server output channel to editor`
95+
96+
Show the gopls (server) output channel in the editor.
97+
9498
### `Go: Toggle gc details`
9599

96100
Toggle the display of compiler optimization choices

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@
242242
"title": "Go: Generate Interface Stubs",
243243
"description": "Generates method stub for implementing the provided interface and inserts at the cursor."
244244
},
245+
{
246+
"command": "go.extractServerChannel",
247+
"title": "Go: extract server output channel to editor",
248+
"description": "Show the gopls (server) output channel in the editor."
249+
},
245250
{
246251
"command": "go.toggle.gc_details",
247252
"title": "Go: Toggle gc details",

src/goLanguageServer.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ function daysBetween(a: Date, b: Date): number {
11471147
return msBetween(a, b) / timeDay;
11481148
}
11491149

1150-
// minutesBetween returns the number of days between a and b.
1150+
// minutesBetween returns the number of minutes between a and b.
11511151
function minutesBetween(a: Date, b: Date): number {
11521152
return msBetween(a, b) / timeMinute;
11531153
}
@@ -1156,6 +1156,34 @@ function msBetween(a: Date, b: Date): number {
11561156
return Math.abs(a.getTime() - b.getTime());
11571157
}
11581158

1159+
export function showServerOutputChannel() {
1160+
if (!languageServerIsRunning) {
1161+
vscode.window.showInformationMessage(`gopls is not running`);
1162+
return;
1163+
}
1164+
// likely show() is asynchronous, despite the documentation
1165+
serverOutputChannel.show();
1166+
let found: vscode.TextDocument;
1167+
for (const doc of vscode.workspace.textDocuments) {
1168+
if (doc.fileName.indexOf('extension-output-') !== -1) {
1169+
// despite show() above, this might not get the output we want, so check
1170+
const contents = doc.getText();
1171+
if (contents.indexOf('[Info - ') === -1) {
1172+
continue;
1173+
}
1174+
if (found !== undefined) {
1175+
vscode.window.showInformationMessage('multiple docs named extension-output-...');
1176+
}
1177+
found = doc;
1178+
// .log, as some decoration is better than none
1179+
vscode.workspace.openTextDocument({language: 'log', content: contents});
1180+
}
1181+
}
1182+
if (found === undefined) {
1183+
vscode.window.showErrorMessage('make sure "gopls (server)" output is showing');
1184+
}
1185+
}
1186+
11591187
function collectGoplsLog(): string {
11601188
serverOutputChannel.show();
11611189
// Find the logs in the output channel. There is no way to read

src/goMain.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ import {
3333
} from './goInstallTools';
3434
import {
3535
languageServerIsRunning,
36-
promptForLanguageServerDefaultChange,
37-
resetSurveyConfig,
38-
showSurveyConfig,
39-
startLanguageServerWithFallback, watchLanguageServerConfiguration
36+
promptForLanguageServerDefaultChange, resetSurveyConfig, showServerOutputChannel,
37+
showSurveyConfig, startLanguageServerWithFallback,
38+
watchLanguageServerConfiguration
4039
} from './goLanguageServer';
4140
import { lintCode } from './goLint';
4241
import { logVerbose, setLogConfig } from './goLogging';
@@ -452,6 +451,10 @@ export function activate(ctx: vscode.ExtensionContext) {
452451

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

454+
ctx.subscriptions.push(vscode.commands.registerCommand('go.extractServerChannel', () => {
455+
showServerOutputChannel();
456+
}));
457+
455458
ctx.subscriptions.push(vscode.commands.registerCommand('go.toggle.gc_details', () => {
456459
if (!languageServerIsRunning) {
457460
vscode.window.showErrorMessage('"Go: Toggle gc details" command is available only when the language server is running');

0 commit comments

Comments
 (0)