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

debt - remove ISuggestionCompare interface and usage

上级 fca50805
......@@ -396,10 +396,6 @@ export interface ISuggestionFilter {
(word: string, suggestion: ISuggestion): IMatch[];
}
export interface ISuggestionCompare {
(one: ISuggestion, other: ISuggestion): number;
}
/**
* Interface used to get completion suggestions at a specific location.
*/
......@@ -413,13 +409,12 @@ export interface ISuggestSupport {
/**
* Compute more details for the given suggestion.
*/
getSuggestionDetails?:(resource:URI, position:EditorCommon.IPosition, suggestion:ISuggestion)=>TPromise<ISuggestion>;
getSuggestionDetails?: (resource: URI, position: EditorCommon.IPosition, suggestion: ISuggestion) => TPromise<ISuggestion>;
getFilter():ISuggestionFilter;
getSorter?():ISuggestionCompare;
getTriggerCharacters():string[];
shouldShowEmptySuggestionList():boolean;
shouldAutotriggerSuggest(context:ILineContext, offset:number, triggeredByCharacter:string):boolean;
getFilter(): ISuggestionFilter;
getTriggerCharacters(): string[];
shouldShowEmptySuggestionList(): boolean;
shouldAutotriggerSuggest(context: ILineContext, offset: number, triggeredByCharacter: string): boolean;
}
/**
......
......@@ -711,23 +711,13 @@ export interface ISuggestContribution {
triggerCharacters: string[];
disableAutoTrigger?: boolean;
excludeTokens: string[];
sortBy?: ISortingTypeAndSeparator[];
suggest: (resource: URI, position: EditorCommon.IPosition) => TPromise<Modes.ISuggestResult[]>;
getSuggestionDetails? : (resource:URI, position:EditorCommon.IPosition, suggestion:Modes.ISuggestion) => TPromise<Modes.ISuggestion>;
}
export interface ISortingTypeAndSeparator {
type: string;
partSeparator?: string;
}
export class SuggestSupport extends AbstractSupport implements Modes.ISuggestSupport {
private contribution: ISuggestContribution;
private sortByType: string[];
private separatorForType: string[]; // Must have identical size to the above
public suggest : (resource:URI, position:EditorCommon.IPosition) => TPromise<Modes.ISuggestResult[]>;
public getSuggestionDetails : (resource:URI, position:EditorCommon.IPosition, suggestion:Modes.ISuggestion) => TPromise<Modes.ISuggestion>;
......@@ -740,15 +730,6 @@ export class SuggestSupport extends AbstractSupport implements Modes.ISuggestSup
if (typeof contribution.getSuggestionDetails === 'function') {
this.getSuggestionDetails = (resource, position, suggestion) => contribution.getSuggestionDetails(resource, position, suggestion);
}
this.sortByType = [];
this.separatorForType = [];
if (Array.isArray(contribution.sortBy) && contribution.sortBy.length > 0) {
for (var i = 0; i < contribution.sortBy.length; ++i) {
this.sortByType.push(contribution.sortBy[i].type);
this.separatorForType.push(contribution.sortBy[i].partSeparator);
}
}
}
shouldAutotriggerSuggest(context: Modes.ILineContext, offset: number, triggeredByCharacter: string): boolean {
......@@ -776,62 +757,6 @@ export class SuggestSupport extends AbstractSupport implements Modes.ISuggestSup
return DefaultFilter;
}
public getSorter(): Modes.ISuggestionCompare {
return (one, other) => {
if (this.sortByType.length > 0) {
var oneTypeIndex = this.sortByType.indexOf(one.type);
var otherTypeIndex = this.sortByType.indexOf(other.type);
if (oneTypeIndex < 0) {
oneTypeIndex = this.sortByType.length;
}
if (otherTypeIndex < 0) {
otherTypeIndex = this.sortByType.length;
}
if (oneTypeIndex < otherTypeIndex) {
return -1;
}
if (otherTypeIndex < oneTypeIndex) {
return 1;
}
// TypeIndices are equal
if (oneTypeIndex < this.sortByType.length) {
var separator = this.separatorForType[oneTypeIndex];
var oneParts = ((typeof separator === 'string' && separator.length > 0) ? one.label.split(separator) : [one.label]);
var otherParts = ((typeof separator === 'string' && separator.length > 0) ? other.label.split(separator) : [other.label]);
if (oneParts.length < otherParts.length) {
return -1;
} else if (oneParts.length > otherParts.length) {
return 1;
} else {
for (var i = 0; i < oneParts.length; i++) {
var result = Strings.localeCompare(oneParts[i], otherParts[i]);
if (result !== 0) {
return result;
}
}
return 0;
}
}
}
let cmp = 0;
if (one.sortText && other.sortText) {
cmp = one.sortText.localeCompare(other.sortText);
}
if (!cmp) {
cmp = Strings.localeCompare(one.label.toLowerCase(), other.label.toLowerCase());
}
return Strings.localeCompare(one.documentationLabel || '', other.documentationLabel || '');
};
}
public getTriggerCharacters(): string[] {
return this.contribution.triggerCharacters;
}
......
......@@ -24,7 +24,7 @@ import * as Timer from 'vs/base/common/timer';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { SuggestRegistry, CONTEXT_SUGGESTION_SUPPORTS_ACCEPT_ON_KEY } from '../common/suggest';
import { IKeybindingService, IKeybindingContextKey } from 'vs/platform/keybinding/common/keybindingService';
import { ISuggestSupport, ISuggestResult, ISuggestion, ISuggestionCompare, ISuggestionFilter } from 'vs/editor/common/modes';
import { ISuggestSupport, ISuggestResult, ISuggestion, ISuggestionFilter } from 'vs/editor/common/modes';
import { DefaultFilter, IMatch } from 'vs/editor/common/modes/modesFilters';
import { ISuggestResult2 } from '../common/suggest';
import URI from 'vs/base/common/uri';
......@@ -70,14 +70,11 @@ class CompletionItem {
}
}
const defaultCompare: ISuggestionCompare = (a, b) => (a.sortText || a.label).localeCompare((b.sortText || b.label));
class CompletionGroup {
incomplete: boolean;
items: CompletionItem[];
size: number;
compare: ISuggestionCompare;
filter: ISuggestionFilter;
constructor(public model: CompletionModel, public index: number, raw: ISuggestResult2[]) {
......@@ -94,14 +91,12 @@ class CompletionGroup {
);
}, []);
this.compare = defaultCompare;
this.filter = DefaultFilter;
if (this.items.length > 0) {
const [first] = this.items;
if (first.support) {
this.compare = first.support.getSorter && first.support.getSorter() || this.compare;
this.filter = first.support.getFilter && first.support.getFilter() || this.filter;
}
}
......@@ -248,7 +243,11 @@ class Sorter implements Tree.ISorter {
return result;
}
return group.compare(item.suggestion, otherItem.suggestion);
return Sorter.suggestionCompare(item.suggestion, otherItem.suggestion);
}
private static suggestionCompare(a: ISuggestion, b: ISuggestion): number {
return (a.sortText || a.label).localeCompare((b.sortText || b.label));
}
}
......
......@@ -105,7 +105,6 @@ export class JSMode extends typescriptMode.TypeScriptMode<javascriptWorker.JavaS
this.suggestSupport = new supports.SuggestSupport(this, {
triggerCharacters: ['.'],
excludeTokens: ['string', 'comment', 'number', 'numeric'],
sortBy: [{type:'reference', partSeparator: '/'}],
suggest: (resource, position) => this.suggest(resource, position),
getSuggestionDetails: (resource, position, suggestion) => this.getSuggestionDetails(resource, position, suggestion)});
}
......
......@@ -229,7 +229,6 @@ export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extend
this.suggestSupport = new supports.SuggestSupport(this, {
triggerCharacters: ['.'],
excludeTokens: ['string', 'comment', 'number'],
sortBy: [{type:'reference', partSeparator: '/'}],
suggest: (resource, position) => this.suggest(resource, position),
getSuggestionDetails: (resource, position, suggestion) => this.getSuggestionDetails(resource, position, suggestion)});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册