@@ -5,20 +5,45 @@ import * as fse from "fs-extra";
5
5
import * as path from "path" ;
6
6
import * as unescapeJS from "unescape-js" ;
7
7
import * as vscode from "vscode" ;
8
+ import { explorerNodeManager } from "../explorer/explorerNodeManager" ;
8
9
import { LeetCodeNode } from "../explorer/LeetCodeNode" ;
9
10
import { leetCodeChannel } from "../leetCodeChannel" ;
10
11
import { leetCodeExecutor } from "../leetCodeExecutor" ;
11
12
import { leetCodeManager } from "../leetCodeManager" ;
12
13
import { IProblem , IQuickItemEx , languages , ProblemState } from "../shared" ;
14
+ import { getNodeIdFromFile } from "../utils/problemUtils" ;
13
15
import { DialogOptions , DialogType , openSettingsEditor , promptForOpenOutputChannel , promptForSignIn , promptHintMessage } from "../utils/uiUtils" ;
14
16
import { selectWorkspaceFolder } from "../utils/workspaceUtils" ;
15
17
import * as wsl from "../utils/wslUtils" ;
16
18
import { leetCodePreviewProvider } from "../webview/leetCodePreviewProvider" ;
17
19
import { leetCodeSolutionProvider } from "../webview/leetCodeSolutionProvider" ;
18
20
import * as list from "./list" ;
19
21
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 ) ;
22
47
leetCodePreviewProvider . show ( descString , node , isSideMode ) ;
23
48
}
24
49
@@ -54,7 +79,7 @@ export async function showSolution(input: LeetCodeNode | vscode.Uri): Promise<vo
54
79
} else if ( input instanceof vscode . Uri ) {
55
80
problemInput = `"${ input . fsPath } "` ;
56
81
} else {
57
- vscode . window . showErrorMessage ( "Invalid input to fetch the solution data" ) ;
82
+ vscode . window . showErrorMessage ( "Invalid input to fetch the solution data. " ) ;
58
83
return ;
59
84
}
60
85
0 commit comments