@@ -4,8 +4,9 @@ import * as fse from 'fs-extra';
4
4
import { findRuntimes } from "jdk-utils" ;
5
5
import * as net from 'net' ;
6
6
import * as path from 'path' ;
7
- import { CancellationToken , CodeActionKind , commands , ConfigurationTarget , DocumentSelector , EventEmitter , ExtensionContext , extensions , languages , Location , ProgressLocation , TextEditor , Uri , ViewColumn , window , workspace } from "vscode" ;
7
+ import { CancellationToken , CodeActionKind , commands , ConfigurationTarget , DocumentSelector , EventEmitter , ExtensionContext , extensions , languages , Location , ProgressLocation , TextEditor , TypeHierarchyItem , Uri , ViewColumn , window , workspace } from "vscode" ;
8
8
import { ConfigurationParams , ConfigurationRequest , LanguageClientOptions , Location as LSLocation , MessageType , Position as LSPosition , TextDocumentPositionParams , WorkspaceEdit } from "vscode-languageclient" ;
9
+ import { TypeHierarchyFeature } from 'vscode-languageclient/lib/common/typeHierarchy' ;
9
10
import { LanguageClient , StreamInfo } from "vscode-languageclient/node" ;
10
11
import { apiManager } from "./apiManager" ;
11
12
import * as buildPath from './buildpath' ;
@@ -34,7 +35,7 @@ import { snippetCompletionProvider } from "./snippetCompletionProvider";
34
35
import * as sourceAction from './sourceAction' ;
35
36
import { askForProjects , projectConfigurationUpdate , upgradeGradle } from "./standardLanguageClientUtils" ;
36
37
import { TracingLanguageClient } from './TracingLanguageClient' ;
37
- import { TypeHierarchyDirection , TypeHierarchyItem } from "./typeHierarchy/protocol" ;
38
+ import { CodeTypeHierarchyItem , showSubtypeHierarchyReferenceViewCommand , showSupertypeHierarchyReferenceViewCommand , showTypeHierarchyReferenceViewCommand } from "./typeHierarchy/protocol" ;
38
39
import { typeHierarchyTree } from "./typeHierarchy/typeHierarchyTree" ;
39
40
import { getAllJavaProjects , getJavaConfig , getJavaConfiguration } from "./utils" ;
40
41
import { Telemetry } from "./telemetry" ;
@@ -107,7 +108,7 @@ export class StandardLanguageClient {
107
108
108
109
// Create the language client and start the client.
109
110
this . languageClient = new TracingLanguageClient ( 'java' , extensionName , serverOptions , clientOptions ) ;
110
-
111
+ this . languageClient . registerFeature ( new TypeHierarchyFeature ( this . languageClient ) ) ;
111
112
this . registerCommandsForStandardServer ( context , jdtEventEmitter ) ;
112
113
fileEventHandler . registerFileEventHandlers ( this . languageClient , context ) ;
113
114
@@ -376,31 +377,68 @@ export class StandardLanguageClient {
376
377
}
377
378
} ) ) ;
378
379
379
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_TYPE_HIERARCHY , ( location : any ) => {
380
- if ( location instanceof Uri ) {
381
- typeHierarchyTree . setTypeHierarchy ( new Location ( location , window . activeTextEditor . selection . active ) , TypeHierarchyDirection . both ) ;
382
- } else {
383
- if ( window . activeTextEditor ?. document ?. languageId !== "java" ) {
384
- return ;
380
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY , async ( anchor : any ) => {
381
+ try {
382
+ if ( anchor instanceof Uri ) { // comes from context menu
383
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor , window . activeTextEditor . selection . active ) ) ;
384
+ } else if ( anchor instanceof TypeHierarchyItem ) { // comes from class hierarchy view item
385
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor . uri , anchor . range . start ) ) ;
386
+ } else { // comes from command palette
387
+ if ( window . activeTextEditor ?. document ?. languageId !== "java" ) {
388
+ return ;
389
+ }
390
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( window . activeTextEditor . document . uri , window . activeTextEditor . selection . active ) ) ;
391
+ }
392
+ } catch ( e ) {
393
+ if ( e ?. message ) {
394
+ // show message in the selection when call from editor context menu
395
+ if ( anchor instanceof Uri ) {
396
+ showNoLocationFound ( e . message ) ;
397
+ } else {
398
+ window . showErrorMessage ( e . message ) ;
399
+ }
385
400
}
386
- typeHierarchyTree . setTypeHierarchy ( new Location ( window . activeTextEditor . document . uri , window . activeTextEditor . selection . active ) , TypeHierarchyDirection . both ) ;
387
401
}
388
402
} ) ) ;
389
403
390
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY , ( ) => {
391
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . both ) ;
392
- } ) ) ;
393
-
394
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUPERTYPE_HIERARCHY , ( ) => {
395
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . parents ) ;
404
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY_FROM_REFERENCE_VIEW , async ( anchor ?: any ) => {
405
+ try {
406
+ if ( ! anchor ) { // comes from reference-view's title or command palette
407
+ await typeHierarchyTree . setTypeHierarchyFromReferenceView ( ) ;
408
+ } else if ( anchor . item instanceof TypeHierarchyItem ) { // comes from reference-view's item
409
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor . item . uri , anchor . item . range . start ) ) ;
410
+ }
411
+ } catch ( e ) {
412
+ if ( e ?. message ) {
413
+ window . showErrorMessage ( e . message ) ;
414
+ }
415
+ }
396
416
} ) ) ;
397
417
398
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUBTYPE_HIERARCHY , ( ) => {
399
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . children ) ;
418
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUPERTYPE_HIERARCHY , async ( anchor ?: any ) => {
419
+ let location : Location ;
420
+ if ( ! anchor ) {
421
+ location = typeHierarchyTree . getAnchor ( ) ;
422
+ } else if ( anchor instanceof TypeHierarchyItem ) {
423
+ location = new Location ( anchor . uri , anchor . range . start ) ;
424
+ }
425
+ if ( location ) {
426
+ await commands . executeCommand ( showTypeHierarchyReferenceViewCommand ) ;
427
+ await commands . executeCommand ( showSupertypeHierarchyReferenceViewCommand , location ) ;
428
+ }
400
429
} ) ) ;
401
430
402
- context . subscriptions . push ( commands . registerCommand ( Commands . CHANGE_BASE_TYPE , async ( item : TypeHierarchyItem ) => {
403
- typeHierarchyTree . changeBaseItem ( item ) ;
431
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUBTYPE_HIERARCHY , async ( anchor ?: any ) => {
432
+ let location : Location ;
433
+ if ( ! anchor ) {
434
+ location = typeHierarchyTree . getAnchor ( ) ;
435
+ } else if ( anchor instanceof TypeHierarchyItem ) {
436
+ location = new Location ( anchor . uri , anchor . range . start ) ;
437
+ }
438
+ if ( location ) {
439
+ await commands . executeCommand ( showTypeHierarchyReferenceViewCommand ) ;
440
+ await commands . executeCommand ( showSubtypeHierarchyReferenceViewCommand , location ) ;
441
+ }
404
442
} ) ) ;
405
443
406
444
context . subscriptions . push ( commands . registerCommand ( Commands . BUILD_PROJECT , async ( uris : Uri [ ] | Uri , isFullBuild : boolean , token : CancellationToken ) => {
0 commit comments