@@ -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
@@ -105,7 +106,7 @@ export class StandardLanguageClient {
105
106
106
107
// Create the language client and start the client.
107
108
this . languageClient = new TracingLanguageClient ( 'java' , extensionName , serverOptions , clientOptions ) ;
108
-
109
+ this . languageClient . registerFeature ( new TypeHierarchyFeature ( this . languageClient ) ) ;
109
110
this . registerCommandsForStandardServer ( context , jdtEventEmitter ) ;
110
111
fileEventHandler . registerFileEventHandlers ( this . languageClient , context ) ;
111
112
@@ -364,31 +365,68 @@ export class StandardLanguageClient {
364
365
}
365
366
} ) ) ;
366
367
367
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_TYPE_HIERARCHY , ( location : any ) => {
368
- if ( location instanceof Uri ) {
369
- typeHierarchyTree . setTypeHierarchy ( new Location ( location , window . activeTextEditor . selection . active ) , TypeHierarchyDirection . both ) ;
370
- } else {
371
- if ( window . activeTextEditor ?. document ?. languageId !== "java" ) {
372
- return ;
368
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY , async ( anchor : any ) => {
369
+ try {
370
+ if ( anchor instanceof Uri ) { // comes from context menu
371
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor , window . activeTextEditor . selection . active ) ) ;
372
+ } else if ( anchor instanceof TypeHierarchyItem ) { // comes from class hierarchy view item
373
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor . uri , anchor . range . start ) ) ;
374
+ } else { // comes from command palette
375
+ if ( window . activeTextEditor ?. document ?. languageId !== "java" ) {
376
+ return ;
377
+ }
378
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( window . activeTextEditor . document . uri , window . activeTextEditor . selection . active ) ) ;
379
+ }
380
+ } catch ( e ) {
381
+ if ( e ?. message ) {
382
+ // show message in the selection when call from editor context menu
383
+ if ( anchor instanceof Uri ) {
384
+ showNoLocationFound ( e . message ) ;
385
+ } else {
386
+ window . showErrorMessage ( e . message ) ;
387
+ }
373
388
}
374
- typeHierarchyTree . setTypeHierarchy ( new Location ( window . activeTextEditor . document . uri , window . activeTextEditor . selection . active ) , TypeHierarchyDirection . both ) ;
375
389
}
376
390
} ) ) ;
377
391
378
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY , ( ) => {
379
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . both ) ;
380
- } ) ) ;
381
-
382
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUPERTYPE_HIERARCHY , ( ) => {
383
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . parents ) ;
392
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_CLASS_HIERARCHY_FROM_REFERENCE_VIEW , async ( anchor ?: any ) => {
393
+ try {
394
+ if ( ! anchor ) { // comes from reference-view's title or command palette
395
+ await typeHierarchyTree . setTypeHierarchyFromReferenceView ( ) ;
396
+ } else if ( anchor . item instanceof TypeHierarchyItem ) { // comes from reference-view's item
397
+ await typeHierarchyTree . setTypeHierarchy ( new Location ( anchor . item . uri , anchor . item . range . start ) ) ;
398
+ }
399
+ } catch ( e ) {
400
+ if ( e ?. message ) {
401
+ window . showErrorMessage ( e . message ) ;
402
+ }
403
+ }
384
404
} ) ) ;
385
405
386
- context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUBTYPE_HIERARCHY , ( ) => {
387
- typeHierarchyTree . changeDirection ( TypeHierarchyDirection . children ) ;
406
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUPERTYPE_HIERARCHY , async ( anchor ?: any ) => {
407
+ let location : Location ;
408
+ if ( ! anchor ) {
409
+ location = typeHierarchyTree . getAnchor ( ) ;
410
+ } else if ( anchor instanceof TypeHierarchyItem ) {
411
+ location = new Location ( anchor . uri , anchor . range . start ) ;
412
+ }
413
+ if ( location ) {
414
+ await commands . executeCommand ( showTypeHierarchyReferenceViewCommand ) ;
415
+ await commands . executeCommand ( showSupertypeHierarchyReferenceViewCommand , location ) ;
416
+ }
388
417
} ) ) ;
389
418
390
- context . subscriptions . push ( commands . registerCommand ( Commands . CHANGE_BASE_TYPE , async ( item : TypeHierarchyItem ) => {
391
- typeHierarchyTree . changeBaseItem ( item ) ;
419
+ context . subscriptions . push ( commands . registerCommand ( Commands . SHOW_SUBTYPE_HIERARCHY , async ( anchor ?: any ) => {
420
+ let location : Location ;
421
+ if ( ! anchor ) {
422
+ location = typeHierarchyTree . getAnchor ( ) ;
423
+ } else if ( anchor instanceof TypeHierarchyItem ) {
424
+ location = new Location ( anchor . uri , anchor . range . start ) ;
425
+ }
426
+ if ( location ) {
427
+ await commands . executeCommand ( showTypeHierarchyReferenceViewCommand ) ;
428
+ await commands . executeCommand ( showSubtypeHierarchyReferenceViewCommand , location ) ;
429
+ }
392
430
} ) ) ;
393
431
394
432
context . subscriptions . push ( commands . registerCommand ( Commands . BUILD_PROJECT , async ( uris : Uri [ ] | Uri , isFullBuild : boolean , token : CancellationToken ) => {
0 commit comments