From 01f5a2854087d08271961ea4aa7f12c108a5818c Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 2 Oct 2019 12:26:56 +0800 Subject: [PATCH 01/55] refactor: Stop using the 'vscode.workspace.rootPath' API (#443) --- src/commands/test.ts | 2 +- src/utils/uiUtils.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/commands/test.ts b/src/commands/test.ts index 262f7339..d070c9aa 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -65,7 +65,7 @@ export async function testSolution(uri?: vscode.Uri): Promise { } break; case ":file": - const testFile: vscode.Uri[] | undefined = await showFileSelectDialog(); + const testFile: vscode.Uri[] | undefined = await showFileSelectDialog(filePath); if (testFile && testFile.length) { const input: string = (await fse.readFile(testFile[0].fsPath, "utf-8")).trim(); if (input) { diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts index 037b2371..53275fa0 100644 --- a/src/utils/uiUtils.ts +++ b/src/utils/uiUtils.ts @@ -80,8 +80,8 @@ export async function openKeybindingsEditor(query?: string): Promise { await vscode.commands.executeCommand("workbench.action.openGlobalKeybindings", query); } -export async function showFileSelectDialog(): Promise { - const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined; +export async function showFileSelectDialog(fsPath?: string): Promise { + const defaultUri: vscode.Uri | undefined = getBelongingWorkspaceFolderUri(fsPath); const options: vscode.OpenDialogOptions = { defaultUri, canSelectFiles: true, @@ -92,8 +92,19 @@ export async function showFileSelectDialog(): Promise return await vscode.window.showOpenDialog(options); } -export async function showDirectorySelectDialog(): Promise { - const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined; +function getBelongingWorkspaceFolderUri(fsPath: string | undefined): vscode.Uri | undefined { + let defaultUri: vscode.Uri | undefined; + if (fsPath) { + const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(fsPath)); + if (workspaceFolder) { + defaultUri = workspaceFolder.uri; + } + } + return defaultUri; +} + +export async function showDirectorySelectDialog(fsPath?: string): Promise { + const defaultUri: vscode.Uri | undefined = getBelongingWorkspaceFolderUri(fsPath); const options: vscode.OpenDialogOptions = { defaultUri, canSelectFiles: false, From ffdccec272bdef9cdbf69ba3ea70cf39b3c0ab29 Mon Sep 17 00:00:00 2001 From: Bill Guo Date: Wed, 2 Oct 2019 01:34:48 -0400 Subject: [PATCH 02/55] feat: added solution link (#441) --- ACKNOWLEDGEMENTS.md | 4 +++- src/webview/leetCodePreviewProvider.ts | 27 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index 49a975e8..4bc00ba3 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -2,6 +2,7 @@ A big thanks to the following individuals for contributing: +- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design - [@TsFreddie](https://github.com/TsFreddie) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=TsFreddie) - [@ntt2k](https://github.com/ntt2k) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=ntt2k) - [@purocean](https://github.com/purocean) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=purocean) @@ -17,4 +18,5 @@ A big thanks to the following individuals for contributing: - [@houtianze](https://github.com/houtianze) — [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=houtianze) - [@magic-akari](https://github.com/magic-akari) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=magic-akari) - [@SF-Zhou](https://github.com/SF-Zhou) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=SF-Zhou) -- [@JIEJIAN21](https://github.com/JIEJIAN21) - thanks for logo and icon design +- [@fuafa](https://github.com/fuafa) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=fuafa) +- [@iFun](https://github.com/iFun) - [contributions](https://github.com/jdneo/vscode-leetcode/commits?author=iFun) diff --git a/src/webview/leetCodePreviewProvider.ts b/src/webview/leetCodePreviewProvider.ts index d0378ef8..fba17728 100644 --- a/src/webview/leetCodePreviewProvider.ts +++ b/src/webview/leetCodePreviewProvider.ts @@ -2,7 +2,8 @@ // Licensed under the MIT license. import { commands, ViewColumn } from "vscode"; -import { IProblem } from "../shared"; +import { getLeetCodeEndpoint } from "../commands/plugin"; +import { Endpoint, IProblem } from "../shared"; import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview"; import { markdownEngine } from "./markdownEngine"; @@ -73,9 +74,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview { const { title, url, category, difficulty, likes, dislikes, body } = this.description; const head: string = markdownEngine.render(`# [${title}](${url})`); const info: string = markdownEngine.render([ - `| Category | Difficulty | Likes | Dislikes | [Discuss](${url.replace("/description/", "/discuss/?currentPage=1&orderBy=most_votes&query=")}) |`, - `| :------: | :--------: | :---: | :------: | :-----: |`, - `| ${category} | ${difficulty} | ${likes} | ${dislikes} | -- |`, + `| Category | Difficulty | Likes | Dislikes |`, + `| :------: | :--------: | :---: | :------: |`, + `| ${category} | ${difficulty} | ${likes} | ${dislikes} |`, ].join("\n")); const tags: string = [ `
`, @@ -97,6 +98,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview { ), `
`, ].join("\n"); + const links: string = markdownEngine.render(`[Discussion](${this.getDiscussionLink(url)}) | [Solution](${this.getSolutionLink(url)})`); return ` @@ -114,6 +116,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview { ${tags} ${companies} ${body} +
+ ${links} ${!this.sideMode ? button.element : ""}