import { CancellationToken , CompletionItem , CompletionItemKind , CompletionItemProvider , Position , TextDocument , workspace } from 'vscode' ; import { Item } from './Item' ; import { ItemsModel } from './ItemsModel' ; import * as _ from 'lodash' ; import { ConfigManager } from '../Utils/ConfigManager' ; import { OH_CONFIG_PARAMETERS } from '../Utils/types' ; author Kuba Wolanin - Initial contribution
  export class ItemsCompletion implements CompletionItemProvider { constructor ( ) { if ( ! this . model ) { this . model = new ItemsModel ( ) ; } } private model : ItemsModel ; public provideCompletionItems ( document , position , token ) { return new Promise ( ( resolve , reject ) => { if ( ConfigManager . get ( OH_CONFIG_PARAMETERS . useRestApi ) ) { this . model . completions . then ( completions => { resolve ( completions . map ( ( item ) => { let completionItem = _ . assign ( new CompletionItem ( item . name ) , { kind : CompletionItemKind . Variable , detail : item . type , documentation : this . getDocumentation ( item ) } ) ; return completionItem ; } ) ) ; } ) ; } else { reject ( ) ; } } ) ; } param item private getDocumentation ( item ) { let label = item . label ? item . label + ' ' : '' ; let state = item . state ? '(' + item . state + ')' : '' ; let tags = item . tags . length && 'Tags: ' + item . tags . join ( ', ' ) ; let groupNames = item . groupNames . length && 'Groups: ' + item . groupNames . join ( ', ' ) ; let documentation = [ label + state , tags , groupNames ] ; return _ . compact ( documentation ) . join ( '\n' ) ; } }