Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code lens for running test in terminal #155

Merged
merged 12 commits into from
Dec 5, 2020
Merged
2 changes: 1 addition & 1 deletion elixir-ls
Submodule elixir-ls updated 58 files
+89 −0 .github/workflows/ci.yml
+0 −39 .travis.yml
+21 −3 CHANGELOG.md
+3 −6 DEVELOPMENT.md
+1 −1 README.md
+4 −0 apps/elixir_ls_debugger/test/test_helper.exs
+1 −1 apps/elixir_ls_utils/lib/mix.tasks.elixir_ls.release.ex
+3 −1 apps/elixir_ls_utils/priv/launch.sh
+4 −0 apps/elixir_ls_utils/test/test_helper.exs
+31 −2 apps/language_server/lib/language_server/build.ex
+20 −13 apps/language_server/lib/language_server/dialyzer.ex
+17 −9 apps/language_server/lib/language_server/dialyzer/manifest.ex
+2 −3 apps/language_server/lib/language_server/dialyzer/utils.ex
+1 −0 apps/language_server/lib/language_server/json_rpc.ex
+6 −2 apps/language_server/lib/language_server/mix_shell.ex
+9 −0 apps/language_server/lib/language_server/protocol.ex
+19 −0 apps/language_server/lib/language_server/protocol/location.ex
+17 −128 apps/language_server/lib/language_server/providers/code_lens.ex
+160 −0 apps/language_server/lib/language_server/providers/code_lens/test.ex
+52 −0 apps/language_server/lib/language_server/providers/code_lens/test/describe_block.ex
+6 −0 apps/language_server/lib/language_server/providers/code_lens/test/test_block.ex
+135 −0 apps/language_server/lib/language_server/providers/code_lens/type_spec.ex
+34 −28 apps/language_server/lib/language_server/providers/completion.ex
+8 −22 apps/language_server/lib/language_server/providers/definition.ex
+25 −10 apps/language_server/lib/language_server/providers/execute_command.ex
+1 −5 apps/language_server/lib/language_server/providers/formatting.ex
+14 −0 apps/language_server/lib/language_server/providers/implementation.ex
+2 −2 apps/language_server/lib/language_server/providers/on_type_formatting.ex
+0 −4 apps/language_server/lib/language_server/providers/references.ex
+3 −1 apps/language_server/lib/language_server/providers/signature_help.ex
+239 −78 apps/language_server/lib/language_server/server.ex
+48 −16 apps/language_server/lib/language_server/source_file.ex
+2 −1 apps/language_server/mix.exs
+99 −13 apps/language_server/test/dialyzer_test.exs
+4 −0 apps/language_server/test/fixtures/protocols/lib/example.ex
+7 −0 apps/language_server/test/fixtures/protocols/lib/implementations.ex
+14 −0 apps/language_server/test/fixtures/protocols/mix.exs
+9 −0 apps/language_server/test/fixtures/test_code_lens/mix.exs
+7 −0 apps/language_server/test/fixtures/test_code_lens/test/fixture_test.exs
+185 −0 apps/language_server/test/providers/code_lens/test_test.exs
+88 −2 apps/language_server/test/providers/completion_test.exs
+3 −2 apps/language_server/test/providers/definition_test.exs
+7 −6 apps/language_server/test/providers/formatting_test.exs
+35 −0 apps/language_server/test/providers/implementation_test.exs
+60 −0 apps/language_server/test/providers/on_type_formatting_test.exs
+5 −4 apps/language_server/test/providers/references_test.exs
+675 −79 apps/language_server/test/server_test.exs
+607 −0 apps/language_server/test/source_file_test.exs
+5 −0 apps/language_server/test/support/fixture_helpers.ex
+10 −0 apps/language_server/test/support/fixtures/example_behaviour.ex
+3 −0 apps/language_server/test/support/fixtures/example_exception.ex
+3 −0 apps/language_server/test/support/fixtures/example_struct.ex
+0 −0 apps/language_server/test/support/fixtures/macro_a.ex
+0 −0 apps/language_server/test/support/fixtures/references_a.ex
+0 −0 apps/language_server/test/support/fixtures/references_b.ex
+0 −0 apps/language_server/test/support/fixtures/uses_macro_a.ex
+5 −0 apps/language_server/test/test_helper.exs
+2 −1 mix.lock
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
},
Expand Down
39 changes: 39 additions & 0 deletions src/commands/runTestFromCodeLens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { window } from "vscode";

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('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}`
}

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}`
}
3 changes: 3 additions & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
RUN_TEST_FROM_CODELENS: 'elixir.lens.test.run'
}
31 changes: 19 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
ServerOptions,
} from "vscode-languageclient";
import * as os from "os";
import Commands from "./constants/commands";
import runFromCodeLens from "./commands/runTestFromCodeLens";

export let defaultClient: LanguageClient;
const clients: Map<string, LanguageClient> = new Map();
Expand Down Expand Up @@ -77,16 +79,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;
Expand Down Expand Up @@ -200,23 +202,28 @@ function configureTerminalLinkProvider(context: ExtensionContext) {
if (!selection) {
return;
}

openUri(selection.uri, line);
});
}
});
}
});

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");

configureRunTestFromCodeLens()
configureCopyDebugInfo(context);
configureDebugger(context);
configureTerminalLinkProvider(context);
Expand Down