|
2 | 2 |
|
3 | 3 | import * as net from 'net'; |
4 | 4 | import * as path from 'path'; |
5 | | -import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode"; |
| 5 | +import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, TypeHierarchyItem, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode"; |
6 | 6 | import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, StaticFeature, ClientCapabilities, FeatureState, TelemetryEventNotification } from "vscode-languageclient"; |
| 7 | +import { TypeHierarchyFeature } from 'vscode-languageclient/lib/common/typeHierarchy'; |
7 | 8 | import { LanguageClient, StreamInfo } from "vscode-languageclient/node"; |
8 | 9 | import { apiManager } from "./apiManager"; |
9 | 10 | import * as buildPath from './buildpath'; |
@@ -32,7 +33,7 @@ import { snippetCompletionProvider } from "./snippetCompletionProvider"; |
32 | 33 | import * as sourceAction from './sourceAction'; |
33 | 34 | import { askForProjects, projectConfigurationUpdate, upgradeGradle } from "./standardLanguageClientUtils"; |
34 | 35 | import { TracingLanguageClient } from './TracingLanguageClient'; |
35 | | -import { TypeHierarchyDirection, TypeHierarchyItem } from "./typeHierarchy/protocol"; |
| 36 | +import { CodeTypeHierarchyItem, showSubtypeHierarchyReferenceViewCommand, showSupertypeHierarchyReferenceViewCommand, showTypeHierarchyReferenceViewCommand } from "./typeHierarchy/protocol"; |
36 | 37 | import { typeHierarchyTree } from "./typeHierarchy/typeHierarchyTree"; |
37 | 38 | import { getAllJavaProjects, getAllProjects, getJavaConfiguration, isPrereleaseOrInsiderVersion } from "./utils"; |
38 | 39 | import { Telemetry } from "./telemetry"; |
@@ -109,6 +110,7 @@ export class StandardLanguageClient { |
109 | 110 | // Create the language client and start the client. |
110 | 111 | this.languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions, DEBUG); |
111 | 112 | this.languageClient.registerFeature(new DisableWillRenameFeature()); |
| 113 | + this.languageClient.registerFeature(new TypeHierarchyFeature(this.languageClient)); |
112 | 114 |
|
113 | 115 | this.registerCommandsForStandardServer(context, jdtEventEmitter); |
114 | 116 | fileEventHandler.registerFileEventHandlers(this.languageClient, context); |
@@ -490,31 +492,68 @@ export class StandardLanguageClient { |
490 | 492 | } |
491 | 493 | })); |
492 | 494 |
|
493 | | - context.subscriptions.push(commands.registerCommand(Commands.SHOW_TYPE_HIERARCHY, (location: any) => { |
494 | | - if (location instanceof Uri) { |
495 | | - typeHierarchyTree.setTypeHierarchy(new Location(location, window.activeTextEditor.selection.active), TypeHierarchyDirection.both); |
496 | | - } else { |
497 | | - if (window.activeTextEditor?.document?.languageId !== "java") { |
498 | | - return; |
| 495 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, async (anchor: any) => { |
| 496 | + try { |
| 497 | + if (anchor instanceof Uri) { // comes from context menu |
| 498 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor, window.activeTextEditor.selection.active)); |
| 499 | + } else if (anchor instanceof TypeHierarchyItem) { // comes from class hierarchy view item |
| 500 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor.uri, anchor.range.start)); |
| 501 | + } else { // comes from command palette |
| 502 | + if (window.activeTextEditor?.document?.languageId !== "java") { |
| 503 | + return; |
| 504 | + } |
| 505 | + await typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active)); |
| 506 | + } |
| 507 | + } catch (e) { |
| 508 | + if (e?.message) { |
| 509 | + // show message in the selection when call from editor context menu |
| 510 | + if (anchor instanceof Uri) { |
| 511 | + showNoLocationFound(e.message); |
| 512 | + } else { |
| 513 | + window.showErrorMessage(e.message); |
| 514 | + } |
499 | 515 | } |
500 | | - typeHierarchyTree.setTypeHierarchy(new Location(window.activeTextEditor.document.uri, window.activeTextEditor.selection.active), TypeHierarchyDirection.both); |
501 | 516 | } |
502 | 517 | })); |
503 | 518 |
|
504 | | - context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY, () => { |
505 | | - typeHierarchyTree.changeDirection(TypeHierarchyDirection.both); |
506 | | - })); |
507 | | - |
508 | | - context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, () => { |
509 | | - typeHierarchyTree.changeDirection(TypeHierarchyDirection.parents); |
| 519 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_CLASS_HIERARCHY_FROM_REFERENCE_VIEW, async (anchor?: any) => { |
| 520 | + try { |
| 521 | + if (!anchor) { // comes from reference-view's title or command palette |
| 522 | + await typeHierarchyTree.setTypeHierarchyFromReferenceView(); |
| 523 | + } else if (anchor.item instanceof TypeHierarchyItem) { // comes from reference-view's item |
| 524 | + await typeHierarchyTree.setTypeHierarchy(new Location(anchor.item.uri, anchor.item.range.start)); |
| 525 | + } |
| 526 | + } catch (e) { |
| 527 | + if (e?.message) { |
| 528 | + window.showErrorMessage(e.message); |
| 529 | + } |
| 530 | + } |
510 | 531 | })); |
511 | 532 |
|
512 | | - context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, () => { |
513 | | - typeHierarchyTree.changeDirection(TypeHierarchyDirection.children); |
| 533 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUPERTYPE_HIERARCHY, async (anchor?: any) => { |
| 534 | + let location: Location; |
| 535 | + if (!anchor) { |
| 536 | + location = typeHierarchyTree.getAnchor(); |
| 537 | + } else if (anchor instanceof TypeHierarchyItem) { |
| 538 | + location = new Location(anchor.uri, anchor.range.start); |
| 539 | + } |
| 540 | + if (location) { |
| 541 | + await commands.executeCommand(showTypeHierarchyReferenceViewCommand); |
| 542 | + await commands.executeCommand(showSupertypeHierarchyReferenceViewCommand, location); |
| 543 | + } |
514 | 544 | })); |
515 | 545 |
|
516 | | - context.subscriptions.push(commands.registerCommand(Commands.CHANGE_BASE_TYPE, async (item: TypeHierarchyItem) => { |
517 | | - typeHierarchyTree.changeBaseItem(item); |
| 546 | + context.subscriptions.push(commands.registerCommand(Commands.SHOW_SUBTYPE_HIERARCHY, async (anchor?: any) => { |
| 547 | + let location: Location; |
| 548 | + if (!anchor) { |
| 549 | + location = typeHierarchyTree.getAnchor(); |
| 550 | + } else if (anchor instanceof TypeHierarchyItem) { |
| 551 | + location = new Location(anchor.uri, anchor.range.start); |
| 552 | + } |
| 553 | + if (location) { |
| 554 | + await commands.executeCommand(showTypeHierarchyReferenceViewCommand); |
| 555 | + await commands.executeCommand(showSubtypeHierarchyReferenceViewCommand, location); |
| 556 | + } |
518 | 557 | })); |
519 | 558 |
|
520 | 559 | context.subscriptions.push(commands.registerCommand(Commands.BUILD_PROJECT, async (uris: Uri[] | Uri, isFullBuild: boolean, token: CancellationToken) => { |
|
0 commit comments