Skip to content

(1)修复无法打开问题描述(2)同时生成markdown描述(3)同时生成多语言版本 #841

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
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Fix previewProblem command not work
  • Loading branch information
Yuelioi authored Sep 18, 2022
commit df7f083943f008fc23d0643714effd1036a932f3
51 changes: 38 additions & 13 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,49 @@ 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);

let id = "";

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

if (editor) {
const fsPath = editor.document.fileName;
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) {
vscode.window.showErrorMessage(`Failed to resolve the problem id from file: ${activeFilePath}.`);
return;
id = path.basename(fsPath).split(".")[0];
}
const cachedNode: IProblem | undefined = explorerNodeManager.getNodeById(id);
if (!cachedNode) {
vscode.window.showErrorMessage(`Failed to resolve the problem with id: ${id}.`);

if (!id) {
vscode.window.showErrorMessage(`Failed to resolve the problem id from file: ${fsPath}.`);
return;
}
node = cachedNode;
// Move the preview page aside if it's triggered from Code Lens
isSideMode = true;
} else {
node = input;
}
const cachedNode: IProblem | undefined = explorerNodeManager.getNodeById(id);
if (!cachedNode) {
vscode.window.showErrorMessage(`Failed to resolve the problem with id: ${id}.`);
return;
}
node = cachedNode;
// Move the preview page aside if it's triggered from Code Lens
isSideMode = true;
// } else {
// node = input;
// }
const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
const descString: string = await leetCodeExecutor.getDescription(node.id, needTranslation);
leetCodePreviewProvider.show(descString, node, isSideMode);
Expand Down