|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | import * as vscode from "vscode";
|
| 5 | +import { getEditorShortcuts } from "../utils/settingUtils"; |
5 | 6 |
|
6 | 7 | export class CustomCodeLensProvider implements vscode.CodeLensProvider {
|
7 | 8 |
|
8 |
| - private validFileNamePattern: RegExp = /\d+\..*\.(.+)/; |
| 9 | + private onDidChangeCodeLensesEmitter: vscode.EventEmitter<void> = new vscode.EventEmitter<void>(); |
| 10 | + |
| 11 | + get onDidChangeCodeLenses(): vscode.Event<void> { |
| 12 | + return this.onDidChangeCodeLensesEmitter.event; |
| 13 | + } |
| 14 | + |
| 15 | + public refresh(): void { |
| 16 | + this.onDidChangeCodeLensesEmitter.fire(); |
| 17 | + } |
9 | 18 |
|
10 | 19 | public provideCodeLenses(document: vscode.TextDocument): vscode.ProviderResult<vscode.CodeLens[]> {
|
| 20 | + const shortcuts: string[] = getEditorShortcuts(); |
| 21 | + if (!shortcuts) { |
| 22 | + return; |
| 23 | + } |
| 24 | + |
11 | 25 | const fileName: string = document.fileName.trim();
|
12 |
| - const matchResult: RegExpMatchArray | null = fileName.match(this.validFileNamePattern); |
| 26 | + const matchResult: RegExpMatchArray | null = fileName.match(/\d+\..*\.(.+)/); |
13 | 27 | if (!matchResult) {
|
14 | 28 | return undefined;
|
15 | 29 | }
|
16 | 30 |
|
17 | 31 | const range: vscode.Range = new vscode.Range(document.lineCount - 1, 0, document.lineCount - 1, 0);
|
| 32 | + const codeLens: vscode.CodeLens[] = []; |
18 | 33 |
|
19 |
| - return [ |
20 |
| - new vscode.CodeLens(range, { |
| 34 | + if (shortcuts.indexOf("submit") >= 0) { |
| 35 | + codeLens.push(new vscode.CodeLens(range, { |
21 | 36 | title: "Submit",
|
22 | 37 | command: "leetcode.submitSolution",
|
23 | 38 | arguments: [document.uri],
|
24 |
| - }), |
25 |
| - new vscode.CodeLens(range, { |
| 39 | + })); |
| 40 | + } |
| 41 | + |
| 42 | + if (shortcuts.indexOf("test") >= 0) { |
| 43 | + codeLens.push(new vscode.CodeLens(range, { |
26 | 44 | title: "Test",
|
27 | 45 | command: "leetcode.testSolution",
|
28 | 46 | arguments: [document.uri],
|
29 |
| - }), |
30 |
| - new vscode.CodeLens(range, { |
| 47 | + })); |
| 48 | + } |
| 49 | + |
| 50 | + if (shortcuts.indexOf("solution") >= 0) { |
| 51 | + codeLens.push(new vscode.CodeLens(range, { |
31 | 52 | title: "Solution",
|
32 | 53 | command: "leetcode.showSolution",
|
33 | 54 | arguments: [document.uri],
|
34 |
| - }), |
35 |
| - new vscode.CodeLens(range, { |
36 |
| - title: "Preview", |
| 55 | + })); |
| 56 | + } |
| 57 | + |
| 58 | + if (shortcuts.indexOf("description") >= 0) { |
| 59 | + codeLens.push(new vscode.CodeLens(range, { |
| 60 | + title: "Description", |
37 | 61 | command: "leetcode.previewProblem",
|
38 | 62 | arguments: [document.uri],
|
39 |
| - }), |
40 |
| - ]; |
| 63 | + })); |
| 64 | + } |
| 65 | + |
| 66 | + return codeLens; |
41 | 67 | }
|
42 | 68 | }
|
0 commit comments