debt - move resolve logic to ISuggestItem
This commit is contained in:
parent
38207c8098
commit
5887ea6d55
|
@ -477,10 +477,8 @@ export class SuggestWidget implements IContentWidget, IDisposable {
|
|||
this.updateWidgetHeight();
|
||||
this.list.reveal(index);
|
||||
|
||||
const position = this.model.getRequestPosition() || this.editor.getPosition();
|
||||
this.currentSuggestionDetails = item.resolveDetails(this.editor.getModel(), position)
|
||||
.then(details => {
|
||||
item.updateDetails(details);
|
||||
this.currentSuggestionDetails = item.resolve()
|
||||
.then(() => {
|
||||
this.list.setFocus(index);
|
||||
this.updateWidgetHeight();
|
||||
this.list.reveal(index);
|
||||
|
|
|
@ -6,14 +6,10 @@
|
|||
'use strict';
|
||||
|
||||
import {isFalsyOrEmpty} from 'vs/base/common/arrays';
|
||||
import {assign} from 'vs/base/common/objects';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {IReadOnlyModel} from 'vs/editor/common/editorCommon';
|
||||
import {IFilter, IMatch, fuzzyContiguousFilter} from 'vs/base/common/filters';
|
||||
import {ISuggestSupport, ISuggestion} from 'vs/editor/common/modes';
|
||||
import {ISuggestion} from 'vs/editor/common/modes';
|
||||
import {ISuggestionItem} from './suggest';
|
||||
import {asWinJsPromise} from 'vs/base/common/async';
|
||||
import {Position} from 'vs/editor/common/core/position';
|
||||
|
||||
export class CompletionItem {
|
||||
|
||||
|
@ -21,26 +17,13 @@ export class CompletionItem {
|
|||
highlights: IMatch[];
|
||||
filter: IFilter;
|
||||
|
||||
private _support: ISuggestSupport;
|
||||
|
||||
constructor(item: ISuggestionItem) {
|
||||
this.suggestion = item.suggestion;
|
||||
this.filter = item.support && item.support.filter || fuzzyContiguousFilter;
|
||||
this._support = item.support;
|
||||
constructor(private _item: ISuggestionItem) {
|
||||
this.suggestion = _item.suggestion;
|
||||
this.filter = _item.support && _item.support.filter || fuzzyContiguousFilter;
|
||||
}
|
||||
|
||||
resolveDetails(model:IReadOnlyModel, position:Position): TPromise<ISuggestion> {
|
||||
if (!this._support || typeof this._support.resolveCompletionItem !== 'function') {
|
||||
return TPromise.as(this.suggestion);
|
||||
}
|
||||
|
||||
return asWinJsPromise((token) => {
|
||||
return this._support.resolveCompletionItem(model, position, this.suggestion, token);
|
||||
});
|
||||
}
|
||||
|
||||
updateDetails(value: ISuggestion): void {
|
||||
this.suggestion = assign(this.suggestion, value);
|
||||
resolve(): TPromise<this> {
|
||||
return this._item.resolve().then(() => this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import {sequence, asWinJsPromise} from 'vs/base/common/async';
|
||||
import {isFalsyOrEmpty} from 'vs/base/common/arrays';
|
||||
import {compare} from 'vs/base/common/strings';
|
||||
import {assign} from 'vs/base/common/objects';
|
||||
import {onUnexpectedError} from 'vs/base/common/errors';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {IReadOnlyModel} from 'vs/editor/common/editorCommon';
|
||||
|
@ -27,6 +28,7 @@ export interface ISuggestionItem {
|
|||
suggestion: ISuggestion;
|
||||
container: ISuggestResult;
|
||||
support: ISuggestSupport;
|
||||
resolve(): TPromise<void>;
|
||||
}
|
||||
|
||||
export type SnippetConfig = 'top' | 'bottom' | 'inline' | 'none' | 'only';
|
||||
|
@ -75,7 +77,7 @@ export function provideSuggestionItems(model: IReadOnlyModel, position: Position
|
|||
return;
|
||||
}
|
||||
|
||||
let oldLen = result.length;
|
||||
const len = result.length;
|
||||
|
||||
for (let container of values) {
|
||||
if (container && !isFalsyOrEmpty(container.suggestions)) {
|
||||
|
@ -87,14 +89,15 @@ export function provideSuggestionItems(model: IReadOnlyModel, position: Position
|
|||
result.push({
|
||||
container,
|
||||
suggestion,
|
||||
support
|
||||
support,
|
||||
resolve: createSuggestionResolver(support, suggestion, model, position)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oldLen !== result.length && support !== snippetSuggestSupport) {
|
||||
if (len !== result.length && support !== snippetSuggestSupport) {
|
||||
hasResult = true;
|
||||
}
|
||||
|
||||
|
@ -114,6 +117,16 @@ function fixOverwriteBeforeAfter(suggestion: ISuggestion, container: ISuggestRes
|
|||
}
|
||||
}
|
||||
|
||||
function createSuggestionResolver(provider: ISuggestSupport, suggestion: ISuggestion, model: IReadOnlyModel, position: Position): () => TPromise<void> {
|
||||
return () => {
|
||||
if (typeof provider.resolveCompletionItem === 'function') {
|
||||
return asWinJsPromise(token => provider.resolveCompletionItem(model, position, suggestion, token))
|
||||
.then(value => { assign(suggestion, value); });
|
||||
}
|
||||
return TPromise.as(void 0);
|
||||
};
|
||||
}
|
||||
|
||||
function createSuggesionFilter(options: ISuggestOptions): (candidate: ISuggestion) => boolean {
|
||||
if (options.snippetConfig === 'only') {
|
||||
return suggestion => suggestion.type === 'snippet';
|
||||
|
|
|
@ -14,7 +14,6 @@ import {ISuggestSupport, ISuggestion, SuggestRegistry} from 'vs/editor/common/mo
|
|||
import {CodeSnippet} from 'vs/editor/contrib/snippet/common/snippet';
|
||||
import {ISuggestionItem, provideSuggestionItems} from './suggest';
|
||||
import {CompletionModel} from './completionModel';
|
||||
import {Position} from 'vs/editor/common/core/position';
|
||||
|
||||
export interface ICancelEvent {
|
||||
retrigger: boolean;
|
||||
|
@ -219,14 +218,6 @@ export class SuggestModel implements IDisposable {
|
|||
return actuallyCanceled;
|
||||
}
|
||||
|
||||
getRequestPosition(): Position {
|
||||
if (!this.context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Position(this.context.lineNumber, this.context.column);
|
||||
}
|
||||
|
||||
private isAutoSuggest(): boolean {
|
||||
return this.state === State.Auto;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue