@@ -21,50 +21,40 @@ export class ClojureCompletionItemProvider implements vscode.CompletionItemProvi
2121 if ( ! cljConnection . isConnected ( ) )
2222 return Promise . reject ( 'No nREPL connected.' ) ;
2323
24- return new Promise < vscode . CompletionList > ( ( resolve , reject ) => {
25- let document = vscode . window . activeTextEditor . document ;
26-
27- // TODO: Use VSCode means for getting a current word
28- let lineText = document . lineAt ( position . line ) . text ;
29- let words : string [ ] = lineText . split ( ' ' ) ;
30- let currentWord = words [ words . length - 1 ] . replace ( / ^ [ \( ' \[ \{ ] + | [ \) \] \} ] + $ / g, '' ) ;
31- let text = document . getText ( )
32- let ns = cljParser . getNamespace ( text ) ;
33-
34- let currentWordLength : number = currentWord . length ;
35-
36- let buildInsertText = ( suggestion : string ) => {
37- return suggestion [ 0 ] === '.' ? suggestion . slice ( 1 ) : suggestion ;
38- }
39-
40- nreplClient . complete ( currentWord , ns , ( completions ) => {
41- let suggestions = [ ] ;
42- if ( 'completions' in completions ) {
43- completions . completions . forEach ( element => {
44- suggestions . push ( {
45- label : element . candidate ,
46- kind : mappings [ element . type ] || vscode . CompletionItemKind . Text ,
47- insertText : buildInsertText ( element . candidate )
48- } )
49- } )
50- } else {
51- return reject ( ) ;
52- }
53- let completionList : vscode . CompletionList = new vscode . CompletionList ( suggestions , false ) ;
54- resolve ( completionList ) ;
55- } ) ;
56- } )
24+ // TODO: Use VSCode means for getting a current word
25+ let lineText = document . lineAt ( position . line ) . text ;
26+ let words : string [ ] = lineText . split ( ' ' ) ;
27+ let currentWord = words [ words . length - 1 ] . replace ( / ^ [ \( ' \[ \{ ] + | [ \) \] \} ] + $ / g, '' ) ;
28+ let text = document . getText ( )
29+ let ns = cljParser . getNamespace ( text ) ;
30+
31+ let currentWordLength : number = currentWord . length ;
32+
33+ let buildInsertText = ( suggestion : string ) => {
34+ return suggestion [ 0 ] === '.' ? suggestion . slice ( 1 ) : suggestion ;
35+ }
36+
37+ return nreplClient . complete ( currentWord , ns ) . then ( completions => {
38+ if ( ! ( 'completions' in completions ) )
39+ return Promise . reject ( undefined ) ;
40+
41+ let suggestions = completions . completions . map ( element => ( {
42+ label : element . candidate ,
43+ kind : mappings [ element . type ] || vscode . CompletionItemKind . Text ,
44+ insertText : buildInsertText ( element . candidate )
45+ } ) ) ;
46+ let completionList : vscode . CompletionList = new vscode . CompletionList ( suggestions , false ) ;
47+ return Promise . resolve ( completionList ) ;
48+ } ) ;
5749 }
5850
5951 public resolveCompletionItem ( item : vscode . CompletionItem , token : vscode . CancellationToken ) : Thenable < vscode . CompletionItem > {
60- return new Promise < vscode . CompletionItem > ( ( resolve , reject ) => {
61- let document = vscode . window . activeTextEditor . document ;
62- let ns = cljParser . getNamespace ( document . getText ( ) ) ;
63- nreplClient . info ( item . label , ns , ( info ) => {
64- item . documentation = info . doc ;
65- resolve ( item ) ;
66- } ) ;
67- } )
52+ let document = vscode . window . activeTextEditor . document ;
53+ let ns = cljParser . getNamespace ( document . getText ( ) ) ;
54+ return nreplClient . info ( item . label , ns ) . then ( info => {
55+ item . documentation = info . doc ;
56+ return Promise . resolve ( item ) ;
57+ } ) ;
6858 }
6959
7060}
0 commit comments