Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb77d76a

Browse files
authored
Can config whether to show or hide the codelens (LeetCode-OpenSource#273)
1 parent781feb2 commitb77d76a

File tree

6 files changed

+75
-15
lines changed

6 files changed

+75
-15
lines changed

‎README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/submit.png"alt="Submit the Answer" />
9494
</p>
9595

96-
- You can submit the answer by clicking`🙏 Submit to LeetCode` at the bottom of the file. Or you can trigger the command:**LeetCode: Submit to LeetCode** to submit the**active** file as the answer.
96+
- You can submit the answer by clicking`Submit` at the bottom of the file. Or you can right click in the editor and select`Submit to LeetCode`.
97+
98+
>If you want to hide the shortcuts showing in the editor, just simply set the setting`leetcode.enableShortcuts` to false.
9799
98100
---
99101

@@ -102,7 +104,7 @@
102104
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/test.png"alt="Test the Answer" />
103105
</p>
104106

105-
-To**test** your answer, right click in the editor and select`Test in LeetCode`.
107+
-You cantest the answer by clicking`Test` at the bottom of the file. Or you can right click in the editor and select`Test in LeetCode`.
106108

107109
- There are 3 ways to test the answer:
108110
-**Test with the default cases**
@@ -138,6 +140,7 @@
138140
|`leetcode.endpoint`| Specify the active endpoint. Supported endpoints are:`leetcode`,`leetcode-cn`|`leetcode`|
139141
|`leetcode.outputFolder`| Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here: <ul><li>`${tag}`: Categorize the problem according to their tags.<li>`${language}`: Categorize the problem according to their language.</li><li>`${difficulty}`: Categorize the problem according to their difficulty.</li></ul>| N/A|
140142
|`leetcode.enableStatusBar`| Specify whether the LeetCode status bar will be shown or not.|`true`|
143+
|`leetcode.enableShortcuts`| Specify whether the submit and test shortcuts in editor or not.|`true`|
141144
|`leetcode.nodePath`| Specify the`Node.js` executable path.|`node`|
142145

143146
##Troubleshooting

‎docs/README_zh-CN.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/submit.png"alt="提交答案" />
9494
</p>
9595

96-
- 通过点击文件最下方的`🙏 Submit to LeetCode` 可提交答案。 你也可以触发**LeetCode: Submit to LeetCode** 命令将**当前**文件作为答案进行提交。
96+
- 通过点击文件最下方的`Submit` 可提交答案。 你也可以在编辑区内右键并选择`Submit to LeetCode`,将**当前**文件提交。
97+
98+
>如果你不希望在编辑器中显示**测试****提交**的快捷方式,可以将配置项`leetcode.enableShortcuts` 设置为`false`
9799
98100
---
99101

@@ -102,7 +104,7 @@
102104
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/test.png"alt="测试答案" />
103105
</p>
104106

105-
-在编辑区内右键并选择`Testin LeetCode`可对**当前**答案进行测试
107+
-通过点击文件最下方的`Test` 可测试答案。你也可以在编辑区内右键并选择`Testin LeetCode`**当前**文件进行测试
106108

107109
- 有下列三种测试集来源:
108110
-**默认测试集**:Test with the default cases
@@ -138,6 +140,7 @@
138140
|`leetcode.endpoint`| 指定使用的终端,可用终端有:`leetcode`,`leetcode-cn`|`leetcode`|
139141
|`leetcode.outputFolder`| 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:<ul><li>`${tag}`: 根据题目的类别进行分类。<li>`${language}`: 根据题目的语言进行分类。</li><li>`${difficulty}`: 根据题目的难度进行分类。</li></ul>| N/A|
140142
|`leetcode.enableStatusBar`| 指定是否在 VS Code 下方显示插件状态栏。|`true`|
143+
|`leetcode.enableShortcuts`| 指定是否在 VS Code 编辑文件下方显示提交和测试的快捷按钮。|`true`|
141144
|`leetcode.nodePath`| 指定`Node.js` 可执行文件的路径。|`node`|
142145

143146
##疑难解答

‎package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@
295295
"scope":"application",
296296
"description":"Show the LeetCode status bar or not."
297297
},
298+
"leetcode.enableShortcuts": {
299+
"type":"boolean",
300+
"default":true,
301+
"scope":"application",
302+
"description":"Show the submit and test shortcuts in editor or not."
303+
},
298304
"leetcode.nodePath": {
299305
"type":"string",
300306
"default":"node",

‎src/codelens/CodeLensController.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) jdneo. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import{ConfigurationChangeEvent,Disposable,languages,workspace,WorkspaceConfiguration}from"vscode";
5+
import{CustomCodeLensProvider}from"./CustomCodeLensProvider";
6+
7+
classCodeLensControllerimplementsDisposable{
8+
privateinternalProvider:CustomCodeLensProvider;
9+
privateregisteredProvider:Disposable|undefined;
10+
privateconfigurationChangeListener:Disposable;
11+
12+
constructor(){
13+
this.internalProvider=newCustomCodeLensProvider();
14+
15+
this.configurationChangeListener=workspace.onDidChangeConfiguration((event:ConfigurationChangeEvent)=>{
16+
if(event.affectsConfiguration("leetcode.enableShortcuts")){
17+
this.setCodeLensVisibility();
18+
}
19+
},this);
20+
21+
this.setCodeLensVisibility();
22+
}
23+
24+
publicdispose():void{
25+
if(this.registeredProvider){
26+
this.registeredProvider.dispose();
27+
}
28+
this.configurationChangeListener.dispose();
29+
}
30+
31+
privatesetCodeLensVisibility():void{
32+
if(this.isShortcutsEnabled()&&!this.registeredProvider){
33+
this.registeredProvider=languages.registerCodeLensProvider({scheme:"file"},this.internalProvider);
34+
}elseif(!this.isShortcutsEnabled()&&this.registeredProvider){
35+
this.registeredProvider.dispose();
36+
this.registeredProvider=undefined;
37+
}
38+
}
39+
40+
privateisShortcutsEnabled():boolean{
41+
constconfiguration:WorkspaceConfiguration=workspace.getConfiguration();
42+
returnconfiguration.get<boolean>("leetcode.enableShortcuts",true);
43+
}
44+
}
45+
46+
exportconstcodeLensController:CodeLensController=newCodeLensController();

‎src/codeLensProvider.tsrenamed to‎src/codelens/CustomCodeLensProvider.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import*asvscodefrom"vscode";
55

6-
classCodeLensProviderimplementsvscode.CodeLensProvider{
6+
exportclassCustomCodeLensProviderimplementsvscode.CodeLensProvider{
77

88
privatevalidFileNamePattern:RegExp=/\d+\..*\.(.+)/;
99

@@ -16,13 +16,15 @@ class CodeLensProvider implements vscode.CodeLensProvider {
1616

1717
constrange:vscode.Range=newvscode.Range(document.lineCount-1,0,document.lineCount-1,0);
1818

19-
constlens:vscode.CodeLens=newvscode.CodeLens(range,{
20-
title:"🙏 Submit to LeetCode",
21-
command:"leetcode.submitSolution",
22-
});
23-
24-
return[lens];
19+
return[
20+
newvscode.CodeLens(range,{
21+
title:"Submit",
22+
command:"leetcode.submitSolution",
23+
}),
24+
newvscode.CodeLens(range,{
25+
title:"Test",
26+
command:"leetcode.testSolution",
27+
}),
28+
];
2529
}
2630
}
27-
28-
exportconstcodeLensProvider:CodeLensProvider=newCodeLensProvider();

‎src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import*asvscodefrom"vscode";
5-
import{codeLensProvider}from"./codeLensProvider";
5+
import{codeLensController}from"./codelens/CodeLensController";
66
import*ascachefrom"./commands/cache";
77
import{switchDefaultLanguage}from"./commands/language";
88
import*aspluginfrom"./commands/plugin";
@@ -43,8 +43,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
4343
leetCodeSolutionProvider,
4444
leetCodeExecutor,
4545
markdownEngine,
46+
codeLensController,
4647
vscode.window.createTreeView("leetCodeExplorer",{treeDataProvider:leetCodeTreeDataProvider,showCollapseAll:true}),
47-
vscode.languages.registerCodeLensProvider({scheme:"file"},codeLensProvider),
4848
vscode.commands.registerCommand("leetcode.deleteCache",()=>cache.deleteCache()),
4949
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn",()=>plugin.switchEndpoint()),
5050
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn()),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp