mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Centralize language mode enumeration in settings completion provider
This commit is contained in:
parent
dfa42afcb8
commit
913651fd55
|
@ -34,7 +34,7 @@ export class SettingsDocument {
|
||||||
|
|
||||||
// files.defaultLanguage
|
// files.defaultLanguage
|
||||||
if (location.path[0] === 'files.defaultLanguage') {
|
if (location.path[0] === 'files.defaultLanguage') {
|
||||||
return this.provideDefaultLanguageCompletionItems(location, range);
|
return this.provideLanguageCompletionItems(location, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.provideLanguageOverridesCompletionItems(location, position);
|
return this.provideLanguageOverridesCompletionItems(location, position);
|
||||||
|
@ -147,10 +147,10 @@ export class SettingsDocument {
|
||||||
return Promise.resolve(completions);
|
return Promise.resolve(completions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private provideLanguageCompletionItems(location: Location, range: vscode.Range, stringify: boolean = true): vscode.ProviderResult<vscode.CompletionItem[]> {
|
private provideLanguageCompletionItems(location: Location, range: vscode.Range, formatFunc: (string) => string = (l) => JSON.stringify(l)): vscode.ProviderResult<vscode.CompletionItem[]> {
|
||||||
return vscode.languages.getLanguages().then(languages => {
|
return vscode.languages.getLanguages().then(languages => {
|
||||||
return languages.map(l => {
|
return languages.map(l => {
|
||||||
return this.newSimpleCompletionItem(stringify ? JSON.stringify(l) : l, range);
|
return this.newSimpleCompletionItem(formatFunc(l), range);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -180,35 +180,13 @@ export class SettingsDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.path.length === 1 && location.previousNode && typeof location.previousNode.value === 'string' && location.previousNode.value.startsWith('[')) {
|
if (location.path.length === 1 && location.previousNode && typeof location.previousNode.value === 'string' && location.previousNode.value.startsWith('[')) {
|
||||||
|
// Suggestion model word matching includes closed sqaure bracket and ending quote
|
||||||
// Suggestion model word matching includes starting quote and open sqaure bracket
|
// Hence include them in the proposal to replace
|
||||||
// Hence exclude them from the proposal range
|
return this.provideLanguageCompletionItems(location, range, language => `"[${language}]"`);
|
||||||
range = new vscode.Range(new vscode.Position(range.start.line, range.start.character + 2), range.end);
|
|
||||||
|
|
||||||
return vscode.languages.getLanguages().then(languages => {
|
|
||||||
return languages.map(l => {
|
|
||||||
|
|
||||||
// Suggestion model word matching includes closed sqaure bracket and ending quote
|
|
||||||
// Hence include them in the proposal to replace
|
|
||||||
return this.newSimpleCompletionItem(l, range, '', l + ']"');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private provideDefaultLanguageCompletionItems(location: Location, range: vscode.Range): vscode.ProviderResult<vscode.CompletionItem[]> {
|
|
||||||
// Suggestion model word matching includes a starting quote
|
|
||||||
// Hence exclude it from the proposal range
|
|
||||||
range = new vscode.Range(new vscode.Position(range.start.line, range.start.character + 1), range.end);
|
|
||||||
|
|
||||||
return vscode.languages.getLanguages().then(languages => {
|
|
||||||
return languages.map(l => {
|
|
||||||
return this.newSimpleCompletionItem(l, range, '', l + '"');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
|
private newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
|
||||||
const item = new vscode.CompletionItem(text);
|
const item = new vscode.CompletionItem(text);
|
||||||
item.kind = vscode.CompletionItemKind.Value;
|
item.kind = vscode.CompletionItemKind.Value;
|
||||||
|
|
Loading…
Reference in a new issue