From 3c70cf8bf3d9d684dd4b259d2fd89681a6037327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Mon, 12 Oct 2020 21:46:40 -0400 Subject: [PATCH 01/11] Add command for running test in terminal --- elixir-ls | 2 +- package.json | 4 +++ src/codelens/testCodeLensProvider.ts | 45 ++++++++++++++++++++++++++++ src/commands/runFromCodeLens.ts | 9 ++++++ src/constants/commands.ts | 5 ++++ src/extension.ts | 41 +++++++++++++++++-------- src/protocols.ts | 10 +++++++ src/utils/commandsUtils.ts | 18 +++++++++++ 8 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 src/codelens/testCodeLensProvider.ts create mode 100644 src/commands/runFromCodeLens.ts create mode 100644 src/constants/commands.ts create mode 100644 src/protocols.ts create mode 100644 src/utils/commandsUtils.ts diff --git a/elixir-ls b/elixir-ls index bd95bb7..293cce2 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit bd95bb7777c696437f9e81644b4bdb69d92d7c9f +Subproject commit 293cce2762a5a5761bd765a7e2cdca89fc97a542 diff --git a/package.json b/package.json index 7a2bb14..8ad3442 100644 --- a/package.json +++ b/package.json @@ -389,6 +389,10 @@ { "command": "extension.copyDebugInfo", "title": "ElixirLS: Copy Debug Info" + }, + { + "command": "elixir.test.run", + "title": "ElixirLS: Run test" } ], "menus": { diff --git a/src/codelens/testCodeLensProvider.ts b/src/codelens/testCodeLensProvider.ts new file mode 100644 index 0000000..678a192 --- /dev/null +++ b/src/codelens/testCodeLensProvider.ts @@ -0,0 +1,45 @@ +import { CodeLensProvider, TextDocument, Event, CodeLens, DocumentSelector, languages } from 'vscode'; +import { Disposable } from 'vscode-languageclient'; +import { ITestItem } from '../protocols'; +import { searchTestCodeLens } from '../utils/commandsUtils'; +import Commands from '../constants/commands'; + +export default class TestCodeLensProvider implements CodeLensProvider { + onDidChangeCodeLenses?: Event | undefined; + + private registeredProvider: Disposable | undefined; + + register(): void { + if (this.registeredProvider) { + this.registeredProvider.dispose(); + } + + const documentSelector: DocumentSelector = { + language: 'elixir', + scheme: 'file', + }; + + this.registeredProvider = languages.registerCodeLensProvider(documentSelector, this); + } + + public async provideCodeLenses(document: TextDocument): Promise { + console.log("test code lens provider") + const items: ITestItem[] = await searchTestCodeLens(document.uri.toString()) + + // const lenses = + // console.log(lenses) + return this.getCodeLenses(items); + } + + private getCodeLenses(items: ITestItem[]): CodeLens[] { + return items.map(item => new CodeLens( + item.location.range, + { + title: 'Run test', + command: Commands.RUN_TEST_FROM_CODELENS, + tooltip: 'Run test in a terminal', + arguments: [item] + }, + )) + } +} \ No newline at end of file diff --git a/src/commands/runFromCodeLens.ts b/src/commands/runFromCodeLens.ts new file mode 100644 index 0000000..8341881 --- /dev/null +++ b/src/commands/runFromCodeLens.ts @@ -0,0 +1,9 @@ +import { window } from "vscode"; + +export default function runFromCodeLens(test_filter: string): void { + const elixirLsTerminal = + window.terminals.find(terminal => terminal.name == "ElixirLS") || window.createTerminal("ElixirLS"); + + elixirLsTerminal.show() + elixirLsTerminal.sendText(`mix test ${test_filter}`); +} \ No newline at end of file diff --git a/src/constants/commands.ts b/src/constants/commands.ts new file mode 100644 index 0000000..310cdbd --- /dev/null +++ b/src/constants/commands.ts @@ -0,0 +1,5 @@ +export default { + EXECUTE_WORKSPACE_COMMAND: 'elixir.execute.workspaceCommand', + SEARCH_TEST_CODE_LENS: 'vscode.elixir.test.search.codelens', + RUN_TEST_FROM_CODELENS: 'elixir.test.run' +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index e59329a..0efa295 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,8 +14,13 @@ import { LanguageClientOptions, RevealOutputChannelOn, ServerOptions, + ExecuteCommandParams, + ExecuteCommandRequest, } from "vscode-languageclient"; import * as os from "os"; +import TestCodeLensProvider from "./codelens/testCodeLensProvider"; +import Commands from "./constants/commands"; +import runFromCodeLens from "./commands/runFromCodeLens"; export let defaultClient: LanguageClient; const clients: Map = new Map(); @@ -65,9 +70,9 @@ function detectConflictingExtension(extensionId: string): void { if (extension) { vscode.window.showErrorMessage( "Warning: " + - extensionId + - " is not compatible with ElixirLS, please uninstall " + - extensionId + extensionId + + " is not compatible with ElixirLS, please uninstall " + + extensionId ); } } @@ -93,16 +98,16 @@ function sortedWorkspaceFolders(): string[] { if (_sortedWorkspaceFolders === void 0) { _sortedWorkspaceFolders = workspace.workspaceFolders ? workspace.workspaceFolders - .map((folder) => { - let result = folder.uri.toString(); - if (result.charAt(result.length - 1) !== "/") { - result = result + "/"; - } - return result; - }) - .sort((a, b) => { - return a.length - b.length; - }) + .map((folder) => { + let result = folder.uri.toString(); + if (result.charAt(result.length - 1) !== "/") { + result = result + "/"; + } + return result; + }) + .sort((a, b) => { + return a.length - b.length; + }) : []; } return _sortedWorkspaceFolders; @@ -160,6 +165,14 @@ export function activate(context: ExtensionContext): void { detectConflictingExtension("sammkj.vscode-elixir-formatter"); vscode.commands.registerCommand("extension.copyDebugInfo", copyDebugInfo); + vscode.commands.registerCommand(Commands.RUN_TEST_FROM_CODELENS, runFromCodeLens); + vscode.commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => { + const params: ExecuteCommandParams = { + command, + arguments: rest + }; + return defaultClient.sendRequest(ExecuteCommandRequest.type, params); + }) configureDebugger(context); const command = @@ -277,6 +290,8 @@ export function activate(context: ExtensionContext): void { } } }); + + new TestCodeLensProvider().register(); } export function deactivate(): Thenable { diff --git a/src/protocols.ts b/src/protocols.ts new file mode 100644 index 0000000..09a7cb1 --- /dev/null +++ b/src/protocols.ts @@ -0,0 +1,10 @@ +import { Range } from 'vscode'; + +export interface ILocation { + uri: string; + range: Range; +}; + +export interface ITestItem { + location: ILocation; +}; diff --git a/src/utils/commandsUtils.ts b/src/utils/commandsUtils.ts new file mode 100644 index 0000000..46f9a9e --- /dev/null +++ b/src/utils/commandsUtils.ts @@ -0,0 +1,18 @@ +import { commands } from 'vscode'; +import Commands from '../constants/commands'; +import { ITestItem } from '../protocols'; + +export async function searchTestCodeLens(uri: string): Promise { + return await executeElixirLanguageServerCommand( + Commands.SEARCH_TEST_CODE_LENS, uri) || []; +} + +async function executeElixirLanguageServerCommand(...rest: any[]): Promise { + try { + // throw new Error("test") + return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, ...rest); + } catch (error) { + console.error(error.toString()); + throw error; + } +} \ No newline at end of file From 528499ec0fc20198845eb25f933b0c7c4cc5c7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Thu, 19 Nov 2020 20:07:40 -0500 Subject: [PATCH 02/11] Remove dead code, update mix command, update elixir-ls --- elixir-ls | 2 +- src/codelens/testCodeLensProvider.ts | 45 ---------------------------- src/commands/runFromCodeLens.ts | 34 +++++++++++++++++++-- src/extension.ts | 12 -------- 4 files changed, 33 insertions(+), 60 deletions(-) delete mode 100644 src/codelens/testCodeLensProvider.ts diff --git a/elixir-ls b/elixir-ls index 293cce2..f61fdd5 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit 293cce2762a5a5761bd765a7e2cdca89fc97a542 +Subproject commit f61fdd584c4faf494a1e6c03f9ef4dba548b00fd diff --git a/src/codelens/testCodeLensProvider.ts b/src/codelens/testCodeLensProvider.ts deleted file mode 100644 index 678a192..0000000 --- a/src/codelens/testCodeLensProvider.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { CodeLensProvider, TextDocument, Event, CodeLens, DocumentSelector, languages } from 'vscode'; -import { Disposable } from 'vscode-languageclient'; -import { ITestItem } from '../protocols'; -import { searchTestCodeLens } from '../utils/commandsUtils'; -import Commands from '../constants/commands'; - -export default class TestCodeLensProvider implements CodeLensProvider { - onDidChangeCodeLenses?: Event | undefined; - - private registeredProvider: Disposable | undefined; - - register(): void { - if (this.registeredProvider) { - this.registeredProvider.dispose(); - } - - const documentSelector: DocumentSelector = { - language: 'elixir', - scheme: 'file', - }; - - this.registeredProvider = languages.registerCodeLensProvider(documentSelector, this); - } - - public async provideCodeLenses(document: TextDocument): Promise { - console.log("test code lens provider") - const items: ITestItem[] = await searchTestCodeLens(document.uri.toString()) - - // const lenses = - // console.log(lenses) - return this.getCodeLenses(items); - } - - private getCodeLenses(items: ITestItem[]): CodeLens[] { - return items.map(item => new CodeLens( - item.location.range, - { - title: 'Run test', - command: Commands.RUN_TEST_FROM_CODELENS, - tooltip: 'Run test in a terminal', - arguments: [item] - }, - )) - } -} \ No newline at end of file diff --git a/src/commands/runFromCodeLens.ts b/src/commands/runFromCodeLens.ts index 8341881..0ee520e 100644 --- a/src/commands/runFromCodeLens.ts +++ b/src/commands/runFromCodeLens.ts @@ -1,9 +1,39 @@ import { window } from "vscode"; -export default function runFromCodeLens(test_filter: string): void { +type RunArgs = { + filePath: string, + describe: string | null, + testName?: string, + module?: string +} + +export default function runFromCodeLens(args: RunArgs): void { const elixirLsTerminal = window.terminals.find(terminal => terminal.name == "ElixirLS") || window.createTerminal("ElixirLS"); elixirLsTerminal.show() - elixirLsTerminal.sendText(`mix test ${test_filter}`); + elixirLsTerminal.sendText('clear') + elixirLsTerminal.sendText(buildTestCommand(args)); +} + +function buildTestCommand(args: RunArgs): string { + const testFilter = buildTestInclude(args.describe, args.testName, args.module) + + return `mix test --exclude test --include "${testFilter}" ${args.filePath} --trace` +} + +function buildTestInclude(describe: string | null, testName?: string, module?: string) { + if (module) { + return `module:${module}` + } + + if (!testName) { + return `describe:${describe}` + } + + if (describe) { + return `test:test ${describe} ${testName}` + } + + return `test:test ${testName}` } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 0efa295..b24804d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,11 +14,8 @@ import { LanguageClientOptions, RevealOutputChannelOn, ServerOptions, - ExecuteCommandParams, - ExecuteCommandRequest, } from "vscode-languageclient"; import * as os from "os"; -import TestCodeLensProvider from "./codelens/testCodeLensProvider"; import Commands from "./constants/commands"; import runFromCodeLens from "./commands/runFromCodeLens"; @@ -166,13 +163,6 @@ export function activate(context: ExtensionContext): void { vscode.commands.registerCommand("extension.copyDebugInfo", copyDebugInfo); vscode.commands.registerCommand(Commands.RUN_TEST_FROM_CODELENS, runFromCodeLens); - vscode.commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => { - const params: ExecuteCommandParams = { - command, - arguments: rest - }; - return defaultClient.sendRequest(ExecuteCommandRequest.type, params); - }) configureDebugger(context); const command = @@ -290,8 +280,6 @@ export function activate(context: ExtensionContext): void { } } }); - - new TestCodeLensProvider().register(); } export function deactivate(): Thenable { From 56eb801fdd3b12a3b6e85c4e22ca9ee7c0ca18bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Thu, 19 Nov 2020 20:24:21 -0500 Subject: [PATCH 03/11] Remove dead code --- src/constants/commands.ts | 2 -- src/protocols.ts | 10 ---------- src/utils/commandsUtils.ts | 18 ------------------ 3 files changed, 30 deletions(-) delete mode 100644 src/protocols.ts delete mode 100644 src/utils/commandsUtils.ts diff --git a/src/constants/commands.ts b/src/constants/commands.ts index 310cdbd..30a102a 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -1,5 +1,3 @@ export default { - EXECUTE_WORKSPACE_COMMAND: 'elixir.execute.workspaceCommand', - SEARCH_TEST_CODE_LENS: 'vscode.elixir.test.search.codelens', RUN_TEST_FROM_CODELENS: 'elixir.test.run' } \ No newline at end of file diff --git a/src/protocols.ts b/src/protocols.ts deleted file mode 100644 index 09a7cb1..0000000 --- a/src/protocols.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Range } from 'vscode'; - -export interface ILocation { - uri: string; - range: Range; -}; - -export interface ITestItem { - location: ILocation; -}; diff --git a/src/utils/commandsUtils.ts b/src/utils/commandsUtils.ts deleted file mode 100644 index 46f9a9e..0000000 --- a/src/utils/commandsUtils.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { commands } from 'vscode'; -import Commands from '../constants/commands'; -import { ITestItem } from '../protocols'; - -export async function searchTestCodeLens(uri: string): Promise { - return await executeElixirLanguageServerCommand( - Commands.SEARCH_TEST_CODE_LENS, uri) || []; -} - -async function executeElixirLanguageServerCommand(...rest: any[]): Promise { - try { - // throw new Error("test") - return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, ...rest); - } catch (error) { - console.error(error.toString()); - throw error; - } -} \ No newline at end of file From 7c3e2e106376c8ad9222c586a0471d079bdb1b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Thu, 19 Nov 2020 20:26:21 -0500 Subject: [PATCH 04/11] Remove command from package.json --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index affacc3..104e8f5 100644 --- a/package.json +++ b/package.json @@ -389,10 +389,6 @@ { "command": "extension.copyDebugInfo", "title": "ElixirLS: Copy Debug Info" - }, - { - "command": "elixir.test.run", - "title": "ElixirLS: Run test" } ], "menus": { From 403204f95bcf90656e4b8b9b85c95f0a08bca4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Thu, 19 Nov 2020 20:33:40 -0500 Subject: [PATCH 05/11] Formatting --- elixir-ls | 2 +- .../{runFromCodeLens.ts => runTestFromCodeLens.ts} | 2 +- src/constants/commands.ts | 4 ++-- src/extension.ts | 14 +++++++++----- 4 files changed, 13 insertions(+), 9 deletions(-) rename src/commands/{runFromCodeLens.ts => runTestFromCodeLens.ts} (99%) diff --git a/elixir-ls b/elixir-ls index f61fdd5..d938be9 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit f61fdd584c4faf494a1e6c03f9ef4dba548b00fd +Subproject commit d938be94f0547cee867bdf5e9b77c938c35c89c9 diff --git a/src/commands/runFromCodeLens.ts b/src/commands/runTestFromCodeLens.ts similarity index 99% rename from src/commands/runFromCodeLens.ts rename to src/commands/runTestFromCodeLens.ts index 0ee520e..d6db33b 100644 --- a/src/commands/runFromCodeLens.ts +++ b/src/commands/runTestFromCodeLens.ts @@ -36,4 +36,4 @@ function buildTestInclude(describe: string | null, testName?: string, module?: s } return `test:test ${testName}` -} \ No newline at end of file +} diff --git a/src/constants/commands.ts b/src/constants/commands.ts index 30a102a..d939008 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -1,3 +1,3 @@ export default { - RUN_TEST_FROM_CODELENS: 'elixir.test.run' -} \ No newline at end of file + RUN_TEST_FROM_CODELENS: 'elixir.lens.test.run' +} diff --git a/src/extension.ts b/src/extension.ts index aca864f..35b07ea 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -18,7 +18,7 @@ import { } from "vscode-languageclient"; import * as os from "os"; import Commands from "./constants/commands"; -import runFromCodeLens from "./commands/runFromCodeLens"; +import runFromCodeLens from "./commands/runTestFromCodeLens"; export let defaultClient: LanguageClient; const clients: Map = new Map(); @@ -68,9 +68,9 @@ function detectConflictingExtension(extensionId: string): void { if (extension) { vscode.window.showErrorMessage( "Warning: " + - extensionId + - " is not compatible with ElixirLS, please uninstall " + - extensionId + extensionId + + " is not compatible with ElixirLS, please uninstall " + + extensionId ); } } @@ -213,13 +213,17 @@ function configureTerminalLinkProvider(context: ExtensionContext) { context.subscriptions.push(disposable); } +function configureRunTestFromCodeLens() { + vscode.commands.registerCommand(Commands.RUN_TEST_FROM_CODELENS, runFromCodeLens); +} + export function activate(context: ExtensionContext): void { testElixir(); detectConflictingExtension("mjmcloug.vscode-elixir"); // https://github.com/elixir-lsp/vscode-elixir-ls/issues/34 detectConflictingExtension("sammkj.vscode-elixir-formatter"); - vscode.commands.registerCommand(Commands.RUN_TEST_FROM_CODELENS, runFromCodeLens); + configureRunTestFromCodeLens() configureCopyDebugInfo(context); configureDebugger(context); configureTerminalLinkProvider(context); From 68b7b64592fb067b6a523dec73c26403b7dcd36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Thu, 19 Nov 2020 20:38:07 -0500 Subject: [PATCH 06/11] Update elixir-ls with master --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index d938be9..395be90 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit d938be94f0547cee867bdf5e9b77c938c35c89c9 +Subproject commit 395be90e4965f6755e38705cf39d879f03617901 From 651b14747d94f63481008cd35fe9922ad64f1275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Sat, 21 Nov 2020 21:04:29 -0500 Subject: [PATCH 07/11] Update elixir-ls --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index 395be90..4b7990c 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit 395be90e4965f6755e38705cf39d879f03617901 +Subproject commit 4b7990cb56e87b676b3a96692f4bcd2b5e00b95b From 0f03544c576001b771dbb5c421751579d21247c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Tue, 1 Dec 2020 20:38:27 -0500 Subject: [PATCH 08/11] Add setting for enabling test code lenses --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 104e8f5..ac5380b 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,11 @@ "type": "boolean", "description": "Show signature help after confirming autocomplete", "default": true + }, + "elixirLS.enableTestLenses": { + "type": "boolean", + "description": "Show code lenses to run tests in terminal", + "default": false } } }, From 5b59e9aaddfd324ca03ad8574714d9fa6ba1baba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Tue, 1 Dec 2020 20:38:41 -0500 Subject: [PATCH 09/11] Update elixir-ls --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index 4b7990c..2fe0e8e 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit 4b7990cb56e87b676b3a96692f4bcd2b5e00b95b +Subproject commit 2fe0e8e9125a655fb67c23610e6d45de1405425e From 5529fd61d31f054dc00b9613e4a977e0c29996f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Sat, 5 Dec 2020 08:12:12 -0500 Subject: [PATCH 10/11] Update elixir-ls to latest master --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index 2fe0e8e..5b2d236 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit 2fe0e8e9125a655fb67c23610e6d45de1405425e +Subproject commit 5b2d23622614b8470293cb7cadba530170f8f70f From d4220063c478ac377cedf8b093899fc41f05b69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Sat, 5 Dec 2020 08:16:57 -0500 Subject: [PATCH 11/11] Remove trace option from mix task --- src/commands/runTestFromCodeLens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/runTestFromCodeLens.ts b/src/commands/runTestFromCodeLens.ts index d6db33b..90e9d1d 100644 --- a/src/commands/runTestFromCodeLens.ts +++ b/src/commands/runTestFromCodeLens.ts @@ -19,7 +19,7 @@ export default function runFromCodeLens(args: RunArgs): void { function buildTestCommand(args: RunArgs): string { const testFilter = buildTestInclude(args.describe, args.testName, args.module) - return `mix test --exclude test --include "${testFilter}" ${args.filePath} --trace` + return `mix test --exclude test --include "${testFilter}" ${args.filePath}` } function buildTestInclude(describe: string | null, testName?: string, module?: string) {