提交 87481145 编写于 作者: J Johannes Rieken

debt - quick outline using the same model cache as breadcrumbs and outline tree

上级 5458ae72
......@@ -3,44 +3,41 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { illegalArgument, onUnexpectedExternalError } from 'vs/base/common/errors';
import { illegalArgument } from 'vs/base/common/errors';
import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { registerLanguageCommand } from 'vs/editor/browser/editorExtensions';
import { DocumentSymbol, DocumentSymbolProviderRegistry } from 'vs/editor/common/modes';
import { DocumentSymbol } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { OutlineModel, OutlineElement } from 'vs/editor/contrib/documentSymbols/outlineModel';
import { values } from 'vs/base/common/collections';
export function getDocumentSymbols(model: ITextModel, flat: boolean, token: CancellationToken): Promise<DocumentSymbol[]> {
export async function getDocumentSymbols(document: ITextModel, flat: boolean, token: CancellationToken): Promise<DocumentSymbol[]> {
let roots: DocumentSymbol[] = [];
let promises = DocumentSymbolProviderRegistry.all(model).map(support => {
return Promise.resolve(support.provideDocumentSymbols(model, token)).then(result => {
if (Array.isArray(result)) {
roots.push(...result);
}
}, err => {
onUnexpectedExternalError(err);
});
});
return Promise.all(promises).then(() => {
let flatEntries: DocumentSymbol[] = [];
if (token.isCancellationRequested) {
return flatEntries;
}
if (flat) {
flatten(flatEntries, roots, '');
const model = await OutlineModel.create(document, token);
const roots: DocumentSymbol[] = [];
for (const child of values(model.children)) {
if (child instanceof OutlineElement) {
roots.push(child.symbol);
} else {
flatEntries = roots;
roots.push(...values(child.children).map(child => child.symbol));
}
flatEntries.sort(compareEntriesUsingStart);
}
let flatEntries: DocumentSymbol[] = [];
if (token.isCancellationRequested) {
return flatEntries;
});
}
if (flat) {
flatten(flatEntries, roots, '');
} else {
flatEntries = roots;
}
return flatEntries.sort(compareEntriesUsingStart);
}
function compareEntriesUsingStart(a: DocumentSymbol, b: DocumentSymbol): number {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册