import * as fs from "fs" ; import { CompletionItem , CompletionItemKind , CompletionItemProvider , DocumentSelector , SnippetString } from "vscode" ; import * as nls from "vscode-nls" ; nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ; const localize = nls . loadMessageBundle ( ) ; type TMSnippet = { prefix : string ; body : string [ ] ; description : string ; } ; type TMSnippets = { [ name ] : TMSnippet ; } ; export class IonicCompletionProvider implements CompletionItemProvider { public static HTML_DOCUMENT_SELECTOR : DocumentSelector = "html" ; public static JS_DOCUMENT_SELECTOR : DocumentSelector = "javascript" ; private snippetCompletions : CompletionItem [ ] ; constructor ( private completionsSource ) { } public provideCompletionItems ( ) { if ( this . snippetCompletions ) { return this . snippetCompletions ; } this . snippetCompletions = [ ] ; try { let rawSnippets = JSON . parse ( fs . readFileSync ( this . completionsSource , "utf8" ) ) ; this . snippetCompletions = Object . keys ( rawSnippets ) . map ( name => makeCompletionItem ( rawSnippets [ name ] ) ) ; } catch ( err ) { console . warn ( localize ( "FailedToReadSnippetsFrom" , "Failed to read snippets from {0}" , this . completionsSource ) ) ; } return this . snippetCompletions ; } } function makeCompletionItem ( rawSnippet ) { const item = new CompletionItem ( rawSnippet . prefix ) ; item . documentation = rawSnippet . description ; item . kind = CompletionItemKind . Snippet ; item . insertText = new SnippetString ( rawSnippet . body . join ( "\n" ) ) ; return item ; }