forked from LeetCode-OpenSource/vscode-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCodeLensProvider.ts
30 lines (24 loc) · 1004 Bytes
/
CustomCodeLensProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
export class CustomCodeLensProvider implements vscode.CodeLensProvider {
private validFileNamePattern: RegExp = /\d+\..*\.(.+)/;
public provideCodeLenses(document: vscode.TextDocument): vscode.ProviderResult<vscode.CodeLens[]> {
const fileName: string = document.fileName.trim();
const matchResult: RegExpMatchArray | null = fileName.match(this.validFileNamePattern);
if (!matchResult) {
return undefined;
}
const range: vscode.Range = new vscode.Range(document.lineCount - 1, 0, document.lineCount - 1, 0);
return [
new vscode.CodeLens(range, {
title: "Submit",
command: "leetcode.submitSolution",
}),
new vscode.CodeLens(range, {
title: "Test",
command: "leetcode.testSolution",
}),
];
}
}