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 Apr 18, 2022
1 parent 88a3c21 commit a8fee04
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 444 deletions.
53 changes: 2 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,30 +958,10 @@
"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"
},
{
Expand Down Expand Up @@ -1042,7 +1022,7 @@
"group": "navigation@90"
},
{
"command": "java.action.showTypeHierarchy",
"command": "java.action.showClassHierarchy",
"when": "javaLSReady && editorTextFocus && editorLangId == java",
"group": "0_navigation@3"
}
Expand All @@ -1068,21 +1048,9 @@
"command": "java.project.listSourcePaths.command",
"when": "javaLSReady"
},
{
"command": "java.action.showTypeHierarchy",
"when": "javaLSReady && editorIsOpen"
},
{
"command": "java.action.showClassHierarchy",
"when": "false"
},
{
"command": "java.action.showSubtypeHierarchy",
"when": "false"
},
{
"command": "java.action.showSupertypeHierarchy",
"when": "false"
"when": "javaLSReady && editorIsOpen"
},
{
"command": "java.action.changeBaseType",
Expand All @@ -1109,23 +1077,6 @@
"when": "java:serverMode == LightWeight"
}
],
"view/title": [
{
"command": "java.action.showClassHierarchy",
"group": "navigation@-1",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && typeHierarchySymbolKind != 10"
},
{
"command": "java.action.showSupertypeHierarchy",
"group": "navigation@0",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
},
{
"command": "java.action.showSubtypeHierarchy",
"group": "navigation@1",
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
}
],
"view/item/context": [
{
"command": "java.action.changeBaseType",
Expand Down
3 changes: 0 additions & 3 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +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",
"java.action.changeBaseType": "Base on this Type"
}
3 changes: 0 additions & 3 deletions package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +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": "显示子类层次结构",
"java.action.changeBaseType": "基于此类型"
}
22 changes: 1 addition & 21 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,33 +193,13 @@ export namespace Commands {
*/
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.
*/
export const SHOW_SUPERTYPE_HIERARCHY = 'java.action.showSupertypeHierarchy';
/**
* Show SubType Hierarchy of given Selection.
*/
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 @@ -285,7 +285,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 @@ -305,7 +305,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
25 changes: 7 additions & 18 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ 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 { snippetCompletionProvider } from "./snippetCompletionProvider";
import { JavaInlayHintsProvider } from "./inlayHintsProvider";
import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/proposed.typeHierarchy";
import { CodeTypeHierarchyItem } from "./typeHierarchy/protocol";

const extensionName = 'Language Support for Java';
const GRADLE_CHECKSUM = "gradle/checksum/prompt";
Expand Down Expand Up @@ -100,7 +101,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 @@ -375,30 +376,18 @@ 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);
}));

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) => {
context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: CodeTypeHierarchyItem) => {
typeHierarchyTree.changeBaseItem(item);
}));

Expand Down
Loading

0 comments on commit a8fee04

Please sign in to comment.