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

修复 previewProblem 命令不正常工作 #840

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

Closed
Yuelioi wants to merge 1 commit into LeetCode-OpenSource:master from Yuelioi:master
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
修复 previewProblem 命令不正常工作
跳过input验证 直接根据当前编辑器活动文件读取/判断题目id
  • Loading branch information
Yuelioi authored Sep 18, 2022
commit 122e36aad854f80edafee9fe3b5df9813e7caec1
35 changes: 29 additions & 6 deletions src/commands/show.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,32 @@ import * as list from "./list";

export async function previewProblem(input: IProblem | vscode.Uri, isSideMode: boolean = false): Promise<void> {
let node: IProblem;
if (input instanceof vscode.Uri) {
const activeFilePath: string = input.fsPath;
const id: string = await getNodeIdFromFile(activeFilePath);
// I dont know why I use this command, it not work,maybe theproblem of "input"?
// 不知道为什么,当我直接使用这个命令,他并不会正常工作,也许input的问题

//if (input instanceof vscode.Uri) {
// const activeFilePath: string = input.fsPath;
// const id: string = await getNodeIdFromFile(activeFilePath);
const editor = vscode.window.activeTextEditor;
let id:string;

// * We can read file throught editor.document not fs
// * 我们可以直接用自带API读取文件内容,从而跳过input判断
const editor = vscode.window.activeTextEditor;
if (editor) {
let fileContent = editor.document.getText();

const matchResults = fileContent.match(/@lc.+id=(.+?) /);
if (matchResults && matchResults.length === 2) {
id = matchResults[1];
}


// Try to get id from file name if getting from comments failed
if (!id) {
id = path.basename(fsPath).split(".")[0];
}

if (!id) {
vscode.window.showErrorMessage(`Failed to resolve the problem id from file: ${activeFilePath}.`);
return;
Expand All @@ -38,9 +61,9 @@ export async function previewProblem(input: IProblem | vscode.Uri, isSideMode: b
node = cachedNode;
// Move the preview page aside if it's triggered from Code Lens
isSideMode = true;
} else {
node = input;
}
// } else {
// node = input;
// }
const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
const descString: string = await leetCodeExecutor.getDescription(node.id, needTranslation);
leetCodePreviewProvider.show(descString, node, isSideMode);
Expand Down

AltStyle によって変換されたページ (->オリジナル) /