Skip to content

Commit

Permalink
change type hierarchy implementation to LSP
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Mar 24, 2022
1 parent a411ed3 commit 67c9794
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 424 deletions.
34 changes: 3 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,35 +941,22 @@
"title": "%java.action.navigateToSuperImplementation%",
"category": "Java"
},
{
"command": "java.action.showTypeHierarchy",
"title": "%java.action.showTypeHierarchy%",
"category": "Java"
},
{
"command": "java.action.showClassHierarchy",
"title": "%java.action.showClassHierarchy%",
"icon": "$(type-hierarchy)",
"enablement": "typeHierarchyDirection != both && typeHierarchySymbolKind != 10",
"category": "Java"
},
{
"command": "java.action.showSupertypeHierarchy",
"title": "%java.action.showSupertypeHierarchy%",
"icon": "$(type-hierarchy-super)",
"enablement": "typeHierarchyDirection != parents",
"category": "Java"
},
{
"command": "java.action.showSubtypeHierarchy",
"title": "%java.action.showSubtypeHierarchy%",
"icon": "$(type-hierarchy-sub)",
"enablement": "typeHierarchyDirection != children",
"category": "Java"
},
{
"command": "java.action.changeBaseType",
"title": "%java.action.changeBaseType%",
"category": "Java"
}
],
Expand Down Expand Up @@ -1025,7 +1012,7 @@
"group": "navigation@90"
},
{
"command": "java.action.showTypeHierarchy",
"command": "java.action.showClassHierarchy",
"when": "javaLSReady && editorTextFocus && editorLangId == java",
"group": "0_navigation@3"
}
Expand All @@ -1051,13 +1038,9 @@
"command": "java.project.listSourcePaths.command",
"when": "javaLSReady"
},
{
"command": "java.action.showTypeHierarchy",
"when": "javaLSReady && editorIsOpen"
},
{
"command": "java.action.showClassHierarchy",
"when": "false"
"when": "javaLSReady && editorIsOpen"
},
{
"command": "java.action.showSubtypeHierarchy",
Expand All @@ -1067,10 +1050,6 @@
"command": "java.action.showSupertypeHierarchy",
"when": "false"
},
{
"command": "java.action.changeBaseType",
"when": "false"
},
{
"command": "java.project.updateSourceAttachment.command",
"when": "false"
Expand All @@ -1096,7 +1075,7 @@
{
"command": "java.action.showClassHierarchy",
"group": "navigation@-1",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && typeHierarchySymbolKind != 10"
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == typeHierarchy && typeHierarchySymbolKind != 10"
},
{
"command": "java.action.showSupertypeHierarchy",
Expand All @@ -1108,13 +1087,6 @@
"group": "navigation@1",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
}
],
"view/item/context": [
{
"command": "java.action.changeBaseType",
"group": "1",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && viewItem != 'false'"
}
]
}
},
Expand Down
1 change: 0 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"java.project.listSourcePaths": "List All Java Source Paths",
"java.show.server.task.status": "Show Build Job Status",
"java.action.navigateToSuperImplementation": "Go to Super Implementation",
"java.action.showTypeHierarchy": "Show Type Hierarchy",
"java.action.showClassHierarchy": "Show Class Hierarchy",
"java.action.showSupertypeHierarchy": "Show Supertype Hierarchy",
"java.action.showSubtypeHierarchy": "Show Subtype Hierarchy",
Expand Down
1 change: 0 additions & 1 deletion package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"java.project.listSourcePaths": "列出所有 Java 源代码路径",
"java.show.server.task.status": "显示工作状态",
"java.action.navigateToSuperImplementation": "转到父类实现",
"java.action.showTypeHierarchy": "显示类型层次结构",
"java.action.showClassHierarchy": "显示类的继承关系",
"java.action.showSupertypeHierarchy": "显示父类层次结构",
"java.action.showSubtypeHierarchy": "显示子类层次结构",
Expand Down
18 changes: 1 addition & 17 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ export namespace Commands {
* Navigate To Super Method Command.
*/
export const NAVIGATE_TO_SUPER_IMPLEMENTATION_COMMAND = 'java.action.navigateToSuperImplementation';
/**
* Open Type Hierarchy of given Selection.
*/
export const SHOW_TYPE_HIERARCHY = 'java.action.showTypeHierarchy';
/**
* Show SuperType Hierarchy of given Selection.
*/
Expand All @@ -205,21 +201,9 @@ export namespace Commands {
*/
export const SHOW_SUBTYPE_HIERARCHY = 'java.action.showSubtypeHierarchy';
/**
* Show Type Hierarchy of given Selection.
* Show Class Hierarchy of given Selection.
*/
export const SHOW_CLASS_HIERARCHY = 'java.action.showClassHierarchy';
/**
* Change the base type of Type Hierarchy.
*/
export const CHANGE_BASE_TYPE = 'java.action.changeBaseType';
/**
* Open the given TypeHierarchy Item.
*/
export const OPEN_TYPE_HIERARCHY = 'java.navigate.openTypeHierarchy';
/**
* Resolve the given TypeHierarchy Item.
*/
export const RESOLVE_TYPE_HIERARCHY = 'java.navigate.resolveTypeHierarchy';
/**
* Show server task status
*/
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}
const codeActionContext: CodeActionContext = {
diagnostics: allDiagnostics,
triggerKind: CodeActionTriggerKind?.Automatic,
triggerKind: context.triggerKind,
only: context.only,
};
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
Expand All @@ -304,7 +304,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}
}
return result;
}, (error) => {
}, () => {
return Promise.resolve([]);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/refactorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R
}

if (refactorEdit.edit) {
const edit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
const edit = languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
if (edit) {
await workspace.applyEdit(edit);
}
Expand Down
29 changes: 13 additions & 16 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position } from "vscode";
import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position, TypeHierarchyItem } from "vscode";
import { Commands } from "./commands";
import { serverStatus, ServerStatusKind } from "./serverStatus";
import { prepareExecutable, awaitServerConnection } from "./javaServerStarter";
Expand Down Expand Up @@ -29,10 +29,11 @@ import * as fileEventHandler from './fileEventHandler';
import { markdownPreviewProvider } from "./markdownPreviewProvider";
import { RefactorDocumentProvider, javaRefactorKinds } from "./codeActionProvider";
import { typeHierarchyTree } from "./typeHierarchy/typeHierarchyTree";
import { TypeHierarchyDirection, TypeHierarchyItem } from "./typeHierarchy/protocol";
import { buildFilePatterns } from './plugin';
import { pomCodeActionMetadata, PomCodeActionProvider } from "./pom/pomCodeActionProvider";
import { findRuntimes, IJavaRuntime } from "jdk-utils";
import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/proposed.typeHierarchy";
import { TypeHierarchyDirection, TypeItem, TypesModel } from "./typeHierarchy/model.reference-view";

const extensionName = 'Language Support for Java';
const GRADLE_CHECKSUM = "gradle/checksum/prompt";
Expand Down Expand Up @@ -98,7 +99,7 @@ export class StandardLanguageClient {

// Create the language client and start the client.
this.languageClient = new LanguageClient('java', extensionName, serverOptions, clientOptions);

this.languageClient.registerFeature(new TypeHierarchyFeature(this.languageClient));
this.languageClient.onReady().then(() => {
activationProgressNotification.showProgress();
this.languageClient.onNotification(StatusNotification.type, (report) => {
Expand Down Expand Up @@ -371,31 +372,27 @@ export class StandardLanguageClient {
}
}));

context.subscriptions.push(commands.registerCommand(Commands.SHOW_TYPE_HIERARCHY, (location: any) => {
context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, (location: any) => {
if (location instanceof Uri) {
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active));
} else {
if (window.activeTextEditor?.document?.languageId !== "java") {
return;
}
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active));
}
}));

context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, () => {
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Both);
}));

context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, () => {
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Parents);
const typesModel: TypesModel = new TypesModel(TypeHierarchyDirection.Supertypes, [typeHierarchyTree.currentItem]);
const typeItem: TypeItem = new TypeItem(typesModel, typeHierarchyTree.currentItem, undefined);
commands.executeCommand("references-view.showSupertypes", typeItem);
}));

context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, () => {
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Children);
}));

context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: TypeHierarchyItem) => {
typeHierarchyTree.changeBaseItem(item);
const typesModel: TypesModel = new TypesModel(TypeHierarchyDirection.Subtypes, [typeHierarchyTree.currentItem]);
const typeItem: TypeItem = new TypeItem(typesModel, typeHierarchyTree.currentItem, undefined);
commands.executeCommand("references-view.showSubtypes", typeItem);
}));

context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean, token?: CancellationToken) => {
Expand Down
Loading

0 comments on commit 67c9794

Please sign in to comment.