mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Change JSON symbol information to document symbol
This commit is contained in:
parent
20a8d5a651
commit
858b03fd8a
2 changed files with 36 additions and 13 deletions
|
|
@ -651,7 +651,7 @@ function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit | null): languages.Workspac
|
||||||
//#region DocumentSymbolAdapter
|
//#region DocumentSymbolAdapter
|
||||||
|
|
||||||
export interface ILanguageWorkerWithDocumentSymbols {
|
export interface ILanguageWorkerWithDocumentSymbols {
|
||||||
findDocumentSymbols(uri: string): Promise<lsTypes.SymbolInformation[]>;
|
findDocumentSymbols(uri: string): Promise<lsTypes.SymbolInformation[] | lsTypes.DocumentSymbol[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DocumentSymbolAdapter<T extends ILanguageWorkerWithDocumentSymbols>
|
export class DocumentSymbolAdapter<T extends ILanguageWorkerWithDocumentSymbols>
|
||||||
|
|
@ -671,25 +671,48 @@ export class DocumentSymbolAdapter<T extends ILanguageWorkerWithDocumentSymbols>
|
||||||
if (!items) {
|
if (!items) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return items.map((item) => ({
|
return items.map((item) => {
|
||||||
name: item.name,
|
if (isDocumentSymbol(item)) {
|
||||||
detail: '',
|
return toDocumentSymbol(item);
|
||||||
containerName: item.containerName,
|
}
|
||||||
kind: toSymbolKind(item.kind),
|
return {
|
||||||
range: toRange(item.location.range),
|
name: item.name,
|
||||||
selectionRange: toRange(item.location.range),
|
detail: '',
|
||||||
tags: []
|
containerName: item.containerName,
|
||||||
}));
|
kind: toSymbolKind(item.kind),
|
||||||
|
range: toRange(item.location.range),
|
||||||
|
selectionRange: toRange(item.location.range),
|
||||||
|
tags: []
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDocumentSymbol(
|
||||||
|
symbol: lsTypes.SymbolInformation | lsTypes.DocumentSymbol
|
||||||
|
): symbol is lsTypes.DocumentSymbol {
|
||||||
|
return 'children' in symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDocumentSymbol(symbol: lsTypes.DocumentSymbol): languages.DocumentSymbol {
|
||||||
|
return {
|
||||||
|
name: symbol.name,
|
||||||
|
detail: symbol.detail ?? '',
|
||||||
|
kind: toSymbolKind(symbol.kind),
|
||||||
|
range: toRange(symbol.range),
|
||||||
|
selectionRange: toRange(symbol.selectionRange),
|
||||||
|
tags: symbol.tags ?? [],
|
||||||
|
children: (symbol.children ?? []).map((item) => toDocumentSymbol(item))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
|
function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
|
||||||
let mKind = languages.SymbolKind;
|
let mKind = languages.SymbolKind;
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case lsTypes.SymbolKind.File:
|
case lsTypes.SymbolKind.File:
|
||||||
return mKind.Array;
|
return mKind.File;
|
||||||
case lsTypes.SymbolKind.Module:
|
case lsTypes.SymbolKind.Module:
|
||||||
return mKind.Module;
|
return mKind.Module;
|
||||||
case lsTypes.SymbolKind.Namespace:
|
case lsTypes.SymbolKind.Namespace:
|
||||||
|
|
|
||||||
|
|
@ -82,13 +82,13 @@ export class JSONWorker {
|
||||||
async resetSchema(uri: string): Promise<boolean> {
|
async resetSchema(uri: string): Promise<boolean> {
|
||||||
return Promise.resolve(this._languageService.resetSchema(uri));
|
return Promise.resolve(this._languageService.resetSchema(uri));
|
||||||
}
|
}
|
||||||
async findDocumentSymbols(uri: string): Promise<jsonService.SymbolInformation[]> {
|
async findDocumentSymbols(uri: string): Promise<jsonService.DocumentSymbol[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
if (!document) {
|
if (!document) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let symbols = this._languageService.findDocumentSymbols(document, jsonDocument);
|
let symbols = this._languageService.findDocumentSymbols2(document, jsonDocument);
|
||||||
return Promise.resolve(symbols);
|
return Promise.resolve(symbols);
|
||||||
}
|
}
|
||||||
async findDocumentColors(uri: string): Promise<jsonService.ColorInformation[]> {
|
async findDocumentColors(uri: string): Promise<jsonService.ColorInformation[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue