This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
RunTest with CodeLens #937
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c6aa0d
wip: run test codelens
goenning d6814a0
renaming to GoRunTestCodeLens
goenning c397367
fix lint
goenning 0ab3926
merge from master
goenning 7aed2b5
refactor + package level run test
goenning 358e5db
early return if not a test file
goenning d3fb696
refactor
goenning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import vscode = require('vscode'); | ||
import { CodeLensProvider, TextDocument, CancellationToken, CodeLens, Command } from 'vscode'; | ||
import { getTestFunctions } from './goTest'; | ||
import { GoDocumentSymbolProvider } from './goOutline'; | ||
|
||
export class GoRunTestCodeLensProvider implements CodeLensProvider { | ||
public provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]> { | ||
if (!document.fileName.endsWith('_test.go')) { | ||
return; | ||
} | ||
|
||
return Promise.all([ | ||
this.getCodeLensForPackage(document), | ||
this.getCodeLensForFunctions(document) | ||
]).then(res => { | ||
return res[0].concat(res[1]); | ||
}); | ||
} | ||
|
||
private getCodeLensForPackage(document: TextDocument): Thenable<CodeLens[]> { | ||
let documentSymbolProvider = new GoDocumentSymbolProvider(); | ||
return documentSymbolProvider.provideDocumentSymbols(document, null) | ||
.then(symbols => symbols.find(sym => sym.kind === vscode.SymbolKind.Package && !!sym.name)) | ||
.then(pkg => { | ||
if (pkg) { | ||
const range = pkg.location.range; | ||
return [ | ||
new CodeLens(range, { | ||
title: 'run package tests', | ||
command: 'go.test.package' | ||
}), | ||
new CodeLens(range, { | ||
title: 'run file tests', | ||
command: 'go.test.file' | ||
}) | ||
]; | ||
} | ||
}); | ||
} | ||
|
||
private getCodeLensForFunctions(document: TextDocument): Thenable<CodeLens[]> { | ||
return getTestFunctions(document).then(testFunctions => { | ||
return testFunctions.map(func => { | ||
let command: Command = { | ||
title: 'run test', | ||
command: 'go.test.cursor', | ||
arguments: [ { functionName: func.name} ] | ||
}; | ||
return new CodeLens(func.location.range, command); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 cents suggestion: s/run/Run. The same for
run file tests
,run test
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
Run tests in package
,Run tests in file
andRun test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer lowercase + shorter text to not get much attention. It should be as unobtrusive as possible so devs can focus on code an not on these actions. It's like this on C# codelens
Next enhancement could be
debug test
😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, when you put it that way it makes sense.
There is already an ask for it #879 :)