mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-28 08:04:00 +01:00
use SuggestionType over string
This commit is contained in:
@@ -325,10 +325,30 @@ export interface IExtraInfoSupport {
|
||||
computeInfo(resource:URI, position:editorCommon.IPosition):TPromise<IComputeExtraInfoResult>;
|
||||
}
|
||||
|
||||
export type SuggestionType = 'method'
|
||||
| 'function'
|
||||
| 'constructor'
|
||||
| 'field'
|
||||
| 'variable'
|
||||
| 'class'
|
||||
| 'interface'
|
||||
| 'module'
|
||||
| 'property'
|
||||
| 'unit'
|
||||
| 'value'
|
||||
| 'enum'
|
||||
| 'keyword'
|
||||
| 'snippet'
|
||||
| 'text'
|
||||
| 'color'
|
||||
| 'file'
|
||||
| 'reference'
|
||||
| 'customcolor';
|
||||
|
||||
export interface ISuggestion {
|
||||
label: string;
|
||||
codeSnippet: string;
|
||||
type: 'Text' | 'Method' | 'Function' | 'Constructor' | 'Field' | 'Variable' | 'Class' | 'Interface' | 'Module' | 'Property' | 'Unit' | 'Value' | 'Enum' | 'Keyword' | 'Snippet' | 'Color' | 'File' | 'Reference' | string;
|
||||
type: SuggestionType;
|
||||
typeLabel?: string;
|
||||
documentationLabel?: string;
|
||||
filterText?: string;
|
||||
|
||||
@@ -83,9 +83,9 @@ class Renderer implements IRenderer<CompletionItem, ISuggestionTemplateData> {
|
||||
data.root.setAttribute('aria-label', nls.localize('suggestionAriaLabel', "{0}, suggestion", suggestion.label));
|
||||
}
|
||||
|
||||
if (suggestion.type && suggestion.type.charAt(0) === '#') {
|
||||
if (suggestion.type === 'customcolor') {
|
||||
data.icon.className = 'icon customcolor';
|
||||
data.colorspan.style.backgroundColor = suggestion.type.substring(1);
|
||||
data.colorspan.style.backgroundColor = suggestion.label;
|
||||
} else {
|
||||
data.icon.className = 'icon ' + suggestion.type;
|
||||
data.colorspan.style.backgroundColor = '';
|
||||
|
||||
@@ -160,14 +160,13 @@ export class CSSIntellisense {
|
||||
|
||||
public getValueEnumProposals(entry:languageFacts.IEntry, result:Modes.ISuggestion[]):Modes.ISuggestion[]{
|
||||
if (entry.values) {
|
||||
var type = 'value';
|
||||
entry.values.forEach((value) => {
|
||||
if (languageFacts.isCommonValue(value)) { // only show if supported by more than one browser
|
||||
result.push({
|
||||
label: value.name,
|
||||
documentationLabel: languageFacts.getEntryDescription(value),
|
||||
codeSnippet: value.name,
|
||||
type: type
|
||||
type: 'value'
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -237,7 +236,7 @@ export class CSSIntellisense {
|
||||
label: color,
|
||||
documentationLabel: languageFacts.colors[color],
|
||||
codeSnippet: color,
|
||||
type: '#' + languageFacts.colors[color]
|
||||
type: 'customcolor'
|
||||
});
|
||||
}
|
||||
for (var color in languageFacts.colorKeywords) {
|
||||
@@ -254,7 +253,7 @@ export class CSSIntellisense {
|
||||
result.push({
|
||||
label: color,
|
||||
codeSnippet: color,
|
||||
type: '#' + color
|
||||
type: 'customcolor'
|
||||
});
|
||||
});
|
||||
CSSIntellisense.colorFunctions.forEach((p) => {
|
||||
|
||||
@@ -253,7 +253,7 @@ suite('Validation - CSS', () => {
|
||||
}),
|
||||
testSuggestionsFor('.foo { background-color: #123456; } .bar { background-color: }', '.bar { background-color:').then(function(completion: Modes.ISuggestResult): void {
|
||||
assert.equal(completion.currentWord, '');
|
||||
assertSuggestion(completion, '#123456', '##123456');
|
||||
assertSuggestion(completion, '#123456', 'customcolor');
|
||||
}),
|
||||
testSuggestionsFor('.foo { unknown: foo; } .bar { unknown: }', '.bar { unknown:').then(function(completion: Modes.ISuggestResult): void {
|
||||
assert.equal(completion.currentWord, '');
|
||||
@@ -263,7 +263,7 @@ suite('Validation - CSS', () => {
|
||||
assert.equal(completion.currentWord, 'r');
|
||||
assertSuggestion(completion, 'rgb', 'function');
|
||||
assertSuggestion(completion, 'rgba', 'function');
|
||||
assertSuggestion(completion, 'red', '##ff0000');
|
||||
assertSuggestion(completion, 'red', 'customcolor');
|
||||
})
|
||||
]).done(() => testDone(), (errors: any[]) => {
|
||||
testDone(errors.reduce((e1, e2) => e1 || e2));
|
||||
|
||||
@@ -397,7 +397,7 @@ export class JSONIntellisense {
|
||||
return snippet;
|
||||
}
|
||||
|
||||
private getSuggestionType(type: any): string {
|
||||
private getSuggestionType(type: any): Modes.SuggestionType {
|
||||
if (Array.isArray(type)) {
|
||||
var array = <any[]> type;
|
||||
type = array.length > 0 ? array[0] : null;
|
||||
|
||||
@@ -188,7 +188,7 @@ class SuggestAdapter extends Adapter implements modes.ISuggestSupport {
|
||||
return <modes.ISuggestion>{
|
||||
label: entry.name,
|
||||
codeSnippet: entry.name,
|
||||
type: entry.kind
|
||||
type: SuggestAdapter.asType(entry.kind)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -213,13 +213,33 @@ class SuggestAdapter extends Adapter implements modes.ISuggestSupport {
|
||||
return <modes.ISuggestion>{
|
||||
label: details.name,
|
||||
codeSnippet: details.name,
|
||||
type: details.kind,
|
||||
type: SuggestAdapter.asType(details.kind),
|
||||
typeLabel: ts.displayPartsToString(details.displayParts),
|
||||
documentationLabel: ts.displayPartsToString(details.documentation)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
static asType(kind: string): modes.SuggestionType{
|
||||
switch (kind) {
|
||||
case 'getter':
|
||||
case 'setting':
|
||||
case 'constructor':
|
||||
case 'method':
|
||||
case 'property':
|
||||
return 'property';
|
||||
case 'function':
|
||||
case 'local function':
|
||||
return 'function';
|
||||
case 'class':
|
||||
return 'class';
|
||||
case 'interface':
|
||||
return 'interface';
|
||||
}
|
||||
|
||||
return 'variable';
|
||||
}
|
||||
|
||||
getFilter(): modes.ISuggestionFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -354,13 +354,47 @@ export function toDocumentHighlight(occurrence: modes.IOccurence): types.Documen
|
||||
types.DocumentHighlightKind[occurrence.kind.charAt(0).toUpperCase() + occurrence.kind.substr(1)]);
|
||||
}
|
||||
|
||||
export const CompletionItemKind = {
|
||||
|
||||
from(kind: types.CompletionItemKind): modes.SuggestionType {
|
||||
switch (kind) {
|
||||
case types.CompletionItemKind.Function: return 'function';
|
||||
case types.CompletionItemKind.Constructor: return 'constructor';
|
||||
case types.CompletionItemKind.Field: return 'field';
|
||||
case types.CompletionItemKind.Variable: return 'variable';
|
||||
case types.CompletionItemKind.Class: return 'class';
|
||||
case types.CompletionItemKind.Interface: return 'interface';
|
||||
case types.CompletionItemKind.Module: return 'module';
|
||||
case types.CompletionItemKind.Property: return 'property';
|
||||
case types.CompletionItemKind.Unit: return 'unit';
|
||||
case types.CompletionItemKind.Value: return 'value';
|
||||
case types.CompletionItemKind.Enum: return 'enum';
|
||||
case types.CompletionItemKind.Keyword: return 'keyword';
|
||||
case types.CompletionItemKind.Snippet: return 'snippet';
|
||||
case types.CompletionItemKind.Text: return 'text';
|
||||
case types.CompletionItemKind.Color: return 'color';
|
||||
case types.CompletionItemKind.File: return 'file';
|
||||
case types.CompletionItemKind.Reference: return 'reference';
|
||||
}
|
||||
return 'text';
|
||||
},
|
||||
|
||||
to(type: modes.SuggestionType): types.CompletionItemKind {
|
||||
if (!type) {
|
||||
return types.CompletionItemKind.Text;
|
||||
} else {
|
||||
return types.CompletionItemKind[type.charAt(0).toUpperCase() + type.substr(1)];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const Suggest = {
|
||||
|
||||
from(item: vscode.CompletionItem): modes.ISuggestion {
|
||||
const suggestion: modes.ISuggestion = {
|
||||
label: item.label,
|
||||
codeSnippet: item.insertText || item.label,
|
||||
type: types.CompletionItemKind[item.kind || types.CompletionItemKind.Text].toString().toLowerCase(),
|
||||
type: CompletionItemKind.from(item.kind),
|
||||
typeLabel: item.detail,
|
||||
documentationLabel: item.documentation,
|
||||
sortText: item.sortText,
|
||||
@@ -372,7 +406,7 @@ export const Suggest = {
|
||||
to(container: modes.ISuggestResult, position: types.Position, suggestion: modes.ISuggestion): types.CompletionItem {
|
||||
const result = new types.CompletionItem(suggestion.label);
|
||||
result.insertText = suggestion.codeSnippet;
|
||||
result.kind = types.CompletionItemKind[suggestion.type.charAt(0).toUpperCase() + suggestion.type.substr(1)];
|
||||
result.kind = CompletionItemKind.to(suggestion.type);
|
||||
result.detail = suggestion.typeLabel;
|
||||
result.documentation = suggestion.documentationLabel;
|
||||
result.sortText = suggestion.sortText;
|
||||
|
||||
Reference in New Issue
Block a user