All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 runtime autoload/ale/lsp.vim
4 let g:message_list = []
6 function! MarkAllConnectionsInitialized() abort
7 for l:conn in values(ale#lsp#GetConnections())
8 let l:conn.initialized = 1
12 function! MarkDocumentOpened() abort
13 for l:conn in values(ale#lsp#GetConnections())
14 let l:conn.open_documents[bufnr('')] = 1
18 function! ale#lsp#Send(conn_id, message) abort
19 let l:connections = ale#lsp#GetConnections()
21 if !l:connections[a:conn_id].initialized
22 throw 'LSP server not initialized yet!'
25 call add(g:message_list, [a:conn_id] + a:message)
28 call ale#lsp#ResetConnections()
32 delfunction MarkAllConnectionsInitialized
33 delfunction MarkDocumentOpened
35 call ale#lsp#ResetConnections()
37 runtime autoload/ale/lsp.vim
39 Execute(No errors should be thrown if the connection is not initialized):
40 call ale#lsp#Register('command', '/foo', '', {})
41 call MarkDocumentOpened()
43 call ale#engine#Cleanup(bufnr(''))
44 AssertEqual [], g:message_list
46 Execute(No messages should be sent if the document wasn't opened):
47 call ale#lsp#Register('command', '/foo', '', {})
48 call MarkAllConnectionsInitialized()
50 call ale#engine#Cleanup(bufnr(''))
51 AssertEqual [], g:message_list
53 Execute(A message should be sent if the document was opened):
54 call ale#lsp#Register('command', '/foo', 'lang', {})
55 call MarkAllConnectionsInitialized()
57 call ale#lsp#OpenDocument('command:/foo', bufnr(''))
58 call ale#engine#Cleanup(bufnr(''))
59 " We should only send the message once.
60 call ale#engine#Cleanup(bufnr(''))
64 \ ['command:/foo', 1, 'textDocument/didOpen', {
66 \ 'uri': ale#path#ToFileURI(expand('%:p')),
67 \ 'version': g:ale_lsp_next_version_id - 1,
68 \ 'languageId': 'lang',
72 \ ['command:/foo', 1, 'textDocument/didClose', {
74 \ 'uri': ale#path#ToFileURI(expand('%:p')),
80 Execute(A message should be sent if the document was opened for tsserver):
81 call ale#lsp#Register('command', '/foo', 'lang', {})
82 call ale#lsp#MarkConnectionAsTsserver('command:/foo')
84 call ale#lsp#OpenDocument('command:/foo', bufnr(''))
85 call ale#engine#Cleanup(bufnr(''))
86 " We should only send the message once.
87 call ale#engine#Cleanup(bufnr(''))
91 \ ['command:/foo', 1, 'ts@open', {'file': expand('%:p')}],
92 \ ['command:/foo', 1, 'ts@close', {'file': expand('%:p')}],
96 Execute(Re-opening and closing the documents should work):
97 call ale#lsp#Register('command', '/foo', 'lang', {})
98 call MarkAllConnectionsInitialized()
100 call ale#lsp#OpenDocument('command:/foo', bufnr(''))
101 call ale#engine#Cleanup(bufnr(''))
102 call ale#lsp#OpenDocument('command:/foo', bufnr(''))
103 call ale#engine#Cleanup(bufnr(''))
107 \ ['command:/foo', 1, 'textDocument/didOpen', {
109 \ 'uri': ale#path#ToFileURI(expand('%:p')),
110 \ 'version': g:ale_lsp_next_version_id - 2,
111 \ 'languageId': 'lang',
115 \ ['command:/foo', 1, 'textDocument/didClose', {
117 \ 'uri': ale#path#ToFileURI(expand('%:p')),
120 \ ['command:/foo', 1, 'textDocument/didOpen', {
122 \ 'uri': ale#path#ToFileURI(expand('%:p')),
123 \ 'version': g:ale_lsp_next_version_id - 1,
124 \ 'languageId': 'lang',
128 \ ['command:/foo', 1, 'textDocument/didClose', {
130 \ 'uri': ale#path#ToFileURI(expand('%:p')),
136 Execute(Messages for closing documents should be sent to each server):
137 call ale#lsp#Register('command', '/foo', 'lang', {})
138 call ale#lsp#Register('command', '/bar', 'lang', {})
139 call MarkAllConnectionsInitialized()
141 call ale#lsp#OpenDocument('command:/foo', bufnr(''))
142 call ale#lsp#OpenDocument('command:/bar', bufnr(''))
143 call ale#engine#Cleanup(bufnr(''))
144 " We should only send the message once.
145 call ale#engine#Cleanup(bufnr(''))
149 \ ['command:/foo', 1, 'textDocument/didOpen', {
151 \ 'uri': ale#path#ToFileURI(expand('%:p')),
152 \ 'version': g:ale_lsp_next_version_id - 2,
153 \ 'languageId': 'lang',
157 \ ['command:/bar', 1, 'textDocument/didOpen', {
159 \ 'uri': ale#path#ToFileURI(expand('%:p')),
160 \ 'version': g:ale_lsp_next_version_id - 1,
161 \ 'languageId': 'lang',
165 \ ['command:/bar', 1, 'textDocument/didClose', {
167 \ 'uri': ale#path#ToFileURI(expand('%:p')),
170 \ ['command:/foo', 1, 'textDocument/didClose', {
172 \ 'uri': ale#path#ToFileURI(expand('%:p')),