-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to view inherited members #2342
The reference view API is used to show the document outline with inherited symbols using the new java.ls extension method. Signed-off-by: Gayan Perera <[email protected]>
- Loading branch information
Showing
8 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { LanguageClient } from "vscode-languageclient/node"; | ||
import { SymbolTree } from "../typeHierarchy/references-view"; | ||
import * as vscode from "vscode"; | ||
import { getActiveLanguageClient } from "../extension"; | ||
import { ExtendedOutlineTreeInput } from "./model"; | ||
|
||
export class ExtendedOutlineTree { | ||
private api: SymbolTree; | ||
private client: LanguageClient; | ||
public initialized: boolean; | ||
|
||
constructor() { | ||
this.initialized = false; | ||
} | ||
|
||
async initialize() { | ||
// It uses a new publisher id in June 2022 Update, check both old/new id for compatibility | ||
// See https://github.com/microsoft/vscode/pull/152213 | ||
const referencesViewExt = vscode.extensions.getExtension<SymbolTree>('vscode.references-view') | ||
?? vscode.extensions.getExtension<SymbolTree>('ms-vscode.references-view'); | ||
this.api = await referencesViewExt?.activate(); | ||
this.client = await getActiveLanguageClient(); | ||
this.initialized = true; | ||
} | ||
|
||
async open(uri: vscode.Uri) { | ||
if (!this.initialized) { | ||
await this.initialize(); | ||
} | ||
|
||
if (!this.api) { | ||
return; | ||
} | ||
const input: ExtendedOutlineTreeInput = new ExtendedOutlineTreeInput(new vscode.Location(uri, new vscode.Position(0, 0))); | ||
this.api.setInput(input); | ||
} | ||
} | ||
|
||
export const extendedOutlineTree: ExtendedOutlineTree = new ExtendedOutlineTree(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { DocumentSymbol, Event, Location, Position, ProviderResult, Range, SymbolKind, TextDocumentShowOptions, TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri } from "vscode"; | ||
import { DocumentSymbolParams, LanguageClient, TextDocumentIdentifier } from "vscode-languageclient/node"; | ||
import { getActiveLanguageClient } from "../extension"; | ||
import { getThemeIcon } from "../themeUtils"; | ||
import { SymbolItemNavigation, SymbolTreeInput, SymbolTreeModel } from "../typeHierarchy/references-view"; | ||
import { ExtendedDocumentSymbol, ExtendedDocumentSymbolsRequest } from "./protocol"; | ||
|
||
export class ExtendedOutlineTreeInput implements SymbolTreeInput<ExtendedDocumentSymbol> { | ||
readonly contextValue: string = "javaExtendedOutline"; | ||
readonly title: string = "Extended Outline"; | ||
client: LanguageClient; | ||
|
||
constructor(readonly location: Location) { | ||
} | ||
|
||
async resolve(): Promise<SymbolTreeModel<ExtendedDocumentSymbol>> { | ||
if (!this.client) { | ||
this.client = await getActiveLanguageClient(); | ||
} | ||
|
||
const params: DocumentSymbolParams = { | ||
textDocument: TextDocumentIdentifier.create(this.location.uri.toString()) | ||
}; | ||
const symbols = await this.client.sendRequest(ExtendedDocumentSymbolsRequest.type, params); | ||
const treeModel: SymbolTreeModel<ExtendedDocumentSymbol> = { | ||
provider: new ExtendedOutlineProvider(symbols, this.client), | ||
message: undefined, | ||
navigation: new ExtendedOutlineModel() | ||
}; | ||
return Promise.resolve(treeModel); | ||
} | ||
|
||
with(location: Location): SymbolTreeInput<ExtendedDocumentSymbol> { | ||
return new ExtendedOutlineTreeInput(location); | ||
} | ||
} | ||
|
||
export class ExtendedOutlineModel implements SymbolItemNavigation<ExtendedDocumentSymbol> { | ||
nearest(_uri: Uri, _position: Position): ExtendedDocumentSymbol | undefined { | ||
return undefined; | ||
} | ||
|
||
next(from: ExtendedDocumentSymbol): ExtendedDocumentSymbol { | ||
return from; | ||
} | ||
previous(from: ExtendedDocumentSymbol): ExtendedDocumentSymbol { | ||
return from; | ||
} | ||
location(item: ExtendedDocumentSymbol): Location { | ||
return new Location(Uri.parse(item.uri), new Range(item.range.start, item.range.end)); | ||
} | ||
|
||
} | ||
|
||
class ExtendedOutlineProvider implements TreeDataProvider<ExtendedDocumentSymbol> { | ||
onDidChangeTreeData?: Event<void | ExtendedDocumentSymbol>; | ||
|
||
constructor(readonly symbols: ExtendedDocumentSymbol[], readonly client: LanguageClient) { } | ||
|
||
getTreeItem(element: ExtendedDocumentSymbol): TreeItem | Thenable<TreeItem> { | ||
let state = TreeItemCollapsibleState.None; | ||
if (element.children != null && element.children.length > 0) | ||
state = TreeItemCollapsibleState.Collapsed; | ||
|
||
const item: TreeItem = new TreeItem(element.name, state); | ||
item.description = element.detail; | ||
item.iconPath = getThemeIcon(element.kind - 1); | ||
item.command = (element.uri) ? { | ||
command: 'vscode.open', | ||
title: 'Open Symbol Definition Location', | ||
arguments: [ | ||
element.uri, <TextDocumentShowOptions>{ selection: element.selectionRange } | ||
] | ||
} : undefined; | ||
return item; | ||
} | ||
|
||
getChildren(element?: ExtendedDocumentSymbol): ProviderResult<ExtendedDocumentSymbol[]> { | ||
if (element == null) { | ||
return Promise.resolve(this.symbols); | ||
} else { | ||
if (element.children != null) { | ||
return Promise.resolve(element.children as ExtendedDocumentSymbol[]); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
getParent?(_element: ExtendedDocumentSymbol): ProviderResult<ExtendedDocumentSymbol> { | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DocumentSymbol, DocumentSymbolParams, RequestType } from "vscode-languageclient"; | ||
|
||
export namespace ExtendedDocumentSymbolsRequest { | ||
export const type = new RequestType<DocumentSymbolParams, ExtendedDocumentSymbol[], void>('java/extendedDocumentSymbols'); | ||
} | ||
|
||
export interface ExtendedDocumentSymbol extends DocumentSymbol { | ||
uri: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { SymbolKind, ThemeIcon } from "vscode"; | ||
|
||
const themeIconIds = [ | ||
'symbol-file', 'symbol-module', 'symbol-namespace', 'symbol-package', 'symbol-class', 'symbol-method', | ||
'symbol-property', 'symbol-field', 'symbol-constructor', 'symbol-enum', 'symbol-interface', | ||
'symbol-function', 'symbol-variable', 'symbol-constant', 'symbol-string', 'symbol-number', 'symbol-boolean', | ||
'symbol-array', 'symbol-object', 'symbol-key', 'symbol-null', 'symbol-enum-member', 'symbol-struct', | ||
'symbol-event', 'symbol-operator', 'symbol-type-parameter' | ||
]; | ||
|
||
export function getThemeIcon(kind: SymbolKind): ThemeIcon | undefined { | ||
const id = themeIconIds[kind]; | ||
return id ? new ThemeIcon(id) : undefined; | ||
} | ||
|