|
1 | 1 | 'use strict'; |
2 | 2 |
|
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"; |
4 | 4 | import { Commands } from "./commands"; |
5 | 5 | import { serverStatus, ServerStatusKind } from "./serverStatus"; |
6 | 6 | import { prepareExecutable, awaitServerConnection } from "./javaServerStarter"; |
@@ -35,7 +35,7 @@ import { findRuntimes, IJavaRuntime } from "jdk-utils"; |
35 | 35 | import { snippetCompletionProvider } from "./snippetCompletionProvider"; |
36 | 36 | import { JavaInlayHintsProvider } from "./inlayHintsProvider"; |
37 | 37 | import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/proposed.typeHierarchy"; |
38 | | -import { CodeTypeHierarchyItem } from "./typeHierarchy/protocol"; |
| 38 | +import { CodeTypeHierarchyItem, showSubtypeHierarchyReferenceViewCommand, showSupertypeHierarchyReferenceViewCommand, showTypeHierarchyReferenceViewCommand } from "./typeHierarchy/protocol"; |
39 | 39 |
|
40 | 40 | const extensionName = 'Language Support for Java'; |
41 | 41 | const GRADLE_CHECKSUM = "gradle/checksum/prompt"; |
@@ -376,19 +376,68 @@ export class StandardLanguageClient { |
376 | 376 | } |
377 | 377 | })); |
378 | 378 |
|
379 | | - context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, (location: any) => { |
380 | | - if (location instanceof Uri) { |
381 | | - typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active)); |
382 | | - } else { |
383 | | - if (window.activeTextEditor?.document?.languageId !== "java") { |
384 | | - return; |
| 379 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, async (anchor: any) => { |
| 380 | + try { |
| 381 | + if (anchor instanceof Uri) { // comes from context menu |
| 382 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor, window.activeTextEditor.selection.active)); |
| 383 | + } else if (anchor instanceof TypeHierarchyItem) { // comes from class hierarchy view item |
| 384 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor.uri, anchor.range.start)); |
| 385 | + } else { // comes from command palette |
| 386 | + if (window.activeTextEditor?.document?.languageId !== "java") { |
| 387 | + return; |
| 388 | + } |
| 389 | + await typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active)); |
| 390 | + } |
| 391 | + } catch (e) { |
| 392 | + if (e?.message) { |
| 393 | + // show message in the selection when call from editor context menu |
| 394 | + if (anchor instanceof Uri) { |
| 395 | + showNoLocationFound(e.message); |
| 396 | + } else { |
| 397 | + window.showErrorMessage(e.message); |
| 398 | + } |
385 | 399 | } |
386 | | - typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active)); |
387 | 400 | } |
388 | 401 | })); |
389 | 402 |
|
390 | | - context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: CodeTypeHierarchyItem) => { |
391 | | - typeHierarchyTree.changeBaseItem(item); |
| 403 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY_FROM_REFERENCE_VIEW, async (anchor?: any) => { |
| 404 | + try { |
| 405 | + if (!anchor) { // comes from reference-view's title or command palette |
| 406 | + await typeHierarchyTree.setTypeHierarchyFromReferenceView(); |
| 407 | + } else if (anchor.item instanceof TypeHierarchyItem) { // comes from reference-view's item |
| 408 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor.item.uri, anchor.item.range.start)); |
| 409 | + } |
| 410 | + } catch (e) { |
| 411 | + if (e?.message) { |
| 412 | + window.showErrorMessage(e.message); |
| 413 | + } |
| 414 | + } |
| 415 | + })); |
| 416 | + |
| 417 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, async (anchor?: any) => { |
| 418 | + let location: Location; |
| 419 | + if (!anchor) { |
| 420 | + location = typeHierarchyTree.getAnchor(); |
| 421 | + } else if (anchor instanceof TypeHierarchyItem) { |
| 422 | + location = new Location(anchor.uri, anchor.range.start); |
| 423 | + } |
| 424 | + if (location) { |
| 425 | + await commands.executeCommand(showTypeHierarchyReferenceViewCommand); |
| 426 | + await commands.executeCommand(showSupertypeHierarchyReferenceViewCommand, location); |
| 427 | + } |
| 428 | + })); |
| 429 | + |
| 430 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, async (anchor?: any) => { |
| 431 | + let location: Location; |
| 432 | + if (!anchor) { |
| 433 | + location = typeHierarchyTree.getAnchor(); |
| 434 | + } else if (anchor instanceof TypeHierarchyItem) { |
| 435 | + location = new Location(anchor.uri, anchor.range.start); |
| 436 | + } |
| 437 | + if (location) { |
| 438 | + await commands.executeCommand(showTypeHierarchyReferenceViewCommand); |
| 439 | + await commands.executeCommand(showSubtypeHierarchyReferenceViewCommand, location); |
| 440 | + } |
392 | 441 | })); |
393 | 442 |
|
394 | 443 | context.subscriptions.push(commands.registerCommand(Commands.COMPILE_WORKSPACE, (isFullCompile: boolean, token?: CancellationToken) => { |
|
0 commit comments