-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: #593 by adding global flag to remove cache #602
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
|
||
import * as cp from "child_process"; | ||
import * as fse from "fs-extra"; | ||
import * as os from "os"; | ||
import * as path from "path"; | ||
import * as requireFromString from "require-from-string"; | ||
import { ExtensionContext } from "vscode"; | ||
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode"; | ||
import { Endpoint, IProblem, supportedPlugins } from "./shared"; | ||
import { Endpoint, IProblem, leetcodeHasInited, supportedPlugins } from "./shared"; | ||
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils"; | ||
import { DialogOptions, openUrl } from "./utils/uiUtils"; | ||
import * as wsl from "./utils/wslUtils"; | ||
|
@@ -34,7 +36,11 @@ class LeetCodeExecutor implements Disposable { | |
return `"${path.join(this.leetCodeRootPath, "bin", "leetcode")}"`; | ||
} | ||
|
||
public async meetRequirements(): Promise<boolean> { | ||
public async meetRequirements(context: ExtensionContext): Promise<boolean> { | ||
const hasInited: boolean | undefined = context.globalState.get(leetcodeHasInited); | ||
if (!hasInited) { | ||
await this.removeOldCache(); | ||
} | ||
if (this.nodeExecutable !== "node") { | ||
if (!await fse.pathExists(this.nodeExecutable)) { | ||
throw new Error(`The Node.js executable does not exist on path ${this.nodeExecutable}`); | ||
|
@@ -60,10 +66,13 @@ class LeetCodeExecutor implements Disposable { | |
for (const plugin of supportedPlugins) { | ||
try { // Check plugin | ||
await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", plugin]); | ||
} catch (error) { // Download plugin and activate | ||
} catch (error) { // Remove old cache that may cause the error download plugin and activate | ||
await this.removeOldCache(); | ||
await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-i", plugin]); | ||
} | ||
} | ||
// Set the global state HasInited true to skip delete old cache after init | ||
context.globalState.update(leetcodeHasInited, true); | ||
return true; | ||
} | ||
|
||
|
@@ -76,7 +85,7 @@ class LeetCodeExecutor implements Disposable { | |
} | ||
|
||
public async signOut(): Promise<string> { | ||
return await await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "user", "-L"]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that its an old typo so I changed it too, am I right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "user", "-L"]); | ||
} | ||
|
||
public async listProblems(showLocked: boolean): Promise<string> { | ||
|
@@ -194,6 +203,14 @@ class LeetCodeExecutor implements Disposable { | |
} | ||
return await executeCommandWithProgress(message, command, args, options); | ||
} | ||
|
||
private async removeOldCache(): Promise<void> { | ||
const oldPath: string = path.join(os.homedir(), ".lc"); | ||
if (await fse.pathExists(oldPath)) { | ||
await fse.remove(oldPath); | ||
} | ||
} | ||
|
||
} | ||
|
||
export const leetCodeExecutor: LeetCodeExecutor = new LeetCodeExecutor(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse the command we have?
https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/src/extension.ts#L51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little different.The command way use leetcode-cli way not delete the whole dir, let me check if it works fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdneo
delete cache only delete the user session but not the plugin.js cache, still have that issue. So I think we can not use it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to change the implementation of the command
delete cache
. Considering that the current implementation does not clean entirely?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, current one only clean the user info(include session), but we change the
delete cache
also have one problem beacuse user may have two account one leetcode one leetcode-cn, if we change that. both will clean, but user may only want to clean the current cache.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. So let's keep the implementation. Maybe later we can provide two option in this command. Something like
Session
andAll
. Anyway it's not a high priority