-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support viewing inherited members through QuickPick UI.
- The QuickPick view API is used to show the document outline with inherited symbols using the new language server extension method, 'java/extendedDocumentSymbol'. - When ctrl+o is activated from the quick-pick menu (eg. the outline view is already active), the extended outline is then activated Co-Authored-by: Gayan Perera <[email protected]> Co-Authored-by: Roland Grunberg <[email protected]>
- Loading branch information
Showing
8 changed files
with
143 additions
and
17 deletions.
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,81 @@ | ||
import { DocumentSymbolParams, LanguageClient, TextDocumentIdentifier } from "vscode-languageclient/node"; | ||
import { getActiveLanguageClient } from "../extension"; | ||
import { ExtendedDocumentSymbolRequest } from "./protocol"; | ||
import { Location, Position, QuickPick, QuickPickItem, Uri, window, workspace } from "vscode"; | ||
import { getLThemeIcon } from "../themeUtils"; | ||
|
||
export class ExtendedOutlineQuickPick { | ||
private api: QuickPick<QuickPickItem>; | ||
private client: LanguageClient; | ||
public initialized: boolean; | ||
|
||
constructor() { | ||
this.initialized = false; | ||
} | ||
|
||
async initialize() { | ||
this.api = window.createQuickPick(); | ||
this.api.ignoreFocusOut = true; | ||
this.api.onDidChangeActive((items: QuickPickItem[]) => { | ||
if (items.length > 0) { | ||
const active: QuickPickItem = items[0]; | ||
const uri = active["uri"]; | ||
const range = active["range"]; | ||
if (uri !== undefined) { | ||
workspace.openTextDocument(Uri.parse(uri)).then(doc => { | ||
window.showTextDocument(doc, {preserveFocus: true, selection: range}); | ||
}); | ||
} else { | ||
window.showTextDocument(window.activeTextEditor.document, {preserveFocus: true, selection: range}); | ||
} | ||
} | ||
}); | ||
this.api.onDidAccept(() => { | ||
this.api.hide(); | ||
}); | ||
this.client = await getActiveLanguageClient(); | ||
this.initialized = true; | ||
} | ||
|
||
async open(uri: Uri) { | ||
if (!this.initialized) { | ||
await this.initialize(); | ||
} | ||
|
||
if (!this.api) { | ||
return; | ||
} | ||
|
||
const location = new Location(uri, new Position(0, 0)); | ||
const params: DocumentSymbolParams = { | ||
textDocument: TextDocumentIdentifier.create(location.uri.toString()) | ||
}; | ||
const symbols = await this.client.sendRequest(ExtendedDocumentSymbolRequest.type, params); | ||
let quickPickItems: QuickPickItem[] = []; | ||
for (const s of symbols) { | ||
const icon = getLThemeIcon(s.kind).id; | ||
const item = { | ||
label: `$(${icon}) ${s.name}`, | ||
description: s.detail.trim(), | ||
uri: s.uri, | ||
range: s.range | ||
}; | ||
quickPickItems.push(item); | ||
if (icon === 'symbol-class') { | ||
const items: QuickPickItem[] = s.children.map(s => ({ | ||
label: `$(${getLThemeIcon(s.kind).id}) ${s.name}`, | ||
// custom quick pick has automatic space between label & description | ||
description: s.detail.trim(), | ||
uri: s.uri, | ||
range: s.range | ||
})); | ||
quickPickItems = quickPickItems.concat(items); | ||
} | ||
} | ||
this.api.items = quickPickItems; | ||
this.api.activeItems = []; | ||
this.api.show(); | ||
} | ||
} | ||
|
||
export const extendedOutlineQuickPick: ExtendedOutlineQuickPick = new ExtendedOutlineQuickPick(); |
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,10 @@ | ||
import { DocumentSymbol, DocumentSymbolParams, RequestType } from "vscode-languageclient"; | ||
|
||
export namespace ExtendedDocumentSymbolRequest { | ||
export const type = new RequestType<DocumentSymbolParams, ExtendedDocumentSymbol[], void>('java/extendedDocumentSymbol'); | ||
} | ||
|
||
export interface ExtendedDocumentSymbol extends DocumentSymbol { | ||
uri: string; | ||
children?: ExtendedDocumentSymbol[]; | ||
} |
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,20 @@ | ||
import { SymbolKind as VSymbolKind, ThemeIcon } from "vscode"; | ||
import { SymbolKind as LSymbolKind} from "vscode-languageclient"; | ||
|
||
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 getLThemeIcon(kind: LSymbolKind): ThemeIcon | undefined { | ||
const id = themeIconIds[kind - 1]; | ||
return id ? new ThemeIcon(id) : undefined; | ||
} | ||
|
||
export function getThemeIcon(kind: VSymbolKind): ThemeIcon | undefined { | ||
const id = themeIconIds[kind]; | ||
return id ? new ThemeIcon(id) : 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