Skip to content

Commit

Permalink
Add commands to run or test the current file or target.
Browse files Browse the repository at this point in the history
Thanks to @ckipp01 it's now possible to run test or main classes inside the current file.

The Metals PR that added this functionality is scalameta/metals#2532
  • Loading branch information
tgodzik committed Apr 6, 2021
1 parent 65ef43b commit 43aac4c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@
"command": "metals.copy-worksheet-output",
"category": "Metals",
"title": "Copy worksheet output"
},
{
"command": "metals.run-current-file",
"category": "Metals",
"title": "Run main class in the current file"
},
{
"command": "metals.test-current-file",
"category": "Metals",
"title": "Run test class in the current file"
},
{
"command": "metals.test-current-target",
"category": "Metals",
"title": "Run all test in the current project"
}
],
"menus": {
Expand Down Expand Up @@ -591,11 +606,11 @@
"vsce": "1.86.0"
},
"dependencies": {
"metals-languageclient": "0.4.1",
"metals-languageclient": "0.4.2",
"promisify-child-process": "4.1.1",
"vscode-languageclient": "6.1.3"
},
"extensionDependencies": [
"scala-lang.scala"
]
}
}
49 changes: 48 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import {
MetalsWindowStateDidChange,
MetalsInputBox,
MetalsQuickPick,
DebugDiscoveryParms,
RunType,
} from "metals-languageclient";
import * as metalsLanguageClient from "metals-languageclient";
import { startTreeView } from "./treeview";
Expand Down Expand Up @@ -189,7 +191,7 @@ function fetchAndLaunchMetals(context: ExtensionContext, javaHome: string) {
if (dottyIde.enabled) {
outputChannel.appendLine(
`Metals will not start since Dotty is enabled for this workspace. ` +
`To enable Metals, remove the file ${dottyIde.path} and run 'Reload window'`
`To enable Metals, remove the file ${dottyIde.path} and run 'Reload window'`
);
return;
}
Expand Down Expand Up @@ -562,6 +564,51 @@ function launchMetals(
}
});

registerTextEditorCommand(
`metals.run-current-file`,
(editor, _edit, _args) => {
const args: DebugDiscoveryParms = {
path: editor.document.uri.toString(true),
runType: RunType.Run,
};
scalaDebugger.start(true, args).then((wasStarted) => {
if (!wasStarted) {
window.showErrorMessage("Debug session not started");
}
});
}
);

registerTextEditorCommand(
`metals.test-current-file`,
(editor, _edit, _args) => {
const args: DebugDiscoveryParms = {
path: editor.document.uri.toString(true),
runType: RunType.TestFile,
};
scalaDebugger.start(true, args).then((wasStarted) => {
if (!wasStarted) {
window.showErrorMessage("Debug session not started");
}
});
}
);

registerTextEditorCommand(
`metals.test-current-target`,
(editor, _edit, _args) => {
const args: DebugDiscoveryParms = {
path: editor.document.uri.toString(true),
runType: RunType.TestTarget,
};
scalaDebugger.start(true, args).then((wasStarted) => {
if (!wasStarted) {
window.showErrorMessage("Debug session not started");
}
});
}
);

registerTextEditorCommand(
`metals.${ServerCommands.GotoSuperMethod}`,
(editor, _edit, _args) => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ mdurl@^1.0.1:
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=

metals-languageclient@0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/metals-languageclient/-/metals-languageclient-0.4.1.tgz#3f379d1073873993ad450e2630ad67510edd8d79"
integrity sha512-X1I0spZy0PQasLYW5FmzbojB5n3F+r8YpPr1fGDyWJGzVBH2WXJv+CwpUcY0VNKIJLrvat8aJRmKTd9PfRreHw==
metals-languageclient@0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/metals-languageclient/-/metals-languageclient-0.4.2.tgz#ec2aea8fef7e5386c2f6bdd05fc5534897d9aaaa"
integrity sha512-AY9lGmUznFNsLr7Vm3hLCT7Ar0bN6Wninp3qA0E0/JBU4uRTRI4fIgM1I3+nbjLf23mwh+vrHut0ML63QB2acA==
dependencies:
fp-ts "^2.4.1"
locate-java-home "^1.1.2"
Expand Down

0 comments on commit 43aac4c

Please sign in to comment.