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

Commitf3946b9

Browse files
TsFreddiejdneo
authored andcommitted
Support locked problems (LeetCode-OpenSource#19)
1 parentf58422f commitf3946b9

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

‎package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
{
130130
"title":"LeetCode",
131131
"properties": {
132+
"leetcode.showLocked": {
133+
"type":"boolean",
134+
"default":false,
135+
"description":"Show locked problems."
136+
},
132137
"leetcode.defaultLanguage": {
133138
"type":"string",
134139
"enum": [

‎resources/lock.png

2.49 KB
Loading

‎src/commands/list.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { executeCommand } from "../utils/cpUtils";
77
import{DialogType,promptForOpenOutputChannel}from"../utils/uiUtils";
88

99
exportinterfaceIProblem{
10+
favorite:boolean;
11+
locked:boolean;
1012
state:ProblemState;
1113
id:string;
1214
name:string;
@@ -19,19 +21,23 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
1921
if(leetCodeManager.getStatus()===UserStatus.SignedOut){
2022
return[];
2123
}
22-
constresult:string=awaitexecuteCommand(channel,"node",[leetCodeBinaryPath,"list","-q","L"]);
24+
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
25+
constshowLocked:boolean|undefined=leetCodeConfig.get<boolean>("showLocked");
26+
constresult:string=awaitexecuteCommand(channel,"node",showLocked ?[leetCodeBinaryPath,"list"] :[leetCodeBinaryPath,"list","-q","L"]);
2327
constproblems:IProblem[]=[];
2428
constlines:string[]=result.split("\n");
25-
constreg:RegExp=/(.?)\s*\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+%)\)/;
29+
constreg:RegExp=/^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+%)\)/;
2630
for(constlineoflines){
2731
constmatch:RegExpMatchArray|null=line.match(reg);
28-
if(match&&match.length===6){
32+
if(match&&match.length===8){
2933
problems.push({
30-
state:parseProblemState(match[1]),
31-
id:match[2].trim(),
32-
name:match[3].trim(),
33-
difficulty:match[4].trim(),
34-
passRate:match[5].trim(),
34+
favorite:match[1].trim().length>0,
35+
locked:match[2].trim().length>0,
36+
state:parseProblemState(match[3]),
37+
id:match[4].trim(),
38+
name:match[5].trim(),
39+
difficulty:match[6].trim(),
40+
passRate:match[7].trim(),
3541
});
3642
}
3743
}

‎src/commands/show.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<
8181
constpicks:Array<IQuickItemEx<string>>=(awaitp).map((problem:list.IProblem)=>Object.assign({},{
8282
label:`${parseProblemDecorator(problem.state)}${problem.id}.${problem.name}`,
8383
description:"",
84-
detail:`AC rate:${problem.passRate}, Difficulty:${problem.difficulty}`,
84+
detail:`${parseLockDecorator(problem.locked)}AC rate:${problem.passRate}, Difficulty:${problem.difficulty}`,
8585
value:problem.id,
8686
}));
8787
resolve(picks);
@@ -98,3 +98,7 @@ function parseProblemDecorator(state: ProblemState): string {
9898
return"";
9999
}
100100
}
101+
102+
functionparseLockDecorator(locked:boolean):string{
103+
returnlocked ?"$(lock) " :"";
104+
}

‎src/leetCodeExplorer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { ProblemState } from "./shared";
1010
exportclassLeetCodeNode{
1111
constructor(privatedata:list.IProblem,privateisProblemNode=true){}
1212

13+
publicgetlocked():boolean{
14+
returnthis.data.locked;
15+
}
1316
publicgetname():string{
1417
returnthis.data.name;
1518
}
@@ -74,6 +77,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
7477
return[
7578
newLeetCodeNode(
7679
{
80+
favorite:false,
81+
locked:false,
7782
state:ProblemState.Unknown,
7883
id:"notSignIn",
7984
name:"Sign in to LeetCode",
@@ -125,6 +130,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
125130
difficultynodes.push(
126131
newLeetCodeNode(
127132
{
133+
favorite:false,
134+
locked:false,
128135
state:ProblemState.Unknown,
129136
id:difficulty,
130137
name:difficulty,
@@ -163,6 +170,9 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
163170
caseProblemState.NotAC:
164171
returnthis.context.asAbsolutePath(path.join("resources","x.png"));
165172
caseProblemState.Unknown:
173+
if(element.locked){
174+
returnthis.context.asAbsolutePath(path.join("resources","lock.png"));
175+
}
166176
returnthis.context.asAbsolutePath(path.join("resources","blank.png"));
167177
default:
168178
return"";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp