From 5b9f89146a651cb8eef410820fbb348013c8816c Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Thu, 2 Mar 2023 12:55:56 +0100 Subject: [PATCH] Fixes #3565 --- src/language/typescript/languageFeatures.ts | 30 +++++++------------ .../typescript/monaco.contribution.ts | 4 +-- src/language/typescript/tsWorker.ts | 6 ++-- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/language/typescript/languageFeatures.ts b/src/language/typescript/languageFeatures.ts index 15b0e7fe..b8cf5e2f 100644 --- a/src/language/typescript/languageFeatures.ts +++ b/src/language/typescript/languageFeatures.ts @@ -865,39 +865,31 @@ export class OutlineAdapter extends Adapter implements languages.DocumentSymbolP return; } - const items = await worker.getNavigationBarItems(resource.toString()); + const root = await worker.getNavigationTree(resource.toString()); - if (!items || model.isDisposed()) { + if (!root || model.isDisposed()) { return; } const convert = ( - bucket: languages.DocumentSymbol[], - item: ts.NavigationBarItem, + item: ts.NavigationTree, containerLabel?: string - ): void => { - let result: languages.DocumentSymbol = { + ): languages.DocumentSymbol => { + const result: languages.DocumentSymbol = { name: item.text, detail: '', kind: (outlineTypeTable[item.kind] || languages.SymbolKind.Variable), range: this._textSpanToRange(model, item.spans[0]), selectionRange: this._textSpanToRange(model, item.spans[0]), - tags: [] + tags: [], + children: item.childItems?.map((child) => convert(child, result.name)), + containerName: containerLabel }; - - if (containerLabel) result.containerName = containerLabel; - - if (item.childItems && item.childItems.length > 0) { - for (let child of item.childItems) { - convert(bucket, child, result.name); - } - } - - bucket.push(result); + return result; }; - let result: languages.DocumentSymbol[] = []; - items.forEach((item) => convert(result, item)); + // Exclude the root node, as it alwas spans the entire document. + const result = root.childItems ? root.childItems.map((item) => convert(item)) : []; return result; } } diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index 9b6a6ae8..f1a985bb 100644 --- a/src/language/typescript/monaco.contribution.ts +++ b/src/language/typescript/monaco.contribution.ts @@ -466,9 +466,9 @@ export interface TypeScriptWorker { /** * Get outline entries for the item at the given position in the file. - * @returns `Promise` + * @returns `Promise` */ - getNavigationBarItems(fileName: string): Promise; + getNavigationTree(fileName: string): Promise; /** * Get changes which should be applied to format the given file. diff --git a/src/language/typescript/tsWorker.ts b/src/language/typescript/tsWorker.ts index 65601f84..783c8e5c 100644 --- a/src/language/typescript/tsWorker.ts +++ b/src/language/typescript/tsWorker.ts @@ -329,11 +329,11 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork return this._languageService.getReferencesAtPosition(fileName, position); } - async getNavigationBarItems(fileName: string): Promise { + async getNavigationTree(fileName: string): Promise { if (fileNameIsLib(fileName)) { - return []; + return undefined; } - return this._languageService.getNavigationBarItems(fileName); + return this._languageService.getNavigationTree(fileName); } async getFormattingEditsForDocument(