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

support trigger test command in file explorer#30

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/test
Mar 19, 2018
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
12 changes: 9 additions & 3 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,7 +81,7 @@
},
{
"command": "leetcode.testSolution",
"title": "Test",
"title": "Test in LeetCode",
"category": "LeetCode"
},
{
Expand DownExpand Up@@ -115,7 +115,7 @@
{
"command": "leetcode.showProblem",
"when": "view == leetCodeExplorer && viewItem == problem",
"group": "1@1"
"group": "leetcode-explorer@1"
}
],
"commandPalette": [
Expand All@@ -125,9 +125,15 @@
}
],
"explorer/context": [
{
"command": "leetcode.testSolution",
"when": "explorerResourceIsFolder == false",
"group": "file-explorer@1"
},
{
"command": "leetcode.submitSolution",
"when": "explorerResourceIsFolder == false"
"when": "explorerResourceIsFolder == false",
"group": "file-explorer@2"
}
]
},
Expand Down
17 changes: 4 additions & 13 deletionssrc/commands/submit.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,26 +5,17 @@ import { leetCodeManager } from "../leetCodeManager";
import { leetCodeBinaryPath } from "../shared";
import { executeCommand } from "../utils/cpUtils";
import { DialogType, promptForOpenOutputChannel, promptForSignIn, showResultFile } from "../utils/uiUtils";
import { getActivefilePath } from "../utils/workspaceUtils";

export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode.Uri): Promise<void> {
if (!leetCodeManager.getUser()) {
promptForSignIn();
return;
}

let filePath: string;
if (uri) {
filePath = uri.fsPath;
} else {
const textEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (!textEditor) {
return;
}
if (!textEditor.document.save()) {
vscode.window.showWarningMessage("Please save the solution file first.");
return;
}
filePath = textEditor.document.uri.fsPath;
const filePath: string | undefined = await getActivefilePath(uri);
if (!filePath) {
return;
}

try {
Expand Down
14 changes: 4 additions & 10 deletionssrc/commands/test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,24 +6,18 @@ import { leetCodeManager } from "../leetCodeManager";
import { IQuickItemEx, leetCodeBinaryPath, UserStatus } from "../shared";
import { executeCommand } from "../utils/cpUtils";
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog, showResultFile } from "../utils/uiUtils";
import { getActivefilePath } from "../utils/workspaceUtils";

export async function testSolution(channel: vscode.OutputChannel): Promise<void> {
export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.Uri): Promise<void> {
try {
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
return;
}

const activeText: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (!activeText) {
vscode.window.showErrorMessage("Please open a LeetCode solution file first.");
const filePath: string | undefined = await getActivefilePath(uri);
if (!filePath) {
return;
}
if (!activeText.document.save()) {
vscode.window.showWarningMessage("Please save the solution file first.");
return;
}

const filePath = activeText.document.uri.fsPath;
const picks: Array<IQuickItemEx<string>> = [];
picks.push(
{
Expand Down
4 changes: 2 additions & 2 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,8 +27,8 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(channel, node)),
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem(channel)),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
vscode.commands.registerCommand("leetcode.testSolution", () => test.testSolution(channel)),
vscode.commands.registerCommand("leetcode.submitSolution", (uri: vscode.Uri) => submit.submitSolution(channel, uri)),
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(channel, uri)),
vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(channel, uri)),
);

leetCodeManager.on("statusChanged", () => {
Expand Down
18 changes: 18 additions & 0 deletionssrc/utils/workspaceUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,3 +17,21 @@ export async function selectWorkspaceFolder(): Promise<string> {
}
return folder ? folder.uri.fsPath : path.join(os.homedir(), ".leetcode");
}

export async function getActivefilePath(uri?: vscode.Uri): Promise<string | undefined> {
let textEditor: vscode.TextEditor | undefined;
if (uri) {
textEditor = await vscode.window.showTextDocument(uri, { preview: false });
} else {
textEditor = vscode.window.activeTextEditor;
}

if (!textEditor) {
return undefined;
}
if (textEditor.document.isDirty && !await textEditor.document.save()) {
vscode.window.showWarningMessage("Please save the solution file first.");
return undefined;
}
return textEditor.document.uri.fsPath;
}

[8]ページ先頭

©2009-2025 Movatter.jp