Skip to content

Commit 67c9794

Browse files
committed
change type hierarchy implementation to LSP
Signed-off-by: Shi Chen <chenshi@microsoft.com>
1 parent a411ed3 commit 67c9794

14 files changed

+325
-424
lines changed

package.json

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -941,35 +941,22 @@
941941
"title": "%java.action.navigateToSuperImplementation%",
942942
"category": "Java"
943943
},
944-
{
945-
"command": "java.action.showTypeHierarchy",
946-
"title": "%java.action.showTypeHierarchy%",
947-
"category": "Java"
948-
},
949944
{
950945
"command": "java.action.showClassHierarchy",
951946
"title": "%java.action.showClassHierarchy%",
952947
"icon": "$(type-hierarchy)",
953-
"enablement": "typeHierarchyDirection != both && typeHierarchySymbolKind != 10",
954948
"category": "Java"
955949
},
956950
{
957951
"command": "java.action.showSupertypeHierarchy",
958952
"title": "%java.action.showSupertypeHierarchy%",
959953
"icon": "$(type-hierarchy-super)",
960-
"enablement": "typeHierarchyDirection != parents",
961954
"category": "Java"
962955
},
963956
{
964957
"command": "java.action.showSubtypeHierarchy",
965958
"title": "%java.action.showSubtypeHierarchy%",
966959
"icon": "$(type-hierarchy-sub)",
967-
"enablement": "typeHierarchyDirection != children",
968-
"category": "Java"
969-
},
970-
{
971-
"command": "java.action.changeBaseType",
972-
"title": "%java.action.changeBaseType%",
973960
"category": "Java"
974961
}
975962
],
@@ -1025,7 +1012,7 @@
10251012
"group": "navigation@90"
10261013
},
10271014
{
1028-
"command": "java.action.showTypeHierarchy",
1015+
"command": "java.action.showClassHierarchy",
10291016
"when": "javaLSReady && editorTextFocus && editorLangId == java",
10301017
"group": "0_navigation@3"
10311018
}
@@ -1051,13 +1038,9 @@
10511038
"command": "java.project.listSourcePaths.command",
10521039
"when": "javaLSReady"
10531040
},
1054-
{
1055-
"command": "java.action.showTypeHierarchy",
1056-
"when": "javaLSReady && editorIsOpen"
1057-
},
10581041
{
10591042
"command": "java.action.showClassHierarchy",
1060-
"when": "false"
1043+
"when": "javaLSReady && editorIsOpen"
10611044
},
10621045
{
10631046
"command": "java.action.showSubtypeHierarchy",
@@ -1067,10 +1050,6 @@
10671050
"command": "java.action.showSupertypeHierarchy",
10681051
"when": "false"
10691052
},
1070-
{
1071-
"command": "java.action.changeBaseType",
1072-
"when": "false"
1073-
},
10741053
{
10751054
"command": "java.project.updateSourceAttachment.command",
10761055
"when": "false"
@@ -1096,7 +1075,7 @@
10961075
{
10971076
"command": "java.action.showClassHierarchy",
10981077
"group": "navigation@-1",
1099-
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && typeHierarchySymbolKind != 10"
1078+
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == typeHierarchy && typeHierarchySymbolKind != 10"
11001079
},
11011080
{
11021081
"command": "java.action.showSupertypeHierarchy",
@@ -1108,13 +1087,6 @@
11081087
"group": "navigation@1",
11091088
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy"
11101089
}
1111-
],
1112-
"view/item/context": [
1113-
{
1114-
"command": "java.action.changeBaseType",
1115-
"group": "1",
1116-
"when": "view == references-view.tree && reference-list.hasResult && reference-list.source == javaTypeHierarchy && viewItem != 'false'"
1117-
}
11181090
]
11191091
}
11201092
},

package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +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",
1918
"java.action.showSupertypeHierarchy": "Show Supertype Hierarchy",
2019
"java.action.showSubtypeHierarchy": "Show Subtype Hierarchy",

package.nls.zh.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +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": "显示类的继承关系",
1918
"java.action.showSupertypeHierarchy": "显示父类层次结构",
2019
"java.action.showSubtypeHierarchy": "显示子类层次结构",

src/commands.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ export namespace Commands {
192192
* Navigate To Super Method Command.
193193
*/
194194
export const NAVIGATE_TO_SUPER_IMPLEMENTATION_COMMAND = 'java.action.navigateToSuperImplementation';
195-
/**
196-
* Open Type Hierarchy of given Selection.
197-
*/
198-
export const SHOW_TYPE_HIERARCHY = 'java.action.showTypeHierarchy';
199195
/**
200196
* Show SuperType Hierarchy of given Selection.
201197
*/
@@ -205,21 +201,9 @@ export namespace Commands {
205201
*/
206202
export const SHOW_SUBTYPE_HIERARCHY = 'java.action.showSubtypeHierarchy';
207203
/**
208-
* Show Type Hierarchy of given Selection.
204+
* Show Class Hierarchy of given Selection.
209205
*/
210206
export const SHOW_CLASS_HIERARCHY = 'java.action.showClassHierarchy';
211-
/**
212-
* Change the base type of Type Hierarchy.
213-
*/
214-
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';
223207
/**
224208
* Show server task status
225209
*/

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
284284
}
285285
const codeActionContext: CodeActionContext = {
286286
diagnostics: allDiagnostics,
287-
triggerKind: CodeActionTriggerKind?.Automatic,
287+
triggerKind: context.triggerKind,
288288
only: context.only,
289289
};
290290
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
@@ -304,7 +304,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
304304
}
305305
}
306306
return result;
307-
}, (error) => {
307+
}, () => {
308308
return Promise.resolve([]);
309309
});
310310
}

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: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position } from "vscode";
3+
import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position, TypeHierarchyItem } from "vscode";
44
import { Commands } from "./commands";
55
import { serverStatus, ServerStatusKind } from "./serverStatus";
66
import { prepareExecutable, awaitServerConnection } from "./javaServerStarter";
@@ -29,10 +29,11 @@ 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";
35+
import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/proposed.typeHierarchy";
36+
import { TypeHierarchyDirection, TypeItem, TypesModel } from "./typeHierarchy/model.reference-view";
3637

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

99100
// Create the language client and start the client.
100101
this.languageClient = new LanguageClient('java', extensionName, serverOptions, clientOptions);
101-
102+
this.languageClient.registerFeature(new TypeHierarchyFeature(this.languageClient));
102103
this.languageClient.onReady().then(() => {
103104
activationProgressNotification.showProgress();
104105
this.languageClient.onNotification(StatusNotification.type, (report) => {
@@ -371,31 +372,27 @@ export class StandardLanguageClient {
371372
}
372373
}));
373374

374-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_TYPE_HIERARCHY, (location: any) => {
375+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, (location: any) => {
375376
if (location instanceof Uri) {
376-
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
377+
typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active));
377378
} else {
378379
if (window.activeTextEditor?.document?.languageId !== "java") {
379380
return;
380381
}
381-
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active), TypeHierarchyDirection.Both);
382+
typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active));
382383
}
383384
}));
384385

385-
context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, () => {
386-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Both);
387-
}));
388-
389386
context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, () => {
390-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Parents);
387+
const typesModel: TypesModel = new TypesModel(TypeHierarchyDirection.Supertypes, [typeHierarchyTree.currentItem]);
388+
const typeItem: TypeItem = new TypeItem(typesModel, typeHierarchyTree.currentItem, undefined);
389+
commands.executeCommand("references-view.showSupertypes", typeItem);
391390
}));
392391

393392
context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, () => {
394-
typeHierarchyTree.changeDirection(TypeHierarchyDirection.Children);
395-
}));
396-
397-
context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: TypeHierarchyItem) => {
398-
typeHierarchyTree.changeBaseItem(item);
393+
const typesModel: TypesModel = new TypesModel(TypeHierarchyDirection.Subtypes, [typeHierarchyTree.currentItem]);
394+
const typeItem: TypeItem = new TypeItem(typesModel, typeHierarchyTree.currentItem, undefined);
395+
commands.executeCommand("references-view.showSubtypes", typeItem);
399396
}));
400397

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

0 commit comments

Comments
 (0)