move the logic of getOutlineEntries into one place

This commit is contained in:
Johannes Rieken
2015-11-25 11:00:40 +01:00
parent 1ef99fc702
commit 6ea319fa68
4 changed files with 75 additions and 43 deletions

View File

@@ -27,7 +27,7 @@ import ExtraInfoRegistry from 'vs/editor/contrib/hover/common/hover';
import DocumentHighlighterRegistry from 'vs/editor/contrib/wordHighlighter/common/wordHighlighter';
import ReferenceSearchRegistry from 'vs/editor/contrib/referenceSearch/common/referenceSearch';
import QuickFixRegistry from 'vs/editor/contrib/quickFix/common/quickFix';
import QuickOutlineRegistry, {IOutlineEntry, IOutlineSupport} from 'vs/editor/contrib/quickOpen/common/quickOpen';
import {OutlineRegistry, IOutlineEntry, IOutlineSupport} from 'vs/editor/contrib/quickOpen/common/quickOpen';
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
import {NavigateTypesSupportRegistry, INavigateTypesSupport, ITypeBearing} from 'vs/workbench/parts/search/common/search'
import {RenameRegistry} from 'vs/editor/contrib/rename/common/rename';
@@ -544,7 +544,7 @@ export class ExtensionHostDocumentSymbols extends AbstractExtensionHostFeature<v
export class MainThreadDocumentSymbols extends AbstractMainThreadFeature<IOutlineSupport> implements IOutlineSupport {
constructor( @IThreadService threadService: IThreadService) {
super('vscode.executeDocumentSymbolProvider', QuickOutlineRegistry, threadService);
super('vscode.executeDocumentSymbolProvider', OutlineRegistry, threadService);
}
getOutline(resource: URI): TPromise<IOutlineEntry[]>{
@@ -1262,7 +1262,7 @@ export namespace LanguageFeatures {
threadService.getRemotable(MainThreadReferenceSearch);
threadService.getRemotable(MainThreadCodeActions);
threadService.getRemotable(MainThreadCodeLens);
threadService.getRemotable(MainThreadDocumentSymbols);
// threadService.getRemotable(MainThreadDocumentSymbols);
threadService.getRemotable(MainThreadWorkspaceSymbols);
threadService.getRemotable(MainThreadRename);
threadService.getRemotable(MainThreadFormatDocument);
@@ -1280,7 +1280,7 @@ export namespace LanguageFeatures {
referenceSearch: new ExtensionHostReferenceSearch(threadService),
codeActions: new ExtensionHostCodeActions(threadService),
codeLens: threadService.getRemotable(ExtensionHostCodeLens),
documentSymbols: new ExtensionHostDocumentSymbols(threadService),
// documentSymbols: new ExtensionHostDocumentSymbols(threadService),
workspaceSymbols: new ExtensionHostWorkspaceSymbols(threadService),
rename: new ExtensionHostRename(threadService),
formatDocument: new ExtHostFormatDocument(threadService),

View File

@@ -31,7 +31,7 @@ import {IQuickOpenService} from 'vs/workbench/services/quickopen/browser/quickOp
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {Position} from 'vs/platform/editor/common/editor';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import QuickOpenRegistry from 'vs/editor/contrib/quickOpen/common/quickOpen';
import {OutlineRegistry, getOutlineEntries} from 'vs/editor/contrib/quickOpen/common/quickOpen';
const ACTION_ID = 'workbench.action.gotoSymbol';
const ACTION_LABEL = nls.localize('gotoSymbol', "Go to Symbol...");
@@ -432,7 +432,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
if (model && types.isFunction((<ITokenizedModel>model).getMode)) {
canRun = QuickOpenRegistry.has(<IModel> model);
canRun = OutlineRegistry.has(<IModel> model);
}
}
@@ -527,34 +527,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
return TPromise.as(this.outlineToModelCache[modelId]);
}
let groupLabels: { [n: string]: string } = Object.create(null);
let entries: IOutlineEntry[] = [];
let resource = (<IModel>model).getAssociatedResource();
let promises = QuickOpenRegistry.all(<IModel>model).map(support => {
if (support.outlineGroupLabel) {
for (var key in support.outlineGroupLabel) {
if (Object.prototype.hasOwnProperty.call(support.outlineGroupLabel, key)) {
groupLabels[key] = support.outlineGroupLabel[key];
}
}
}
return support.getOutline(resource).then(result => {
if (Array.isArray(result)) {
entries.push(...result);
}
}, err => {
errors.onUnexpectedError(err);
});
});
return TPromise.join(promises).then(() => {
let outline = {
entries,
outlineGroupLabel: groupLabels
};
return getOutlineEntries(<IModel>model).then(outline => {
let model = new OutlineModel(outline, this.toQuickOpenEntries(outline));

View File

@@ -18,7 +18,7 @@ import * as LF from 'vs/workbench/api/common/languageFeatures';
import {PluginHostCommands, MainThreadCommands} from 'vs/workbench/api/common/pluginHostCommands';
import {PluginHostModelService} from 'vs/workbench/api/common/pluginHostDocuments';
import {SyncDescriptor0} from 'vs/platform/instantiation/common/descriptors';
import QuickOutlineRegistry from 'vs/editor/contrib/quickOpen/common/quickOpen';
import {OutlineRegistry} from 'vs/editor/contrib/quickOpen/common/quickOpen';
import {LanguageSelector, ModelLike} from 'vs/editor/common/modes/languageSelector';
class ThreadService extends NullThreadService {
@@ -85,17 +85,17 @@ suite('ExtHostLanguageFeatures', function() {
// register
assert.equal(QuickOutlineRegistry.all(model).length, 0);
assert.equal(OutlineRegistry.all(model).length, 0);
let disposable = extHost.register('far', {
provideDocumentSymbols() {
return [];
}
});
assert.equal(QuickOutlineRegistry.all(model).length, 1);
assert.equal(OutlineRegistry.all(model).length, 1);
// deregister
disposable.dispose();
assert.equal(QuickOutlineRegistry.all(model).length, 0);
assert.equal(OutlineRegistry.all(model).length, 0);
// all extension host provider appear as one
disposable = extHost.register('far', {
@@ -108,12 +108,12 @@ suite('ExtHostLanguageFeatures', function() {
return [];
}
});
assert.equal(QuickOutlineRegistry.all(model).length, 1);
assert.equal(OutlineRegistry.all(model).length, 1);
disposable.dispose();
assert.equal(QuickOutlineRegistry.all(model).length, 1);
assert.equal(OutlineRegistry.all(model).length, 1);
disposable2.dispose();
assert.equal(QuickOutlineRegistry.all(model).length, 0);
assert.equal(OutlineRegistry.all(model).length, 0);
});
test('DocumentSymbols, evil provider', function(done) {