have intellisense for modes

This commit is contained in:
Benjamin Pasero
2016-03-04 17:36:31 +01:00
parent 3ff5de1e0a
commit 3041b376a0
3 changed files with 75 additions and 58 deletions

View File

@@ -13,18 +13,20 @@ import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
let globProperties: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('assocLabel', "Files with Extension"), insertText: '"*.{{extension}}": "{{language}}"', documentation: localize('assocDescription', "Map all files matching the given pattern to the language with the given id.") },
];
let globValues: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('languageId', "Language Identifier"), insertText: '"{{language}}"', documentation: localize('languageDescription', "The identifier of the language to associate with the file name pattern.") },
{ kind: CompletionItemKind.Value, label: localize('assocLabelFile', "Files with Extension"), insertText: '"*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionFile', "Map all files matching the glob pattern in their filename to the language with the given id.") },
{ kind: CompletionItemKind.Value, label: localize('assocLabelPath', "Files with Path"), insertText: '"{{folder}}/*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionPath', "Map all files matching the glob pattern in their full path to the language with the given id.") }
];
export class FileAssociationContribution implements IJSONWorkerContribution {
private languageIds:string[];
constructor() {
}
public setLanguageIds(ids:string[]): void {
this.languageIds = ids;
}
private isSettingsFile(resource: string): boolean {
return Strings.endsWith(resource, '/settings.json');
}
@@ -43,7 +45,13 @@ export class FileAssociationContribution implements IJSONWorkerContribution {
public collectValueSuggestions(resource: string, location: JSONLocation, currentKey: string, result: ISuggestionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.matches(['files.associations'])) {
globValues.forEach((e) => result.add(e));
this.languageIds.forEach(l => {
result.add({
kind: CompletionItemKind.Value,
label: l,
insertText: '"{{' + l + '}}"',
});
});
}
return null;

View File

@@ -58,11 +58,14 @@ let documents: TextDocuments = new TextDocuments();
// for open, change and close text document events
documents.listen(connection);
const filesAssociationContribution = new FileAssociationContribution();
// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilites.
let workspaceRoot: URI;
connection.onInitialize((params: InitializeParams): InitializeResult => {
workspaceRoot = URI.parse(params.rootPath);
filesAssociationContribution.setLanguageIds(params.initializationOptions.languageIds);
return {
capabilities: {
// Tell the client that the server works in FULL text document sync mode
@@ -120,7 +123,7 @@ let contributions = [
new PackageJSONContribution(request),
new BowerJSONContribution(request),
new GlobPatternContribution(),
new FileAssociationContribution()
filesAssociationContribution
];
let jsonSchemaService = new JSONSchemaService(request, workspaceContext, telemetry);