-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code lens for quick evaluation (#1035)
* Add code lens for quick eval command * Ensure commented out predicates do not have code lens * Improve conditional check for commented out predicate detection * Refactor regex * Move comment check to eliminate evaluating regex more than once Co-authored-by: marcnjaramillo <[email protected]>
- Loading branch information
1 parent
58f4a82
commit c8ed8b2
Showing
4 changed files
with
88 additions
and
16 deletions.
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
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,43 @@ | ||
import { | ||
CodeLensProvider, | ||
TextDocument, | ||
CodeLens, | ||
Command, | ||
Range | ||
} from 'vscode'; | ||
|
||
class QuickEvalCodeLensProvider implements CodeLensProvider { | ||
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> { | ||
|
||
const codeLenses: CodeLens[] = []; | ||
|
||
for (let index = 0; index < document.lineCount; index++) { | ||
const textLine = document.lineAt(index); | ||
|
||
// Match a predicate signature, including predicate name, parameter list, and opening brace. | ||
// This currently does not match predicates that span multiple lines. | ||
const regex = new RegExp(/(\w+)\s*\([^()]*\)\s*\{/); | ||
|
||
const matches = textLine.text.match(regex); | ||
|
||
// Make sure that a code lens is not generated for any predicate that is commented out. | ||
if (matches && !(/^\s*\/\//).test(textLine.text)) { | ||
const range: Range = new Range( | ||
textLine.range.start.line, matches.index!, | ||
textLine.range.end.line, matches.index! + 1 | ||
); | ||
|
||
const command: Command = { | ||
command: 'codeQL.codeLensQuickEval', | ||
title: `Quick Evaluation: ${matches[1]}`, | ||
arguments: [document.uri, range] | ||
}; | ||
const codeLens = new CodeLens(range, command); | ||
codeLenses.push(codeLens); | ||
} | ||
} | ||
return codeLenses; | ||
} | ||
} | ||
|
||
export default QuickEvalCodeLensProvider; |
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