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

Using webview instead of open a file to show the result#89

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 1 commit intomasterfromcs/webview
Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 3 additions & 2 deletionssrc/commands/submit.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,8 @@
import*asvscodefrom"vscode";
import{leetCodeExecutor}from"../leetCodeExecutor";
import{leetCodeManager}from"../leetCodeManager";
import{DialogType,promptForOpenOutputChannel,promptForSignIn,showResultFile}from"../utils/uiUtils";
import{leetCodeResultProvider}from"../leetCodeResultProvider";
import{DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
import{getActivefilePath}from"../utils/workspaceUtils";

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

try{
constresult:string=awaitleetCodeExecutor.submitSolution(filePath);
awaitshowResultFile(result);
awaitleetCodeResultProvider.show(result);
}catch(error){
awaitpromptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.",DialogType.error);
}
Expand Down
5 changes: 3 additions & 2 deletionssrc/commands/test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,8 +5,9 @@ import * as fse from "fs-extra";
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { leetCodeResultProvider } from "../leetCodeResultProvider";
import { IQuickItemEx, UserStatus } from "../shared";
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog, showResultFile } from "../utils/uiUtils";
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog } from "../utils/uiUtils";
import { getActivefilePath } from "../utils/workspaceUtils";

export async function testSolution(uri?: vscode.Uri): Promise<void> {
Expand DownExpand Up@@ -78,7 +79,7 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
if (!result) {
return;
}
awaitshowResultFile(result);
awaitleetCodeResultProvider.show(result);
} catch (error) {
await promptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.", DialogType.error);
}
Expand Down
3 changes: 3 additions & 0 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import { leetCodeChannel } from "./leetCodeChannel";
import { leetCodeExecutor } from "./leetCodeExecutor";
import { LeetCodeNode, LeetCodeTreeDataProvider } from "./leetCodeExplorer";
import { leetCodeManager } from "./leetCodeManager";
import { leetCodeResultProvider } from "./leetCodeResultProvider";
import { leetCodeStatusBarItem } from "./leetCodeStatusBarItem";

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

const leetCodeTreeDataProvider: LeetCodeTreeDataProvider = new LeetCodeTreeDataProvider(context);
leetCodeResultProvider.initialize(context);

context.subscriptions.push(
leetCodeStatusBarItem,
leetCodeChannel,
leetCodeResultProvider,
vscode.window.registerTreeDataProvider("leetCodeExplorer", leetCodeTreeDataProvider),
vscode.languages.registerCodeLensProvider({ scheme: "file" }, codeLensProvider),
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
Expand Down
52 changes: 52 additions & 0 deletionssrc/leetCodeResultProvider.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import { Disposable, ExtensionContext, ViewColumn, WebviewPanel, window } from "vscode";

class LeetCodeResultProvider implements Disposable {

private context: ExtensionContext;
private panel: WebviewPanel | undefined;

public initialize(context: ExtensionContext): void {
this.context = context;
}

public async show(result: string): Promise<void> {
if (!this.panel) {
this.panel = window.createWebviewPanel("leetCode", "LeetCode Results", ViewColumn.Active, {
retainContextWhenHidden: true,
enableFindWidget: true,
});

this.panel.onDidDispose(() => {
this.panel = undefined;
}, null, this.context.subscriptions);
}

this.panel.webview.html = await this.provideHtmlContent(result);
this.panel.reveal(ViewColumn.Active);
}

public dispose(): void {
if (this.panel) {
this.panel.dispose();
}
}

private async provideHtmlContent(result: string): Promise<string> {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LeetCode Results</title>
</head>
<body>
<pre>${result.trim()}</pre>
</body>
</html>`;
}
}

export const leetCodeResultProvider: LeetCodeResultProvider = new LeetCodeResultProvider();
10 changes: 0 additions & 10 deletionssrc/utils/uiUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import * as fse from "fs-extra";
import * as opn from "opn";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { isLeetCodeCnEnabled } from "../commands/plugin";
import { leetCodeChannel } from "../leetCodeChannel";
Expand DownExpand Up@@ -73,13 +70,6 @@ export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined>
return await vscode.window.showOpenDialog(options);
}

export async function showResultFile(result: string): Promise<void> {
const resultPath: string = path.join(os.homedir(), ".leetcode", "Result");
await fse.ensureFile(resultPath);
await fse.writeFile(resultPath, result);
await vscode.window.showTextDocument(vscode.Uri.file(resultPath));
}

export enum DialogType {
info = "info",
warning = "warning",
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp