Movatterモバイル変換


[0]ホーム

URL:


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

Commite257c76

Browse files
authored
Using webview instead of open a file to show the result (LeetCode-OpenSource#89)
1 parent74bf2b7 commite257c76

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

‎src/commands/submit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import*asvscodefrom"vscode";
55
import{leetCodeExecutor}from"../leetCodeExecutor";
66
import{leetCodeManager}from"../leetCodeManager";
7-
import{DialogType,promptForOpenOutputChannel,promptForSignIn,showResultFile}from"../utils/uiUtils";
7+
import{leetCodeResultProvider}from"../leetCodeResultProvider";
8+
import{DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
89
import{getActivefilePath}from"../utils/workspaceUtils";
910

1011
exportasyncfunctionsubmitSolution(uri?:vscode.Uri):Promise<void>{
@@ -20,7 +21,7 @@ export async function submitSolution(uri?: vscode.Uri): Promise<void> {
2021

2122
try{
2223
constresult:string=awaitleetCodeExecutor.submitSolution(filePath);
23-
awaitshowResultFile(result);
24+
awaitleetCodeResultProvider.show(result);
2425
}catch(error){
2526
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.",DialogType.error);
2627
}

‎src/commands/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import * as fse from "fs-extra";
55
import*asvscodefrom"vscode";
66
import{leetCodeExecutor}from"../leetCodeExecutor";
77
import{leetCodeManager}from"../leetCodeManager";
8+
import{leetCodeResultProvider}from"../leetCodeResultProvider";
89
import{IQuickItemEx,UserStatus}from"../shared";
9-
import{DialogType,promptForOpenOutputChannel,showFileSelectDialog,showResultFile}from"../utils/uiUtils";
10+
import{DialogType,promptForOpenOutputChannel,showFileSelectDialog}from"../utils/uiUtils";
1011
import{getActivefilePath}from"../utils/workspaceUtils";
1112

1213
exportasyncfunctiontestSolution(uri?:vscode.Uri):Promise<void>{
@@ -78,7 +79,7 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
7879
if(!result){
7980
return;
8081
}
81-
awaitshowResultFile(result);
82+
awaitleetCodeResultProvider.show(result);
8283
}catch(error){
8384
awaitpromptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.",DialogType.error);
8485
}

‎src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { leetCodeChannel } from "./leetCodeChannel";
1313
import{leetCodeExecutor}from"./leetCodeExecutor";
1414
import{LeetCodeNode,LeetCodeTreeDataProvider}from"./leetCodeExplorer";
1515
import{leetCodeManager}from"./leetCodeManager";
16+
import{leetCodeResultProvider}from"./leetCodeResultProvider";
1617
import{leetCodeStatusBarItem}from"./leetCodeStatusBarItem";
1718

1819
exportasyncfunctionactivate(context:vscode.ExtensionContext):Promise<void>{
@@ -26,10 +27,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
2627
});
2728

2829
constleetCodeTreeDataProvider:LeetCodeTreeDataProvider=newLeetCodeTreeDataProvider(context);
30+
leetCodeResultProvider.initialize(context);
2931

3032
context.subscriptions.push(
3133
leetCodeStatusBarItem,
3234
leetCodeChannel,
35+
leetCodeResultProvider,
3336
vscode.window.registerTreeDataProvider("leetCodeExplorer",leetCodeTreeDataProvider),
3437
vscode.languages.registerCodeLensProvider({scheme:"file"},codeLensProvider),
3538
vscode.commands.registerCommand("leetcode.deleteCache",()=>cache.deleteCache()),

‎src/leetCodeResultProvider.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) jdneo. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import{Disposable,ExtensionContext,ViewColumn,WebviewPanel,window}from"vscode";
5+
6+
classLeetCodeResultProviderimplementsDisposable{
7+
8+
privatecontext:ExtensionContext;
9+
privatepanel:WebviewPanel|undefined;
10+
11+
publicinitialize(context:ExtensionContext):void{
12+
this.context=context;
13+
}
14+
15+
publicasyncshow(result:string):Promise<void>{
16+
if(!this.panel){
17+
this.panel=window.createWebviewPanel("leetCode","LeetCode Results",ViewColumn.Active,{
18+
retainContextWhenHidden:true,
19+
enableFindWidget:true,
20+
});
21+
22+
this.panel.onDidDispose(()=>{
23+
this.panel=undefined;
24+
},null,this.context.subscriptions);
25+
}
26+
27+
this.panel.webview.html=awaitthis.provideHtmlContent(result);
28+
this.panel.reveal(ViewColumn.Active);
29+
}
30+
31+
publicdispose():void{
32+
if(this.panel){
33+
this.panel.dispose();
34+
}
35+
}
36+
37+
privateasyncprovideHtmlContent(result:string):Promise<string>{
38+
return`<!DOCTYPE html>
39+
<html lang="en">
40+
<head>
41+
<meta charset="UTF-8">
42+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
43+
<title>LeetCode Results</title>
44+
</head>
45+
<body>
46+
<pre>${result.trim()}</pre>
47+
</body>
48+
</html>`;
49+
}
50+
}
51+
52+
exportconstleetCodeResultProvider:LeetCodeResultProvider=newLeetCodeResultProvider();

‎src/utils/uiUtils.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Copyright (c) jdneo. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import*asfsefrom"fs-extra";
54
import*asopnfrom"opn";
6-
import*asosfrom"os";
7-
import*aspathfrom"path";
85
import*asvscodefrom"vscode";
96
import{isLeetCodeCnEnabled}from"../commands/plugin";
107
import{leetCodeChannel}from"../leetCodeChannel";
@@ -73,13 +70,6 @@ export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined>
7370
returnawaitvscode.window.showOpenDialog(options);
7471
}
7572

76-
exportasyncfunctionshowResultFile(result:string):Promise<void>{
77-
constresultPath:string=path.join(os.homedir(),".leetcode","Result");
78-
awaitfse.ensureFile(resultPath);
79-
awaitfse.writeFile(resultPath,result);
80-
awaitvscode.window.showTextDocument(vscode.Uri.file(resultPath));
81-
}
82-
8373
exportenumDialogType{
8474
info="info",
8575
warning="warning",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp