Skip to content

Commit

Permalink
src/goLanguageServer.ts: add "debug test" and "debug benchmark" codelens
Browse files Browse the repository at this point in the history
This CL adds a "debug test" and "debug benchmark" codelens to the
intercepted lenses from gopls.

Additionally, a fix is included for finding the function name argument
in the arguments that come from gopls.

Updates golang/go#36787

Change-Id: I1a109902bbee25ecb9bbf4ae1c8d9af1b6d2fa2f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/245358
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
mcjcloud authored and hyangah committed Jul 29, 2020
1 parent e3aa3a2 commit 9d1620b
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
InitializeError,
LanguageClient,
Message,
ProvideCodeLensesSignature,
ProvideCompletionItemsSignature,
ProvideDocumentLinksSignature,
RevealOutputChannelOn,
Expand Down Expand Up @@ -258,34 +259,54 @@ function buildLanguageClient(config: LanguageServerConfig): LanguageClient {
},
},
middleware: {
provideCodeLenses: async (doc, token, next): Promise<vscode.CodeLens[]> => {
provideCodeLenses: async (
doc: vscode.TextDocument,
token: vscode.CancellationToken,
next: ProvideCodeLensesSignature
): Promise<vscode.CodeLens[]> => {
const codeLens = await next(doc, token);
if (!codeLens || codeLens.length === 0) {
return codeLens;
}
return codeLens.map((lens: vscode.CodeLens) => {
return codeLens.reduce((lenses: vscode.CodeLens[], lens: vscode.CodeLens) => {
switch (lens.command.title) {
case 'run test': {
const args = lens.command.arguments;
return new vscode.CodeLens(lens.range, {
...lens.command,
command: 'go.test.cursor',
arguments: [{ functionName: args[args.indexOf('run') + 1] }],
});
return [
...lenses,
new vscode.CodeLens(lens.range, {
...lens.command,
command: 'go.test.cursor',
arguments: [{ functionName: args[args.indexOf('-run') + 1] }],
}),
new vscode.CodeLens(lens.range, {
title: 'debug test',
command: 'go.debug.cursor',
arguments: [{ functionName: args[args.indexOf('-run') + 1] }],
}),
];
}
case 'run benchmark': {
const args = lens.command.arguments;
return new vscode.CodeLens(lens.range, {
...lens.command,
command: 'go.benchmark.cursor',
arguments: [{ functionName: args[args.indexOf('bench') + 1] }],
});
return [
...lenses,
new vscode.CodeLens(lens.range, {
...lens.command,
command: 'go.benchmark.cursor',
arguments: [{ functionName: args[args.indexOf('-bench') + 1] }],
}),
new vscode.CodeLens(lens.range, {
title: 'debug benchmark',
command: 'go.debug.cursor',
arguments: [{ functionName: args[args.indexOf('-bench') + 1] }],
}),
];
}
default: {
return lens;
return [...lenses, lens];
}
}
});
}, []);
},
handleDiagnostics: (
uri: vscode.Uri,
Expand Down

0 comments on commit 9d1620b

Please sign in to comment.