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

Commit1893d34

Browse files
authored
fix:LeetCode-OpenSource#593 by adding global flag to remove cache (LeetCode-OpenSource#602)
1 parent5fa449e commit1893d34

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

‎src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { markdownEngine } from "./webview/markdownEngine";
2626

2727
exportasyncfunctionactivate(context:vscode.ExtensionContext):Promise<void>{
2828
try{
29-
if(!awaitleetCodeExecutor.meetRequirements()){
29+
if(!awaitleetCodeExecutor.meetRequirements(context)){
3030
thrownewError("The environment doesn't meet requirements.");
3131
}
3232

‎src/leetCodeExecutor.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import*ascpfrom"child_process";
55
import*asfsefrom"fs-extra";
6+
import*asosfrom"os";
67
import*aspathfrom"path";
78
import*asrequireFromStringfrom"require-from-string";
9+
import{ExtensionContext}from"vscode";
810
import{ConfigurationChangeEvent,Disposable,MessageItem,window,workspace,WorkspaceConfiguration}from"vscode";
9-
import{Endpoint,IProblem,supportedPlugins}from"./shared";
11+
import{Endpoint,IProblem,leetcodeHasInited,supportedPlugins}from"./shared";
1012
import{executeCommand,executeCommandWithProgress}from"./utils/cpUtils";
1113
import{DialogOptions,openUrl}from"./utils/uiUtils";
1214
import*aswslfrom"./utils/wslUtils";
@@ -34,7 +36,11 @@ class LeetCodeExecutor implements Disposable {
3436
return`"${path.join(this.leetCodeRootPath,"bin","leetcode")}"`;
3537
}
3638

37-
publicasyncmeetRequirements():Promise<boolean>{
39+
publicasyncmeetRequirements(context:ExtensionContext):Promise<boolean>{
40+
consthasInited:boolean|undefined=context.globalState.get(leetcodeHasInited);
41+
if(!hasInited){
42+
awaitthis.removeOldCache();
43+
}
3844
if(this.nodeExecutable!=="node"){
3945
if(!awaitfse.pathExists(this.nodeExecutable)){
4046
thrownewError(`The Node.js executable does not exist on path${this.nodeExecutable}`);
@@ -60,10 +66,13 @@ class LeetCodeExecutor implements Disposable {
6066
for(constpluginofsupportedPlugins){
6167
try{// Check plugin
6268
awaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"plugin","-e",plugin]);
63-
}catch(error){// Download plugin and activate
69+
}catch(error){// Remove old cache that may cause the error download plugin and activate
70+
awaitthis.removeOldCache();
6471
awaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"plugin","-i",plugin]);
6572
}
6673
}
74+
// Set the global state HasInited true to skip delete old cache after init
75+
context.globalState.update(leetcodeHasInited,true);
6776
returntrue;
6877
}
6978

@@ -76,7 +85,7 @@ class LeetCodeExecutor implements Disposable {
7685
}
7786

7887
publicasyncsignOut():Promise<string>{
79-
returnawaitawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"user","-L"]);
88+
returnawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"user","-L"]);
8089
}
8190

8291
publicasynclistProblems(showLocked:boolean):Promise<string>{
@@ -194,6 +203,14 @@ class LeetCodeExecutor implements Disposable {
194203
}
195204
returnawaitexecuteCommandWithProgress(message,command,args,options);
196205
}
206+
207+
privateasyncremoveOldCache():Promise<void>{
208+
constoldPath:string=path.join(os.homedir(),".lc");
209+
if(awaitfse.pathExists(oldPath)){
210+
awaitfse.remove(oldPath);
211+
}
212+
}
213+
197214
}
198215

199216
exportconstleetCodeExecutor:LeetCodeExecutor=newLeetCodeExecutor();

‎src/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@ export enum DescriptionConfiguration {
114114
Both="Both",
115115
None="None",
116116
}
117+
118+
exportconstleetcodeHasInited:string="leetcode.hasInited";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp