Skip to content

feat: Add 'Reveal in Java Projects' in editor titile context #332

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 1 commit into from
Sep 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public static List<PackageNode> resolvePath(List<Object> arguments, IProgressMon
} else {
return getParentAncestorNodes(resource);
}
} else {
IContainer container = JDTUtils.findFolder(typeRootUri);
IJavaElement element = JavaCore.create(container);
result.add(PackageNode.createNodeForProject(element));
}
}

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"explorer"
],
"engines": {
"vscode": "^1.44.0"
"vscode": "^1.49.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -248,10 +248,27 @@
}
],
"explorer/context": [
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceFilename in java:supportedBuildFiles && java:projectManagerActivated && java:serverMode == Standard",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java:supportedBuildFiles? or in supportedBuildFiles

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's a name convention you used.

"group": "navigation@100"
},
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceExtname == .java && java:projectManagerActivated && java:serverMode == Standard",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paranthesis in "when" is not supported so here I split them into two part: microsoft/vscode#91473

"group": "navigation@100"
}
],
"editor/title/context": [
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceFilename in java:supportedBuildFiles && java:projectManagerActivated && java:serverMode == Standard",
"group": "2_files@100"
},
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceExtname == .java && java:projectManagerActivated && java:serverMode == Standard",
"group": "java:project_10"
"group": "2_files@100"
}
],
"view/title": [
Expand Down Expand Up @@ -394,7 +411,7 @@
"@types/minimatch": "^3.0.3",
"@types/mocha": "^5.2.7",
"@types/node": "^8.10.62",
"@types/vscode": "1.44.0",
"@types/vscode": "1.49.0",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"gulp-copy": "^4.0.1",
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

export namespace Context {
export const EXTENSION_ACTIVATED: string = "java:projectManagerActivated";
export const SUPPORTED_BUILD_FILES: string = "java:supportedBuildFiles";
}

export namespace Explorer {
Expand All @@ -15,3 +16,7 @@ export namespace Explorer {
Jar = "jar",
}
}

export namespace Build {
export const FILE_NAMES: string[] = ["pom.xml", "build.gradle"];
}
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { commands, Event, Extension, ExtensionContext, extensions, Uri } from "vscode";
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { Commands } from "./commands";
import { Context } from "./constants";
import { Build, Context } from "./constants";
import { contextManager } from "./contextManager";
import { LibraryController } from "./controllers/libraryController";
import { ProjectController } from "./controllers/projectController";
Expand Down Expand Up @@ -62,6 +62,7 @@ async function activateExtension(_operationId: string, context: ExtensionContext
context.subscriptions.push(contextManager);
context.subscriptions.push(syncHandler);
contextManager.setContextValue(Context.EXTENSION_ACTIVATED, true);
contextManager.setContextValue(Context.SUPPORTED_BUILD_FILES, Build.FILE_NAMES);

initExpService(context);
}));
Expand Down
4 changes: 4 additions & 0 deletions src/views/dataNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as _ from "lodash";
import { ProviderResult, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
import { INodeData } from "../java/nodeData";
import { ExplorerNode } from "./explorerNode";
Expand Down Expand Up @@ -45,6 +46,9 @@ export abstract class DataNode extends ExplorerNode {
}

public async revealPaths(paths: INodeData[]): Promise<DataNode> {
if (_.isEmpty(paths)) {
return this;
}
const childNodeData = paths.shift();
const children: ExplorerNode[] = await this.getChildren();
const childNode = children ? <DataNode>children.find((child: DataNode) =>
Expand Down
11 changes: 4 additions & 7 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,10 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
});
}

if (!this._rootItems || !element) {
return this.getRootNodes();
} else {
const children: ExplorerNode[] = await element.getChildren();
explorerNodeCache.saveNodes(children);
return children;
}
const children: ExplorerNode[] = (!this._rootItems || !element) ?
await this.getRootNodes() : await element.getChildren();
explorerNodeCache.saveNodes(children);
return children;
}

public getParent(element: ExplorerNode): ProviderResult<ExplorerNode> {
Expand Down
15 changes: 14 additions & 1 deletion src/views/dependencyExplorer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as fse from "fs-extra";
import * as path from "path";
import { commands, Disposable, ExtensionContext, TextEditor, TreeView, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
import { Build } from "../constants";
import { isStandardServerReady } from "../extension";
import { Jdtls } from "../java/jdtls";
import { INodeData } from "../java/nodeData";
Expand Down Expand Up @@ -50,7 +53,17 @@ 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);
let fsPath: string = uri.fsPath;
const fileName: string = path.basename(fsPath);
if (Build.FILE_NAMES.includes(fileName)) {
fsPath = path.dirname(fsPath);
}

uri = Uri.file(fsPath);
if ((await fse.stat(fsPath)).isFile()) {
await commands.executeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, uri);
}

this.reveal(uri);
}),
);
Expand Down