import { workspace , CompletionItemProvider , Thenable , CompletionItem , TextDocument , Position , ProviderResult , } from 'coc.nvim' ; import { complKind2cmakeType , cmake_help_all , cmCommandsSuggestions , cmModulesSuggestions , cmPropertiesSuggestions , cmVariablesSuggestions , } from '../core' ; export default class CMakeCompletionProvider implements CompletionItemProvider { provideCompletionItems ( document , position ) { const doc = workspace . getDocument ( document . uri ) ; if ( ! doc ) return [ ] ; const wordRange = doc . getWordRangeAtPosition ( Position . create ( position . line , position . character - 1 ) ) ; if ( ! wordRange ) return [ ] ; const text = document . getText ( wordRange ) ; return new Promise ( ( resolve , reject ) => { Promise . all ( [ cmCommandsSuggestions ( text ) , cmVariablesSuggestions ( text ) , cmPropertiesSuggestions ( text ) , cmModulesSuggestions ( text ) , ] ) . then ( ( results ) => { const suggestions = Array . prototype . concat . apply ( [ ] , results ) ; resolve ( suggestions ) ; } ) . catch ( ( err ) => { reject ( err ) ; } ) ; } ) ; } public resolveCompletionItem ( item ) { const promises = cmake_help_all ( ) ; const type = complKind2cmakeType ( item . kind ) ; return promises [ type ] ( item . label ) . then ( ( result ) => { item . documentation = result . split ( '\n' ) [ 3 ] ; return item ; } ) ; } }