diff --git a/README.md b/README.md
index 490db51e..3396d0c7 100644
--- a/README.md
+++ b/README.md
@@ -90,9 +90,10 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
-- 插件会在编辑区域内支持四种不同的快捷方式(Code Lens):
+- 插件会在编辑区域内支持五种不同的快捷方式(Code Lens):
- `Submit`: 提交你的答案至 LeetCode;
- `Test`: 用给定的测试用例测试你的答案;
+ - `Star`: 收藏或取消收藏该问题;
- `Solution`: 显示该问题的高票解答;
- `Description`: 显示该问题的题目描述。
@@ -129,7 +130,7 @@
| `leetcode.workspaceFolder` | 指定保存文件的工作区目录 | `""` |
| `leetcode.filePath` | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%98%E7%9B%AE%E6%96%87%E4%BB%B6%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%96%87%E4%BB%B6%E5%A4%B9%E8%B7%AF%E5%BE%84%E5%92%8C%E6%96%87%E4%BB%B6%E5%90%8D)。 | |
| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
-| `leetcode.editor.shortcuts` | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `solution`, `description`。 | `["submit, test"]` |
+| `leetcode.editor.shortcuts` | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `star`, `solution`, `description`。 | `["submit, test"]` |
| `leetcode.enableSideMode` | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` |
| `leetcode.nodePath` | 指定 `Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe | `node` |
| `leetcode.showCommentDescription` | 指定是否要在注释中显示题干。 | `false` |
diff --git a/package.json b/package.json
index b6164f17..81a8536b 100644
--- a/package.json
+++ b/package.json
@@ -629,8 +629,16 @@
"enum": [
"submit",
"test",
+ "star",
"solution",
"description"
+ ],
+ "enumDescriptions": [
+ "Submit your answer to LeetCode.",
+ "Test your answer with customized test cases.",
+ "Star or unstar the current problem.",
+ "Show the top voted solution for the current problem.",
+ "Show the problem description page."
]
},
"description": "Customize the shorcuts in editors."
diff --git a/src/codelens/CodeLensController.ts b/src/codelens/CodeLensController.ts
index 8e2fa3c9..b41f28f0 100644
--- a/src/codelens/CodeLensController.ts
+++ b/src/codelens/CodeLensController.ts
@@ -2,7 +2,7 @@
// Licensed under the MIT license.
import { ConfigurationChangeEvent, Disposable, languages, workspace } from "vscode";
-import { CustomCodeLensProvider } from "./CustomCodeLensProvider";
+import { customCodeLensProvider, CustomCodeLensProvider } from "./CustomCodeLensProvider";
class CodeLensController implements Disposable {
private internalProvider: CustomCodeLensProvider;
@@ -10,7 +10,7 @@ class CodeLensController implements Disposable {
private configurationChangeListener: Disposable;
constructor() {
- this.internalProvider = new CustomCodeLensProvider();
+ this.internalProvider = customCodeLensProvider;
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("leetcode.editor.shortcuts")) {
diff --git a/src/codelens/CustomCodeLensProvider.ts b/src/codelens/CustomCodeLensProvider.ts
index 4764e999..4b9b6491 100644
--- a/src/codelens/CustomCodeLensProvider.ts
+++ b/src/codelens/CustomCodeLensProvider.ts
@@ -2,6 +2,8 @@
// Licensed under the MIT license.
import * as vscode from "vscode";
+import { explorerNodeManager } from "../explorer/explorerNodeManager";
+import { LeetCodeNode } from "../explorer/LeetCodeNode";
import { getEditorShortcuts } from "../utils/settingUtils";
export class CustomCodeLensProvider implements vscode.CodeLensProvider {
@@ -23,10 +25,15 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
}
const content: string = document.getText();
- const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=.* lang=.*/);
+ const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=.*/);
if (!matchResult) {
return undefined;
}
+ const nodeId: string | undefined = matchResult[1];
+ let node: LeetCodeNode | undefined;
+ if (nodeId) {
+ node = explorerNodeManager.getNodeById(nodeId);
+ }
let codeLensLine: number = document.lineCount - 1;
for (let i: number = document.lineCount - 1; i >= 0; i--) {
@@ -56,6 +63,14 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
}));
}
+ if (shortcuts.indexOf("star") >= 0 && node) {
+ codeLens.push(new vscode.CodeLens(range, {
+ title: node.isFavorite ? "Unstar" : "Star",
+ command: node.isFavorite ? "leetcode.removeFavorite" : "leetcode.addFavorite",
+ arguments: [node],
+ }));
+ }
+
if (shortcuts.indexOf("solution") >= 0) {
codeLens.push(new vscode.CodeLens(range, {
title: "Solution",
@@ -75,3 +90,5 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
return codeLens;
}
}
+
+export const customCodeLensProvider: CustomCodeLensProvider = new CustomCodeLensProvider();
diff --git a/src/commands/star.ts b/src/commands/star.ts
index baae0b07..36611499 100644
--- a/src/commands/star.ts
+++ b/src/commands/star.ts
@@ -2,15 +2,20 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
+import { customCodeLensProvider } from "../codelens/CustomCodeLensProvider";
import { LeetCodeNode } from "../explorer/LeetCodeNode";
import { leetCodeTreeDataProvider } from "../explorer/LeetCodeTreeDataProvider";
import { leetCodeExecutor } from "../leetCodeExecutor";
+import { hasStarShortcut } from "../utils/settingUtils";
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
export async function addFavorite(node: LeetCodeNode): Promise