From b7ededcbc4cceccd1f7b41f9caf21d1ac2cd286c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E5=8D=A1=E7=90=B3?= Date: Fri, 27 Sep 2019 20:04:17 +0800 Subject: [PATCH 01/58] fix: CodeLens position (#426) --- package-lock.json | 18 +++++++++--------- package.json | 2 +- src/codelens/CustomCodeLensProvider.ts | 11 ++++++++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb81a83b..88602cc1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -316,9 +316,9 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "colors": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", - "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==" + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" }, "combined-stream": { "version": "1.0.7", @@ -485,9 +485,9 @@ } }, "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", "requires": { "once": "^1.4.0" } @@ -1786,9 +1786,9 @@ } }, "vsc-leetcode-cli": { - "version": "2.6.10", - "resolved": "https://registry.npmjs.org/vsc-leetcode-cli/-/vsc-leetcode-cli-2.6.10.tgz", - "integrity": "sha512-eGf0GorHCkheBnqJN5B/RslZcfdcI6wL/v5Z23e4M3IZVOrrasiL9t6alAVXsOmeVubdMDJAaWT8R08lY46YCA==", + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/vsc-leetcode-cli/-/vsc-leetcode-cli-2.6.11.tgz", + "integrity": "sha512-W0qFCLMh1vfFk/nbSj0Zc80tm1/kPAbF5gRJdm01XV19+2BE8RRHcwhWVPsOUksE6cK7Rw1KuvzGxS9wDLG2Qw==", "requires": { "ansi-styles": "3.2.1", "cheerio": "0.20.0", diff --git a/package.json b/package.json index bedaed77..45f6e63e 100644 --- a/package.json +++ b/package.json @@ -683,6 +683,6 @@ "markdown-it": "^8.4.2", "require-from-string": "^2.0.2", "unescape-js": "^1.1.1", - "vsc-leetcode-cli": "2.6.10" + "vsc-leetcode-cli": "2.6.11" } } diff --git a/src/codelens/CustomCodeLensProvider.ts b/src/codelens/CustomCodeLensProvider.ts index 52deaf38..4764e999 100644 --- a/src/codelens/CustomCodeLensProvider.ts +++ b/src/codelens/CustomCodeLensProvider.ts @@ -28,7 +28,16 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider { return undefined; } - const range: vscode.Range = new vscode.Range(document.lineCount - 1, 0, document.lineCount - 1, 0); + let codeLensLine: number = document.lineCount - 1; + for (let i: number = document.lineCount - 1; i >= 0; i--) { + const lineContent: string = document.lineAt(i).text; + if (lineContent.indexOf("@lc code=end") >= 0) { + codeLensLine = i; + break; + } + } + + const range: vscode.Range = new vscode.Range(codeLensLine, 0, codeLensLine, 0); const codeLens: vscode.CodeLens[] = []; if (shortcuts.indexOf("submit") >= 0) { From 31d6f94c2c6a20d479fd5c6368ba9af390417be7 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Fri, 27 Sep 2019 20:11:04 +0800 Subject: [PATCH 02/58] fix: Use default file name when the setting is empty (#433) --- src/commands/show.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/show.ts b/src/commands/show.ts index 1906bd8e..3de4f89a 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -150,7 +150,7 @@ async function showProblemInternal(node: IProblem): Promise { const fileName: string = leetCodeConfig .get( `filePath.${language}.filename`, - leetCodeConfig.get(`filePath.default.filename`, genFileName(node, language)), + leetCodeConfig.get(`filePath.default.filename`) || genFileName(node, language), ) .trim(); From 8d50a2fab6d1c91e9f622f3ca282362ce5e63402 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Sat, 28 Sep 2019 16:13:22 +0800 Subject: [PATCH 03/58] chore: prepare for 0.15.5 (#438) --- CHANGELOG.md | 7 +++++++ package-lock.json | 8 ++++---- package.json | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af503540..7f2f9985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to the "leetcode" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [0.15.5] +### Added +- Add a link to the discussion page [#420](https://github.com/jdneo/vscode-leetcode/issues/420) + +### Fixed +[Bugs fixed](https://github.com/jdneo/vscode-leetcode/issues?q=is%3Aissue+milestone%3A0.15.5+is%3Aclosed+label%3Abug) + ## [0.15.4] ### Added - Add a new setting `leetcode.filePath`. Now users can use this setting to dynamicly specify the relative folder name and file name. [#PR380](https://github.com/jdneo/vscode-leetcode/pull/380) diff --git a/package-lock.json b/package-lock.json index 88602cc1..47f8dab5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-leetcode", - "version": "0.15.4", + "version": "0.15.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1786,9 +1786,9 @@ } }, "vsc-leetcode-cli": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/vsc-leetcode-cli/-/vsc-leetcode-cli-2.6.11.tgz", - "integrity": "sha512-W0qFCLMh1vfFk/nbSj0Zc80tm1/kPAbF5gRJdm01XV19+2BE8RRHcwhWVPsOUksE6cK7Rw1KuvzGxS9wDLG2Qw==", + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/vsc-leetcode-cli/-/vsc-leetcode-cli-2.6.13.tgz", + "integrity": "sha512-otwxXXBDPGJX2IkIbTTsXdwA9yYMxdFWqmPwtSwXfNrN1oAturxfXS61T/1vUkcwAPMMpoFtXdGr99pnSVyYtw==", "requires": { "ansi-styles": "3.2.1", "cheerio": "0.20.0", diff --git a/package.json b/package.json index 45f6e63e..bbedd4ab 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode", "displayName": "LeetCode", "description": "Solve LeetCode problems in VS Code", - "version": "0.15.4", + "version": "0.15.5", "author": "Sheng Chen", "publisher": "shengchen", "license": "MIT", @@ -683,6 +683,6 @@ "markdown-it": "^8.4.2", "require-from-string": "^2.0.2", "unescape-js": "^1.1.1", - "vsc-leetcode-cli": "2.6.11" + "vsc-leetcode-cli": "2.6.13" } } From 01f5a2854087d08271961ea4aa7f12c108a5818c Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 2 Oct 2019 12:26:56 +0800 Subject: [PATCH 04/58] 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 05/58] 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 : ""}