KUDO Shunsuke
3 years ago
3 changed files with 80 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||
|
function! ddc_vim_lsp#_callback(server, position, plugin_name, method_name, data) abort |
||||
|
if lsp#client#is_error(a:data) || !has_key(a:data, 'response') || !has_key(a:data['response'], 'result') || !has_key(a:data['response']['result'], 'items') |
||||
|
return |
||||
|
endif |
||||
|
|
||||
|
call denops#request(a:plugin_name, a:method_name, [a:data['response']['result']['items']]) |
||||
|
endfunction |
||||
|
|
||||
|
function! ddc_vim_lsp#request(plugin_name, method_name) abort |
||||
|
let l:servers = lsp#get_allowed_servers() |
||||
|
if len(l:servers) == 0 |
||||
|
return |
||||
|
endif |
||||
|
|
||||
|
" NOTE: choose first lsp server |
||||
|
let l:server_name = l:servers[0] |
||||
|
let l:server = lsp#get_server_info(l:server_name) |
||||
|
let l:position = lsp#get_position() |
||||
|
|
||||
|
call lsp#send_request(l:server_name, { |
||||
|
\ 'method': 'textDocument/completion', |
||||
|
\ 'params': { |
||||
|
\ 'textDocument': lsp#get_text_document_identifier(), |
||||
|
\ 'position': l:position, |
||||
|
\ }, |
||||
|
\ 'on_notification': function('ddc_vim_lsp#_callback', [l:server, l:position, a:plugin_name, a:method_name]), |
||||
|
\ }) |
||||
|
endfunction |
@ -0,0 +1,42 @@ |
|||||
|
import { |
||||
|
BaseSource, |
||||
|
Candidate, |
||||
|
Context, |
||||
|
DdcOptions, |
||||
|
SourceOptions, |
||||
|
} from "https://deno.land/x/ddc_vim@v0.0.11/types.ts#^"; |
||||
|
|
||||
|
import { |
||||
|
Denops, |
||||
|
} from "https://deno.land/x/ddc_vim@v0.0.11/deps.ts#^"; |
||||
|
|
||||
|
import { |
||||
|
once |
||||
|
} from "https://deno.land/x/denops_std@v1.0.1/anonymous/mod.ts"; |
||||
|
|
||||
|
export class Source extends BaseSource { |
||||
|
async gatherCandidates( |
||||
|
denops: Denops, |
||||
|
context: Context, |
||||
|
_ddcOptions: DdcOptions, |
||||
|
_sourceOptions: SourceOptions, |
||||
|
_sourceParams: Record<string, unknown>, |
||||
|
completeStr: string, |
||||
|
): Promise<Candidate[]> { |
||||
|
return new Promise((resolve) => { |
||||
|
denops.call("ddc_vim_lsp#request", denops.name, once(denops, (response) => { |
||||
|
resolve(this.toCandidates(response)); |
||||
|
})[0]) |
||||
|
}) |
||||
|
.then((cs: Candidate[]) => { |
||||
|
return cs; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
toCandidates(response: unknown[]): Candidate[] { |
||||
|
const cs: Candidate[] = response.map((e) => { |
||||
|
return {word: e.label}; |
||||
|
}); |
||||
|
return cs; |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
if exists('g:loaded_ddc_vim_lsp') |
||||
|
finish |
||||
|
endif |
||||
|
|
||||
|
let g:loaded_ddc_vim_lsp = 1 |
||||
|
|
||||
|
silent! call ddc#register_source({ |
||||
|
\ 'name': 'ddc-vim-lsp', |
||||
|
\ 'path': printf('%s/denops/ddc/sources/ddc-vim-lsp.ts', fnamemodify(expand('<sfile>'), ':h:h:h')), |
||||
|
\ }) |
Loading…
Reference in new issue