Skip to content

Commit

Permalink
feat: Add 'Reveal in Java Projects' in editor titile context
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo committed Sep 23, 2020
1 parent 42e2cef commit 6a807ba
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 17 deletions.
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.

27 changes: 22 additions & 5 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,9 +248,26 @@
],
"explorer/context": [
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceExtname == .java && java:projectManagerActivated && java:serverMode == Standard",
"group": "java:project_10"
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceFilename in java:supportedBuildFiles && java:projectManagerActivated && java:serverMode == Standard",
"group": "navigation@100"
},
{
"command": "java.view.package.revealInProjectExplorer",
"when": "resourceExtname == .java && java:projectManagerActivated && java:serverMode == Standard",
"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": "2_files@100"
}
],
"view/title": [
Expand Down Expand Up @@ -383,7 +400,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

0 comments on commit 6a807ba

Please sign in to comment.