Skip to content

Commit

Permalink
Merge pull request #93 from Achal1607/javavscode-56
Browse files Browse the repository at this point in the history
Added "Go To Test" option
  • Loading branch information
Achal1607 authored Jan 18, 2024
2 parents 22f03a2 + c0cac0b commit 010008c
Show file tree
Hide file tree
Showing 7 changed files with 2,054 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ In the VS Code command palette :
* Debugger __Java+...__ - start main class or test on selected JDK. More in [Debugger section](#debugger-and-launch-configurations)
* __Test Explorer__ for Java tests results visualization and execution including editor code Lenses.
* Maven and Gradle support including multi-project projects, subprojects opening and Gradle priming builds.
* __Java: Go To Test/Tested Class__ - Navigates to the corresponding test or source class file

## Project Explorer
Project Explorer provides an overview of logical project structure, groups sources together and greatly simplifies Java package structure exploration. Project Explorer is an addition to the classical workspace explorer. Use it to build, test, execute and operate your Maven and Gradle Java projects.
Expand Down
3 changes: 1 addition & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
<property name="nbplatform.default.harness.dir" location="${nbplatform.default.netbeans.dest.dir}/harness" />
<property name="nbantext.jar" location="netbeans/nbbuild/build/nbantext.jar" />
<property name="nb_all" location="netbeans" />
<property name="patches" value="patches/6330.diff patches/6481.diff patches/6615.diff patches/6631.diff patches/6637.diff patches/6642.diff patches/6649.diff patches/6690.diff patches/6771.diff patches/6329.diff patches/6742.diff patches/6780.diff patches/mvn-sh.diff patches/rename-debugger.diff" />

<property name="patches" value="patches/6133.diff patches/6330.diff patches/6481.diff patches/6615.diff patches/6631.diff patches/6637.diff patches/6642.diff patches/6649.diff patches/6690.diff patches/6771.diff patches/6329.diff patches/6742.diff patches/6780.diff patches/6834.diff patches/mvn-sh.diff patches/rename-debugger.diff" />
<condition property="cmd.suffix" value=".cmd" else="">
<os family="windows"/>
</condition>
Expand Down
1,018 changes: 1,018 additions & 0 deletions patches/6133.diff

Large diffs are not rendered by default.

972 changes: 972 additions & 0 deletions patches/6834.diff

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ In the VS Code command palette :
* Debugger __Java+...__ - start main class or test on selected JDK. More in [Debugger section](#debugger-and-launch-configurations)
* __Test Explorer__ for Java tests results visualization and execution including editor code Lenses.
* Maven and Gradle support including multi-project projects, subprojects opening and Gradle priming builds.
* __Java: Go To Test/Tested Class__ - Navigates to the corresponding test or source class file

## Project Explorer
Project Explorer provides an overview of logical project structure, groups sources together and greatly simplifies Java package structure exploration. Project Explorer is an addition to the classical workspace explorer. Use it to build, test, execute and operate your Maven and Gradle Java projects.
Expand Down
19 changes: 19 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@
{
"command": "jdk.download.jdk",
"title": "Download, install and use JDK"
},
{
"command": "jdk.goto.test",
"title": "Go To Test/Tested class...",
"category": "Java"
}
],
"keybindings": [
Expand Down Expand Up @@ -468,6 +473,11 @@
"when": "nbJdkReady && editorLangId == java && editorTextFocus",
"group": "navigation@100"
},
{
"command": "jdk.goto.test",
"when": "nbJdkReady && editorLangId == java",
"group": "navigation@101"
},
{
"command": "jdk.project.run",
"when": "nbJdkReady && editorLangId == java && resourceExtname == .java",
Expand All @@ -485,6 +495,11 @@
"when": "nbJdkReady && explorerResourceIsFolder",
"group": "navigation@3"
},
{
"command": "jdk.goto.test",
"when": "nbJdkReady && resourceExtname == .java",
"group": "goto@1"
},
{
"command": "jdk.project.run",
"when": "nbJdkReady && resourceExtname == .java",
Expand All @@ -510,6 +525,10 @@
"command": "jdk.workspace.compile",
"when": "nbJdkReady"
},
{
"command": "jdk.goto.test",
"when": "nbJdkReady && editorLangId == java"
},
{
"command": "jdk.java.goto.super.implementation",
"when": "nbJdkReady && editorLangId == java"
Expand Down
42 changes: 42 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,48 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
throw `Client ${c} doesn't support new project`;
}
}));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.goto.test', async (ctx) => {
let c: LanguageClient = await client;
const commands = await vscode.commands.getCommands();
if (commands.includes(COMMAND_PREFIX + '.go.to.test')) {
try {
const res: Array<string> = await vscode.commands.executeCommand(COMMAND_PREFIX + '.go.to.test', contextUri(ctx)?.toString());
if (res?.length) {
if (res.length === 1) {
let file = vscode.Uri.parse(res[0]);
await vscode.window.showTextDocument(file, { preview: false });
} else {
const namePathMapping: { [key: string]: string } = {}
res.forEach(fp => {
const fileName = path.basename(fp);
namePathMapping[fileName] = fp
});
const selected = await window.showQuickPick(Object.keys(namePathMapping), {
title: 'Select files to open',
placeHolder: 'Test files or source files associated to each other',
canPickMany: true
});
if (selected) {
for await (const filePath of selected) {
let file = vscode.Uri.parse(filePath);
await vscode.window.showTextDocument(file, { preview: false });
}
} else {
vscode.window.showInformationMessage("No file selected");
}
}
}
else {
throw new Error("No corresponding file found");
}
} catch (err) {
vscode.window.showInformationMessage("Source file does not have corresponding test file or vice versa");
}
} else {
throw `Client ${c} doesn't support go to test`;
}
}));
context.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + ".download.jdk", async () => { openJDKSelectionView(log); }));
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.workspace.compile', () =>
wrapCommandWithProgress(COMMAND_PREFIX + '.build.workspace', 'Compiling workspace...', log, true)
Expand Down

0 comments on commit 010008c

Please sign in to comment.