Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9a4b564

Browse files
committed
fix: add code file support
1 parent 457425d commit 9a4b564

File tree

7 files changed

+58
-18
lines changed

7 files changed

+58
-18
lines changed

.vscode/launch.json

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,51 @@
22
{
33
"version": "0.1.0",
44
"configurations": [
5+
{
6+
"name": "Run Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": [
11+
"D:/tmp/leetcode-test",
12+
"--disable-extensions",
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "${defaultBuildTask}"
19+
},
520
{
621
"name": "Launch Extension",
722
"type": "extensionHost",
823
"request": "launch",
924
"runtimeExecutable": "${execPath}",
10-
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
25+
"args": [
26+
"--extensionDevelopmentPath=${workspaceRoot}"
27+
],
1128
"stopOnEntry": false,
1229
"sourceMaps": true,
13-
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
30+
"outFiles": [
31+
"${workspaceRoot}/out/src/**/*.js"
32+
],
1433
"preLaunchTask": "npm"
1534
},
1635
{
1736
"name": "Launch Tests",
1837
"type": "extensionHost",
1938
"request": "launch",
2039
"runtimeExecutable": "${execPath}",
21-
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
40+
"args": [
41+
"--extensionDevelopmentPath=${workspaceRoot}",
42+
"--extensionTestsPath=${workspaceRoot}/out/test"
43+
],
2244
"stopOnEntry": false,
2345
"sourceMaps": true,
24-
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
46+
"outFiles": [
47+
"${workspaceRoot}/out/test/**/*.js"
48+
],
2549
"preLaunchTask": "npm"
2650
}
2751
]
28-
}
52+
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode",
33
"displayName": "LeetCode",
44
"description": "Solve LeetCode problems in VS Code",
5-
"version": "0.19.0",
5+
"version": "0.19.1",
66
"author": "convexwf",
77
"publisher": "LeetCode",
88
"license": "MIT",

src/commands/show.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { leetCodeManager } from "../leetCodeManager";
1313
import { IProblem, IQuickItemEx, languages, ProblemState } from "../shared";
1414
import { genFileExt, genFileName, getNodeIdFromFile } from "../utils/problemUtils";
1515
import * as settingUtils from "../utils/settingUtils";
16-
import { IDescriptionConfiguration } from "../utils/settingUtils";
16+
import { IDescriptionConfiguration, getWorkspaceConfiguration } from "../utils/settingUtils";
1717
import { DialogOptions, DialogType, openSettingsEditor, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/uiUtils";
1818
import { getActiveFilePath, selectWorkspaceFolder } from "../utils/workspaceUtils";
1919
import * as wsl from "../utils/wslUtils";
@@ -65,7 +65,7 @@ export async function showDocumentation(node?: LeetCodeNode): Promise<void> {
6565
}
6666
console.log(`Show documentation: ${node.id}`);
6767
try {
68-
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
68+
const leetCodeConfig: vscode.WorkspaceConfiguration = getWorkspaceConfiguration();
6969
const workspaceFolder: string = await selectWorkspaceFolder();
7070
if (!workspaceFolder) {
7171
return;

src/leetCodeExecutor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class LeetCodeExecutor implements Disposable {
160160
const description = this.parseDescription(descString, problemNode);
161161
const { title, url, category, difficulty, likes, dislikes, body } = description;
162162

163-
const head: string = `# [${problemNode.id}. ${title}](${url})`;
163+
const head: string = `# [${problemNode.id}.${title}](${url})`;
164164
const info: string = [
165165
`| Category | Difficulty | Likes | Dislikes |`,
166166
`| :------: | :--------: | :---: | :------: |`,
@@ -180,7 +180,7 @@ class LeetCodeExecutor implements Disposable {
180180
'',
181181
info,
182182
'',
183-
body.replace(/\t/g, " "),
183+
body.replace(/\t/g, " ").replace(/(\n)+/g, "\n"),
184184
"## Solution\n",
185185
"**题目描述**\n",
186186
"**解题思路**\n",
@@ -261,8 +261,8 @@ class LeetCodeExecutor implements Disposable {
261261

262262
public async submitSolution(filePath: string): Promise<string> {
263263
try {
264-
return promiseWithTimeout(this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]), 10000);
265-
// return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
264+
// return promiseWithTimeout(this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]), 10000);
265+
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
266266
} catch (error) {
267267
if (error.result) {
268268
return error.result;
@@ -273,8 +273,8 @@ class LeetCodeExecutor implements Disposable {
273273

274274
public async testSolution(filePath: string, testString?: string): Promise<string> {
275275
if (testString) {
276-
return promiseWithTimeout(this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]), 10000);
277-
// return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]);
276+
// return promiseWithTimeout(this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]), 10000);
277+
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]);
278278
}
279279
return promiseWithTimeout(this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]), 10000);
280280
// return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);

src/utils/settingUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ import { workspace, WorkspaceConfiguration } from "vscode";
55
import { DescriptionConfiguration } from "../shared";
66

77
export function getWorkspaceConfiguration(): WorkspaceConfiguration {
8+
// if (!window.activeTextEditor) {
9+
// return workspace.getConfiguration("leetcode");
10+
// }
811
return workspace.getConfiguration("leetcode");
12+
// let uri = window.activeTextEditor.document.uri;
13+
// let workspaceFolder = workspace.getWorkspaceFolder(uri);
14+
// console.log("workspaceFolder", workspaceFolder ? workspaceFolder.uri.fsPath : "");
15+
// let config = workspace.getConfiguration('leetcode', workspaceFolder);
16+
// console.log("getWorkspaceConfiguration", config.get("workspaceFolder"));
17+
// return config;
918
}
1019

1120
export function shouldHideSolvedProblem(): boolean {

src/utils/workspaceUtils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export async function copyCodeBlock(): Promise<string | undefined> {
104104
vscode.window.showErrorMessage('当前没有打开的文本编辑器');
105105
return;
106106
}
107+
// 获取当前文件的后缀名
108+
const activeFilePath = editor.document.uri.fsPath;
109+
const activeileExt = activeFilePath.split('.').pop();
107110
// 获取当前光标所在行
108111
const currentLine = editor.selection.active.line;
109112

@@ -127,12 +130,14 @@ export async function copyCodeBlock(): Promise<string | undefined> {
127130
endLine++;
128131
}
129132

130-
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
131-
const filePath: string = leetCodeConfig.get<string>(`filePath.default.codefile`, "").trim();
133+
const workspaceFolder = getWorkspaceFolder();
134+
let filePath: string = path.join(workspaceFolder, "temp", `temp.${activeileExt}`);
135+
console.log("filePath", filePath);
132136
if (filePath === "") {
133-
vscode.window.showErrorMessage("Please specify the default code file path in the settings.");
137+
vscode.window.showErrorMessage('请先设置 LeetCode 插件的工作目录');
134138
return;
135139
}
140+
filePath = wsl.useWsl() ? await wsl.toWinPath(filePath) : filePath;
136141

137142
// 如果找到了符合条件的区域,将其复制到文件中
138143
if (startLine < endLine) {
@@ -141,6 +146,8 @@ export async function copyCodeBlock(): Promise<string | undefined> {
141146
new vscode.Position(startLine, 0),
142147
new vscode.Position(endLine + 1, 0)
143148
));
149+
// create dir if not exists
150+
fse.ensureDirSync(path.dirname(filePath));
144151
fse.writeFileSync(filePath, fileContent);
145152

146153
// vscode.window.showInformationMessage(`成功将代码复制到文件 ${filePath}`);

0 commit comments

Comments
 (0)