forked from LeetCode-OpenSource/vscode-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeLensProvider.ts
28 lines (20 loc) · 955 Bytes
/
codeLensProvider.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
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
class CodeLensProvider 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);
const lens: vscode.CodeLens = new vscode.CodeLens(range, {
title: "🙏 Submit to LeetCode",
command: "leetcode.submitSolution",
});
return [lens];
}
}
export const codeLensProvider: CodeLensProvider = new CodeLensProvider();