From afacd8da567feb9a77a10bb9d83d275fae49f0a9 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 22 Nov 2016 12:25:52 -0500 Subject: [PATCH] Add initial API --- autoload/langserver/api/textDocument.vim | 9 +++++ autoload/langserver/client.vim | 11 +++++++ autoload/langserver/goto.vim | 7 ++-- tests/test_goto.vader | 42 ++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 autoload/langserver/api/textDocument.vim create mode 100644 tests/test_goto.vader diff --git a/autoload/langserver/api/textDocument.vim b/autoload/langserver/api/textDocument.vim new file mode 100644 index 0000000..25f5e02 --- /dev/null +++ b/autoload/langserver/api/textDocument.vim @@ -0,0 +1,9 @@ +"" +function! langserver#api#textDocument#definition(request) abort + return langserver#goto#goto_defintion( + \ langserver#util#get_lsp_id(), + \ a:request.result.uri, + \ a:request.result.range, + \ {}, + \ ) +endfunction diff --git a/autoload/langserver/client.vim b/autoload/langserver/client.vim index 4ebd774..0cdd4e1 100644 --- a/autoload/langserver/client.vim +++ b/autoload/langserver/client.vim @@ -10,6 +10,17 @@ let s:lsp_text_document_sync_kind_incremental = 2 function! s:_on_lsp_stdout(id, data, event) abort if has_key(s:lsp_clients, a:id) + " let s:lsp_clients[l:lsp_client_id] = { + " \ 'id': l:lsp_client_id, + " \ 'opts': a:opts, + " \ 'req_seq': 0, + " \ 'on_notifications': {}, + " \ 'stdout': { + " \ 'max_buffer_size': l:max_buffer_size, + " \ 'buffer': '', + " \ 'next_token': s:lsp_token_type_contentlength, + " \ }, + " \ } let l:client = s:lsp_clients[a:id] let l:client.stdout.buffer .= join(a:data, "\n") diff --git a/autoload/langserver/goto.vim b/autoload/langserver/goto.vim index 27dde86..8fade52 100644 --- a/autoload/langserver/goto.vim +++ b/autoload/langserver/goto.vim @@ -83,8 +83,11 @@ function! langserver#goto#goto_defintion(name, uri, range_dict, options) abort " \ a:range_dict['start']['line'] + 1, " \ a:range_dict['start']['character'] + 1, " \ ) - execute(printf('norm! %sG%s|', + let l:action = printf('norm! %sG%s|', \ a:range_dict['start']['line'] + 1, \ a:range_dict['start']['character'] + 1, - \ )) + \ ) + execute(l:action) + + return l:action endfunction diff --git a/tests/test_goto.vader b/tests/test_goto.vader new file mode 100644 index 0000000..7e7e705 --- /dev/null +++ b/tests/test_goto.vader @@ -0,0 +1,42 @@ + +Given vim (Goto position): + let this = 'that' + + " A comment here + " A comment there + " Here a comment, there a comment + + " Everywhere a comment + +Do (Move): + 2j + +Execute (Call goto): + let g:test_request = { + \ 'result': { + \ 'uri': 'file://' . expand('%'), + \ 'range': { + \ 'start': {'line': 0, 'character': 4}, + \ 'end': {'line': 0, 'character': 8}, + \ }, + \ }} + + Log g:test_request.result.uri + + let cmd = langserver#api#textDocument#definition(g:test_request) + AssertEqual cmd, 'norm! 1G5|' + +" I Would like to use these but it doesn't seem to work. +" Then (delete character): +" x + +" Expect (Line to be deleted): +" let his = 'that' + +" " A comment here +" " A comment there +" " Here a comment, there a comment + +" " Everywhere a comment + +