Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

Commit 7413c1d

Browse files
author
TJ DeVries
committed
Working on improving callback setup
1 parent 4b1f7ef commit 7413c1d

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

autoload/langserver/api/textDocument.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ function! langserver#api#textDocument#definition(request) abort
77
\ {},
88
\ )
99
endfunction
10+
11+
function! langserver#api#textDocument#completion(request) abort
12+
13+
endfunction

autoload/langserver/client.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let s:lsp_clients = {} " { id, opts, req_seq, on_notifications: { request, on_notification }, stdout: { max_buffer_size, buffer, next_token, current_content_length, current_content_type } }
1+
let s:lsp_clients = {}
22
let s:lsp_token_type_contentlength = 'content-length'
33
let s:lsp_token_type_contenttype = 'content-type'
44
let s:lsp_token_type_message = 'message'
@@ -14,11 +14,14 @@ function! s:_on_lsp_stdout(id, data, event) abort
1414
" \ 'id': l:lsp_client_id,
1515
" \ 'opts': a:opts,
1616
" \ 'req_seq': 0,
17-
" \ 'on_notifications': {},
17+
" \ 'lock': langserver#lock#semaphore(),
18+
" \ 'request_notifications': {},
1819
" \ 'stdout': {
1920
" \ 'max_buffer_size': l:max_buffer_size,
2021
" \ 'buffer': '',
2122
" \ 'next_token': s:lsp_token_type_contentlength,
23+
" \ 'current_content_length': ,
24+
" \ 'current_content_type': ,
2225
" \ },
2326
" \ }
2427
let l:client = s:lsp_clients[a:id]
@@ -126,6 +129,7 @@ function! s:lsp_start(opts) abort
126129
\ 'id': l:lsp_client_id,
127130
\ 'opts': a:opts,
128131
\ 'req_seq': 0,
132+
\ 'lock': langserver#lock#semaphore(),
129133
\ 'on_notifications': {},
130134
\ 'stdout': {
131135
\ 'max_buffer_size': l:max_buffer_size,

autoload/langserver/hover.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function! langserver#hover#request() abort
2020
return langserver#client#send(langserver#util#get_lsp_id(), {
2121
\ 'method': 'textDocument/hover',
2222
\ 'params': langserver#util#get_text_document_position_params(),
23+
\ 'on_notification': {
24+
\ 'callback': function('langserver#hover#callback'),
25+
\ },
2326
\ })
2427
endfunction
2528

@@ -38,7 +41,7 @@ function! langserver#hover#display(range, data) abort
3841

3942
echo l:hover_string
4043

41-
return timer_start(5000, function('s:delete_highlight'))
44+
return timer_start(3000, function('s:delete_highlight'))
4245
endfunction
4346

4447
function! s:delete_highlight() abort

autoload/langserver/lock.vim

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
1+
let s:unlocked_id = -1
12

2-
function! s:dict_lock() dict
3-
let self.locked = v:true
3+
function! s:dict_lock(job_id) dict
4+
if self.locked == v:false
5+
let self.locked = v:true
6+
let self.id = a:job_id
7+
return v:true
8+
else
9+
return v:false
10+
endif
411
endfunction
512

613
function! s:dict_unlock() dict
14+
let self.id = s:unlocked_id
715
let self.locked = v:false
816
endfunction
917

10-
function! s:set_id(job_id) dict
11-
let self.id = a:job_id
12-
endfunction
13-
1418
function! s:get_id() dict
1519
return self.id
1620
endfunction
1721

22+
function! s:take_lock(job_id) dict
23+
" If we're locked, kill the other job
24+
" And set ourselves to be the current job.
25+
if self.locked
26+
" TODO: Don't actually want to stop the whole server...
27+
" I just want to stop the current request. Maybe a send cancel request
28+
" would be good enough. We will see.
29+
" call langserver#job#stop(self.id)
30+
call self.unlock()
31+
endif
32+
33+
call self.lock(a:job_id)
34+
endfunction
35+
1836
function! langserver#lock#semaphore() abort
1937
let l:ret = {
20-
\ 'id': -1,
38+
\ 'id': s:unlocked_id,
2139
\ 'locked': v:false,
2240
\ }
2341
let l:ret.lock = function('s:dict_lock')
2442
let l:ret.unlock = function('s:dict_unlock')
25-
let l:ret.set_id = function('s:set_id')
2643
let l:ret.get_id = function('s:get_id')
44+
let l:ret.take_lock = function('s:take_lock')
2745
return l:ret
2846
endfunction

tests/test_lock.vader

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ Execute (Test Lock):
33

44
AssertEqual v:false, my_lock.locked
55

6-
call my_lock.lock()
6+
call my_lock.lock(1)
77
AssertEqual v:true, my_lock.locked
88

99
call my_lock.unlock()
1010
AssertEqual v:false, my_lock.locked
1111

1212
AssertEqual -1, my_lock.get_id()
1313

14-
call my_lock.set_id(1)
14+
call my_lock.lock(1)
1515
AssertEqual 1, my_lock.get_id()
16+
17+
let set_result = my_lock.lock(2)
18+
AssertEqual v:false, set_result
19+
AssertEqual 1, my_lock.get_id()
20+
21+
call my_lock.take_lock(2)
22+
AssertEqual 2, my_lock.get_id()

0 commit comments

Comments
 (0)