Skip to content

Commit

Permalink
word-based completion item provider gets its own class, #9504
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Mar 8, 2017
1 parent 85982ed commit 8706d1f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/vs/editor/common/services/editorWorkerServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SimpleWorkerClient, logOnceWebWorkerWarning } from 'vs/base/common/work
import { DefaultWorkerFactory } from 'vs/base/worker/defaultWorkerFactory';
import * as editorCommon from 'vs/editor/common/editorCommon';
import * as modes from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditorSimpleWorkerImpl } from 'vs/editor/common/services/editorSimpleWorker';
Expand Down Expand Up @@ -46,14 +47,7 @@ export class EditorWorkerServiceImpl implements IEditorWorkerService {
return wireCancellationToken(token, this._workerManager.withWorker().then(client => client.computeLinks(model.uri)));
}
});
const completionProvider = modes.SuggestRegistry.register('*', <modes.ISuggestSupport>{
provideCompletionItems: (model, position, token) => {
if (configurationService.lookup<boolean>('editor.wordBasedSuggestions').value) {
return this._workerManager.withWorker().then(client => client.textualSuggest(model.uri, position));
}
return undefined;
}
});
const completionProvider = modes.SuggestRegistry.register('*', new WordBasedCompletionItemProvider(this._workerManager, configurationService));
this._registrations = [linkProvider, completionProvider];
}

Expand Down Expand Up @@ -81,7 +75,24 @@ export class EditorWorkerServiceImpl implements IEditorWorkerService {
public navigateValueSet(resource: URI, range: editorCommon.IRange, up: boolean): TPromise<modes.IInplaceReplaceSupportResult> {
return this._workerManager.withWorker().then(client => client.navigateValueSet(resource, range, up));
}
}

class WordBasedCompletionItemProvider implements modes.ISuggestSupport {

private readonly _workerManager: WorkerManager;
private readonly _configurationService: IConfigurationService;

constructor(workerManager: WorkerManager, configurationService: IConfigurationService) {
this._workerManager = workerManager;
this._configurationService = configurationService;
}

provideCompletionItems(model: editorCommon.IModel, position: Position): TPromise<modes.ISuggestResult> {
if (!this._configurationService.lookup<boolean>('editor.wordBasedSuggestions').value) {
return undefined;
}
return this._workerManager.withWorker().then(client => client.textualSuggest(model.uri, position));
}
}

class WorkerManager extends Disposable {
Expand Down

0 comments on commit 8706d1f

Please sign in to comment.