-
Notifications
You must be signed in to change notification settings - Fork 645
Put run/debug test links in the context menu instead #1088
Comments
You can control which commands are showed in the context menu by updating the This way you can get the run test in the menu but not the debug test This is easily fixable and PRs are welcome. |
And that would also make both the run and debug links in all those fake lines disappear? |
the run/debug links are called codelens in general. If you don't want to see them in any file that you work on you can set |
(Edited) OK, so to get the run-test option in the context-menu, I have to add the run-test command to go.editorContextMenuCommands? To remove the run-test and debug-test buttons from the editor buffer, I have to set go.enableCodeLens to false? Does Code Lens show up for Go files in any other context? Just wondering if I'd be losing anything else by disabling it. How do I run the debug-test command? "Debug test" in the command palette shows nothing. |
Yes, we have references codelens, but this is disabled by default as it tends to be slow on large projects
There is one command to start debugging using the currently selected debug configuration. But there is none for debugging the test function under a cursor. It should be pretty straight forward to add it though. PRs are welcome :) |
OK, so the closest I can get without adding anything new is to disable the Go Code Lens and add the run-test command to the context menu. Do you know by chance what value needs to be added to go.editorContextMenuCommands for running tests? |
I see go.editorContextMenuCommands.testAtCursor is true by default, which seems to be the one I want, but as seen above, there's no "Go: Run Test" context menu item. If I set go.editorContextMenuCommands.testFile and .testPackage to true then I see "Go: Test File" and "Go: Test Package" context menu items, so it seems like something similar should be appearing for the test under the cursor. Also, why are testFile and testPackage defaulted to false? They seem useful. |
It seems if I set go.enableCodeLens to false I get a JSON lint error saying false is the wrong type, it expects object. If I set it to null or {} or {"runtests": false} then the feature isn't actually disabled. Bug? |
Also, I'm happy to add the debug-test context menu item, but I've never contributed before, so I'd have no idea where to start. Got any suggestions? |
You need to disable the For disabling go codelens
For Debug Test command
|
I think it'd still be useful to have the run-test command in the menu even if Code Lens is enabled. Otherwise you have to know where to look to find the feature. Menus should always have what you're looking for, in my opinion. Is setting go.enableCodeLens as you show above enough, or do I need to set editor.codeLens too (and if so, to what?)? |
Got run-test working, had to disable editor.codeLens entirely. Whew! Thanks. |
Made an attempt at adding a debug-test command, but hit a wall once I had the Command. It also wasn't clear where a TextDocument would come from in that context. |
I figured that part out. I have the function name, I made a Command with it like in the debug example you gave, except in that example there's a "document" TextDocument used that isn't available in the testAtCursor context. Do I just leave that out?
…Sent from my iPhone
On Jul 20, 2017, at 12:23 PM, Ramya Rao ***@***.***> wrote:
Refer to https://github.com/Microsoft/vscode-go/blob/0.6.62/src/goTest.ts#L59
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
you should be able to get the document from I have a feeling we are talking about 2 different things Can you point me to your code in your repo where you feel you need the document and don't have it? |
This is what I have now: import vscode = require('vscode');
import { getTestFunctions } from './goTests';
import { Command, TextDocument } from 'vscode';
import path = require('path');
let debugConfig: any = {
'name': 'Launch',
'type': 'go',
'request': 'launch',
'mode': 'test'
};
/**
* Debugs the unit test at the primary cursor. Output is sent to the 'Go' channel.
*
* @param goConfig Configuration for the Go extension.
*/
export function debugTestAtCursor(goConfig: vscode.WorkspaceConfiguration, args: any) {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (!editor.document.fileName.endsWith('_test.go')) {
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
return;
}
if (editor.document.isDirty) {
vscode.window.showInformationMessage('File has unsaved changes. Save and try again.');
return;
}
getTestFunctions(editor.document).then(testFunctions => {
let testFunctionName: string;
// We use functionName if it was provided as argument
// Otherwise find any test function containing the cursor.
if (args && args.functionName) {
testFunctionName = args.functionName;
} else {
for (let func of testFunctions) {
let selection = editor.selection;
if (selection && func.location.range.contains(selection.start)) {
testFunctionName = func.name;
break;
}
};
}
if (!testFunctionName) {
vscode.window.showInformationMessage('No test function found at cursor.');
return;
}
const args = ['-test.run', testFunctionName];
const program = path.dirname(editor.document.fileName);
const env = goConfig['testEnvVars'] || {};
const envFile = goConfig['testEnvFile'];
let config = Object.assign({}, this.debugConfig, { args, program, env, envFile });
let debugTestAtCursorCmd: Command = {
title: 'debug test',
command: 'vscode.startDebug',
arguments: [ config ]
};
return vscode.commands.executeCommand('vscode.startDebug', debugTestAtCursorCmd)
}).then(null, err => {
console.error(err);
});
} Not sure about the use of executeCommand. |
executeCommand is fine. That's how we programmatically run a command. So where in there are you seeing the " there's a "document" TextDocument used that isn't available in the testAtCursor context" ? |
It was in the |
it definitely should :) |
Hi, I'm new here. I gave it a shot, and it seems to be working. Preparing my PR. |
@Ashiroq Cool, thanks! My effort fell through. |
Thanks @willfaught, @Ashiroq and @vladbarosan! |
Thank you! |
The blank non-line line the run/debug test links are in looks weird and makes it hard to tell at a glance what I'm looking at.
Can they be moved to context menu items instead?
The text was updated successfully, but these errors were encountered: