Skip to content

feat: Can reveal the Java Project explorer from java source file #327

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

Merged
merged 4 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"command": "java.project.clean.workspace",
"title": "%contributes.commands.java.project.clean.workspace%"
},
{
"command": "java.view.package.revealInProjectExplorer",
"title": "%contributes.commands.java.view.package.revealInProjectExplorer%",
"category": "Java"
},
{
"command": "java.view.package.refresh",
"title": "%contributes.commands.java.view.package.refresh%",
Expand Down Expand Up @@ -234,6 +239,17 @@
{
"command": "java.project.clean.workspace",
"when": "never"
},
{
"command": "java.view.package.revealInProjectExplorer",
"when": "never"
}
],
"explorer/context": [
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceExtname == .java && extensionActivated && java:serverMode == Standard",
"group": "java:project_10"
}
],
"view/title": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"contributes.commands.java.view.package.refresh": "Refresh",
"contributes.commands.java.project.build.workspace": "Build Workspace",
"contributes.commands.java.project.clean.workspace": "Clean Workspace",
"contributes.commands.java.view.package.revealInProjectExplorer": "Reveal in Java Projects",
"contributes.commands.java.view.package.changeToFlatPackageView":"Flat View",
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View",
"contributes.commands.java.view.package.linkWithFolderExplorer":"Synchronize with Editor",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"contributes.commands.java.view.package.refresh": "刷新",
"contributes.commands.java.project.build.workspace": "构建工作空间",
"contributes.commands.java.project.clean.workspace": "清理工作空间",
"contributes.commands.java.view.package.revealInProjectExplorer": "在 Java 项目视图中显示",
"contributes.commands.java.view.package.changeToFlatPackageView":"平行显示",
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示",
"contributes.commands.java.view.package.linkWithFolderExplorer":"启用编辑器关联",
Expand Down
4 changes: 4 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export namespace Commands {

export const VIEW_PACKAGE_NEW_JAVA_PACKAGE = "java.view.package.newPackage";

export const VIEW_PACKAGE_REVEAL_IN_PROJECT_EXPLORER = "java.view.package.revealInProjectExplorer";

export const JAVA_PROJECT_CREATE = "java.project.create";

export const JAVA_PROJECT_ADD_LIBRARIES = "java.project.addLibraries";
Expand All @@ -48,6 +50,8 @@ export namespace Commands {

export const JAVA_PROJECT_CLEAN_WORKSPACE = "java.project.clean.workspace";

export const JAVA_PROJECT_EXPLORER_FOCUS = "javaProjectExplorer.focus";

export const JAVA_MAVEN_CREATE_PROJECT = "maven.archetype.generate";

export const JAVA_PROJECT_LIST = "java.project.list";
Expand Down
12 changes: 11 additions & 1 deletion src/views/dependencyExplorer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Disposable, ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
import { commands, Disposable, ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
import { isStandardServerReady } from "../extension";
import { Jdtls } from "../java/jdtls";
import { INodeData } from "../java/nodeData";
Expand Down Expand Up @@ -44,6 +46,14 @@ export class DependencyExplorer implements Disposable {
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_IN_PROJECT_EXPLORER, async (uri: Uri) => {
await commands.executeCommand(Commands.JAVA_PROJECT_EXPLORER_FOCUS);
await commands.executeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, uri);
this.reveal(uri);
}),
);
}

public dispose(): void {
Expand Down