mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
commit
836c19717b
3 changed files with 16 additions and 24 deletions
|
|
@ -873,39 +873,31 @@ export class OutlineAdapter extends Adapter implements languages.DocumentSymbolP
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = await worker.getNavigationBarItems(resource.toString());
|
const root = await worker.getNavigationTree(resource.toString());
|
||||||
|
|
||||||
if (!items || model.isDisposed()) {
|
if (!root || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const convert = (
|
const convert = (
|
||||||
bucket: languages.DocumentSymbol[],
|
item: ts.NavigationTree,
|
||||||
item: ts.NavigationBarItem,
|
|
||||||
containerLabel?: string
|
containerLabel?: string
|
||||||
): void => {
|
): languages.DocumentSymbol => {
|
||||||
let result: languages.DocumentSymbol = {
|
const result: languages.DocumentSymbol = {
|
||||||
name: item.text,
|
name: item.text,
|
||||||
detail: '',
|
detail: '',
|
||||||
kind: <languages.SymbolKind>(outlineTypeTable[item.kind] || languages.SymbolKind.Variable),
|
kind: <languages.SymbolKind>(outlineTypeTable[item.kind] || languages.SymbolKind.Variable),
|
||||||
range: this._textSpanToRange(model, item.spans[0]),
|
range: this._textSpanToRange(model, item.spans[0]),
|
||||||
selectionRange: 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
|
||||||
};
|
};
|
||||||
|
return result;
|
||||||
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let result: languages.DocumentSymbol[] = [];
|
// Exclude the root node, as it alwas spans the entire document.
|
||||||
items.forEach((item) => convert(result, item));
|
const result = root.childItems ? root.childItems.map((item) => convert(item)) : [];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -463,9 +463,9 @@ export interface TypeScriptWorker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get outline entries for the item at the given position in the file.
|
* Get outline entries for the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.NavigationBarItem[]>`
|
* @returns `Promise<typescript.NavigationTree | undefined>`
|
||||||
*/
|
*/
|
||||||
getNavigationBarItems(fileName: string): Promise<any[]>;
|
getNavigationTree(fileName: string): Promise<any | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get changes which should be applied to format the given file.
|
* Get changes which should be applied to format the given file.
|
||||||
|
|
|
||||||
|
|
@ -330,11 +330,11 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
|
||||||
return this._languageService.getReferencesAtPosition(fileName, position);
|
return this._languageService.getReferencesAtPosition(fileName, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNavigationBarItems(fileName: string): Promise<ts.NavigationBarItem[]> {
|
async getNavigationTree(fileName: string): Promise<ts.NavigationTree | undefined> {
|
||||||
if (fileNameIsLib(fileName)) {
|
if (fileNameIsLib(fileName)) {
|
||||||
return [];
|
return undefined;
|
||||||
}
|
}
|
||||||
return this._languageService.getNavigationBarItems(fileName);
|
return this._languageService.getNavigationTree(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFormattingEditsForDocument(
|
async getFormattingEditsForDocument(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue