Skip to content

Commit a8fee04

Browse files
committed
change type hierarchy implementation to LSP
Signed-off-by: Shi Chen <[email protected]>
1 parent 88a3c21 commit a8fee04

File tree

13 files changed

+103
-444
lines changed

13 files changed

+103
-444
lines changed

package.json

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -958,30 +958,10 @@
958958
"title": "%java.action.navigateToSuperImplementation%",
959959
"category": "Java"
960960
},
961-
{
962-
"command": "java.action.showTypeHierarchy",
963-
"title": "%java.action.showTypeHierarchy%",
964-
"category": "Java"
965-
},
966961
{
967962
"command": "java.action.showClassHierarchy",
968963
"title": "%java.action.showClassHierarchy%",
969964
"icon": "$(type-hierarchy)",
970-
"enablement": "typeHierarchyDirection != both && typeHierarchySymbolKind != 10",
971-
"category": "Java"
972-
},
973-
{
974-
"command": "java.action.showSupertypeHierarchy",
975-
"title": "%java.action.showSupertypeHierarchy%",
976-
"icon": "$(type-hierarchy-super)",
977-
"enablement": "typeHierarchyDirection != parents",
978-
"category": "Java"
979-
},
980-
{
981-
"command": "java.action.showSubtypeHierarchy",
982-
"title": "%java.action.showSubtypeHierarchy%",
983-
"icon": "$(type-hierarchy-sub)",
984-
"enablement": "typeHierarchyDirection != children",
985965
"category": "Java"
986966
},
987967
{
@@ -1042,7 +1022,7 @@
10421022
"group": "navigation@90"
10431023
},
10441024
{
1045-
"command": "java.action.showTypeHierarchy",
1025+
"command": "java.action.showClassHierarchy",
10461026
"when": "javaLSReady && editorTextFocus && editorLangId == java",
10471027
"group": "0_navigation@3"
10481028
}
@@ -1068,21 +1048,9 @@
10681048
"command": "java.project.listSourcePaths.command",
10691049
"when": "javaLSReady"
10701050
},
1071-
{
1072-
"command": "java.action.showTypeHierarchy",
1073-
"when": "javaLSReady && editorIsOpen"
1074-
},
10751051
{
10761052
"command": "java.action.showClassHierarchy",
1077-
"when": "false"
1078-
},
1079-
{
1080-
"command": "java.action.showSubtypeHierarchy",
1081-
"when": "false"
1082-
},
1083-
{
1084-
"command": "java.action.showSupertypeHierarchy",
1085-
"when": "false"
1053+
"when": "javaLSReady && editorIsOpen"
10861054
},
10871055
{
10881056
"command": "java.action.changeBaseType",
@@ -1109,23 +1077,6 @@
11091077
"when": "java:serverMode == LightWeight"
11101078
}
11111079
],
1112-
"view/title": [
1113-
{
1114-
"command": "java.action.showClassHierarchy",
1115-
"group": "navigation@-1",
1116-
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && typeHierarchySymbolKind != 10"
1117-
},
1118-
{
1119-
"command": "java.action.showSupertypeHierarchy",
1120-
"group": "navigation@0",
1121-
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
1122-
},
1123-
{
1124-
"command": "java.action.showSubtypeHierarchy",
1125-
"group": "navigation@1",
1126-
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
1127-
}
1128-
],
11291080
"view/item/context": [
11301081
{
11311082
"command": "java.action.changeBaseType",

package.nls.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"java.project.listSourcePaths": "List All Java Source Paths",
1515
"java.show.server.task.status": "Show Build Job Status",
1616
"java.action.navigateToSuperImplementation": "Go to Super Implementation",
17-
"java.action.showTypeHierarchy": "Show Type Hierarchy",
1817
"java.action.showClassHierarchy": "Show Class Hierarchy",
19-
"java.action.showSupertypeHierarchy": "Show Supertype Hierarchy",
20-
"java.action.showSubtypeHierarchy": "Show Subtype Hierarchy",
2118
"java.action.changeBaseType": "Base on this Type"
2219
}

package.nls.zh.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"java.project.listSourcePaths": "列出所有 Java 源代码路径",
1515
"java.show.server.task.status": "显示工作状态",
1616
"java.action.navigateToSuperImplementation": "转到父类实现",
17-
"java.action.showTypeHierarchy": "显示类型层次结构",
1817
"java.action.showClassHierarchy": "显示类的继承关系",
19-
"java.action.showSupertypeHierarchy": "显示父类层次结构",
20-
"java.action.showSubtypeHierarchy": "显示子类层次结构",
2118
"java.action.changeBaseType": "基于此类型"
2219
}

src/commands.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,13 @@ export namespace Commands {
193193
*/
194194
export const NAVIGATE_TO_SUPER_IMPLEMENTATION_COMMAND = 'java.action.navigateToSuperImplementation';
195195
/**
196-
* Open Type Hierarchy of given Selection.
197-
*/
198-
export const SHOW_TYPE_HIERARCHY = 'java.action.showTypeHierarchy';
199-
/**
200-
* Show SuperType Hierarchy of given Selection.
201-
*/
202-
export const SHOW_SUPERTYPE_HIERARCHY = 'java.action.showSupertypeHierarchy';
203-
/**
204-
* Show SubType Hierarchy of given Selection.
205-
*/
206-
export const SHOW_SUBTYPE_HIERARCHY = 'java.action.showSubtypeHierarchy';
207-
/**
208-
* Show Type Hierarchy of given Selection.
196+
* Show Class Hierarchy of given Selection.
209197
*/
210198
export const SHOW_CLASS_HIERARCHY = 'java.action.showClassHierarchy';
211199
/**
212200
* Change the base type of Type Hierarchy.
213201
*/
214202
export const CHANGE_BASE_TYPE = 'java.action.changeBaseType';
215-
/**
216-
* Open the given TypeHierarchy Item.
217-
*/
218-
export const OPEN_TYPE_HIERARCHY = 'java.navigate.openTypeHierarchy';
219-
/**
220-
* Resolve the given TypeHierarchy Item.
221-
*/
222-
export const RESOLVE_TYPE_HIERARCHY = 'java.navigate.resolveTypeHierarchy';
223203
/**
224204
* Show server task status
225205
*/

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
285285
}
286286
const codeActionContext: CodeActionContext = {
287287
diagnostics: allDiagnostics,
288-
triggerKind: CodeActionTriggerKind?.Automatic,
288+
triggerKind: context.triggerKind,
289289
only: context.only,
290290
};
291291
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
@@ -305,7 +305,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
305305
}
306306
}
307307
return result;
308-
}, (error) => {
308+
}, () => {
309309
return Promise.resolve([]);
310310
});
311311
}

src/refactorAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R
214214
}
215215

216216
if (refactorEdit.edit) {
217-
const edit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
217+
const edit = languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
218218
if (edit) {
219219
await workspace.applyEdit(edit);
220220
}

src/standardLanguageClient.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ import * as fileEventHandler from './fileEventHandler';
2929
import { markdownPreviewProvider } from "./markdownPreviewProvider";
3030
import { RefactorDocumentProvider, javaRefactorKinds } from "./codeActionProvider";
3131
import { typeHierarchyTree } from "./typeHierarchy/typeHierarchyTree";
32-
import { TypeHierarchyDirection, TypeHierarchyItem } from "./typeHierarchy/protocol";
3332
import { buildFilePatterns } from './plugin';
3433
import { pomCodeActionMetadata, PomCodeActionProvider } from "./pom/pomCodeActionProvider";
3534
import { findRuntimes, IJavaRuntime } from "jdk-utils";
3635
import { snippetCompletionProvider } from "./snippetCompletionProvider";
3736
import { JavaInlayHintsProvider } from "./inlayHintsProvider";
37+
import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/proposed.typeHierarchy";
38+
import { CodeTypeHierarchyItem } from "./typeHierarchy/protocol";
3839

3940
const extensionName = 'Language Support for Java';
4041
const GRADLE_CHECKSUM = "gradle/checksum/prompt";
@@ -100,7 +101,7 @@ export class StandardLanguageClient {
100101

101102
// Create the language client and start the client.
102103
this.languageClient = new LanguageClient('java', extensionName, serverOptions, clientOptions);
103-
104+
this.languageClient.registerFeature(new TypeHierarchyFeature(this.languageClient));
104105
this.languageClient.onReady().then(() => {
105106
activationProgressNotification.showProgress();
106107
this.languageClient.onNotification(StatusNotification.type, (report) => {
@@ -375,30 +376,18 @@ export class StandardLanguageClient {
375376
}
376377
}));
377378

378-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_TYPE_HIERARCHY, (location: any) => {
379+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, (location: any) => {
379380
if (location instanceof Uri) {
380-
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
381+
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active));
381382
} else {
382383
if (window.activeTextEditor?.document?.languageId !== "java") {
383384
return;
384385
}
385-
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
386+
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active));
386387
}
387388
}));
388389

389-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, () => {
390-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Both);
391-
}));
392-
393-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, () => {
394-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Parents);
395-
}));
396-
397-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, () => {
398-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Children);
399-
}));
400-
401-
context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: TypeHierarchyItem) => {
390+
context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: CodeTypeHierarchyItem) => {
402391
typeHierarchyTree.changeBaseItem(item);
403392
}));
404393

0 commit comments

Comments
 (0)