@@ -5,20 +5,45 @@ import * as fse from "fs-extra";
55import * as path from "path" ;
66import * as unescapeJS from "unescape-js" ;
77import * as vscode from "vscode" ;
8+ import { explorerNodeManager } from "../explorer/explorerNodeManager" ;
89import { LeetCodeNode } from "../explorer/LeetCodeNode" ;
910import { leetCodeChannel } from "../leetCodeChannel" ;
1011import { leetCodeExecutor } from "../leetCodeExecutor" ;
1112import { leetCodeManager } from "../leetCodeManager" ;
1213import { IProblem , IQuickItemEx , languages , ProblemState } from "../shared" ;
14+ import { getNodeIdFromFile } from "../utils/problemUtils" ;
1315import { DialogOptions , DialogType , openSettingsEditor , promptForOpenOutputChannel , promptForSignIn , promptHintMessage } from "../utils/uiUtils" ;
1416import { selectWorkspaceFolder } from "../utils/workspaceUtils" ;
1517import * as wsl from "../utils/wslUtils" ;
1618import { leetCodePreviewProvider } from "../webview/leetCodePreviewProvider" ;
1719import { leetCodeSolutionProvider } from "../webview/leetCodeSolutionProvider" ;
1820import * as list from "./list" ;
1921
20- export async function previewProblem ( node : IProblem , isSideMode : boolean = false ) : Promise < void > {
21- const descString : string = await leetCodeExecutor . getDescription ( node ) ;
22+ export async function previewProblem ( input : IProblem | vscode . Uri , isSideMode : boolean = false ) : Promise < void > {
23+ let node : LeetCodeNode ;
24+ if ( input instanceof LeetCodeNode ) {
25+ node = input ;
26+ } else if ( input instanceof vscode . Uri ) {
27+ const activeFilePath : string = input . fsPath ;
28+ const id : string = await getNodeIdFromFile ( activeFilePath ) ;
29+ if ( ! id ) {
30+ vscode . window . showErrorMessage ( `Failed to resolve the problem id from file: ${ activeFilePath } .` ) ;
31+ return ;
32+ }
33+ const cachedNode : LeetCodeNode | undefined = explorerNodeManager . getNodeById ( id ) ;
34+ if ( ! cachedNode ) {
35+ vscode . window . showErrorMessage ( `Failed to resolve the problem with id: ${ id } .` ) ;
36+ return ;
37+ }
38+ node = cachedNode ;
39+ // Move the preview page aside if it's triggered from Code Lens
40+ isSideMode = true ;
41+ } else {
42+ vscode . window . showErrorMessage ( "Invalid input to fetch the preview data." ) ;
43+ return ;
44+ }
45+
46+ const descString : string = await leetCodeExecutor . getDescription ( node . id ) ;
2247 leetCodePreviewProvider . show ( descString , node , isSideMode ) ;
2348}
2449
@@ -54,7 +79,7 @@ export async function showSolution(input: LeetCodeNode | vscode.Uri): Promise<vo
5479 } else if ( input instanceof vscode . Uri ) {
5580 problemInput = `"${ input . fsPath } "` ;
5681 } else {
57- vscode . window . showErrorMessage ( "Invalid input to fetch the solution data" ) ;
82+ vscode . window . showErrorMessage ( "Invalid input to fetch the solution data. " ) ;
5883 return ;
5984 }
6085
0 commit comments