'use strict' ; import { MarkedString , CompletionItemKind , CompletionItem } from 'vscode-languageserver' ; import Strings = require ( '../utils/strings' ) ; import { JSONWorkerContribution , JSONPath , CompletionsCollector } from 'vscode-json-languageservice' ; import * as nls from 'vscode-nls' ; const localize = nls . loadMessageBundle ( ) ; let globProperties = [ { 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 identifier." ) } , { kind : CompletionItemKind . Value , label : localize ( 'assocLabelPath' , "Files with Path" ) , insertText : '"/{{path to file}}/*.{{extension}}": "{{language}}"' , documentation : localize ( 'assocDescriptionPath' , "Map all files matching the absolute path glob pattern in their path to the language with the given identifier." ) } ] ; export class FileAssociationContribution implements JSONWorkerContribution { private languageIds : string [ ] ; constructor ( ) { } public setLanguageIds ( ids ) { this . languageIds = ids ; } private isSettingsFile ( resource ) { return Strings . endsWith ( resource , '/settings.json' ) ; } public collectDefaultCompletions ( resource , result ) { return null ; } public collectPropertyCompletions ( resource , location , currentWord , addValue , isLast , result ) { if ( this . isSettingsFile ( resource ) && location . length === 1 && location [ 0 ] === 'files.associations' ) { globProperties . forEach ( e => { e . filterText = e . insertText ; result . add ( e ) ; } ) ; } return null ; } public collectValueCompletions ( resource , location , currentKey , result ) { if ( this . isSettingsFile ( resource ) && location . length === 1 && location [ 0 ] === 'files.associations' ) { this . languageIds . forEach ( l => { result . add ( { kind : CompletionItemKind . Value , label : l , insertText : JSON . stringify ( '{{' + l + '}}' ) , filterText : JSON . stringify ( l ) } ) ; } ) ; } return null ; } public getInfoContribution ( resource , location ) { return null ; } }