]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/lsp/test_closing_documents.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / ale / test / lsp / test_closing_documents.vader
1 Before:
2   runtime autoload/ale/lsp.vim
3
4   let g:message_list = []
5
6   function! MarkAllConnectionsInitialized() abort
7     for l:conn in values(ale#lsp#GetConnections())
8       let l:conn.initialized = 1
9     endfor
10   endfunction
11
12   function! MarkDocumentOpened() abort
13     for l:conn in values(ale#lsp#GetConnections())
14       let l:conn.open_documents[bufnr('')] = 1
15     endfor
16   endfunction
17
18   function! ale#lsp#Send(conn_id, message) abort
19     let l:connections = ale#lsp#GetConnections()
20
21     if !l:connections[a:conn_id].initialized
22         throw 'LSP server not initialized yet!'
23     endif
24
25     call add(g:message_list, [a:conn_id] + a:message)
26   endfunction
27
28   call ale#lsp#ResetConnections()
29
30 After:
31   unlet! g:message_list
32   delfunction MarkAllConnectionsInitialized
33   delfunction MarkDocumentOpened
34
35   call ale#lsp#ResetConnections()
36
37   runtime autoload/ale/lsp.vim
38
39 Execute(No errors should be thrown if the connection is not initialized):
40   call ale#lsp#Register('command', '/foo', '', {})
41   call MarkDocumentOpened()
42
43   call ale#engine#Cleanup(bufnr(''))
44   AssertEqual [], g:message_list
45
46 Execute(No messages should be sent if the document wasn't opened):
47   call ale#lsp#Register('command', '/foo', '', {})
48   call MarkAllConnectionsInitialized()
49
50   call ale#engine#Cleanup(bufnr(''))
51   AssertEqual [], g:message_list
52
53 Execute(A message should be sent if the document was opened):
54   call ale#lsp#Register('command', '/foo', 'lang', {})
55   call MarkAllConnectionsInitialized()
56
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(''))
61
62   AssertEqual
63   \ [
64   \   ['command:/foo', 1, 'textDocument/didOpen', {
65   \     'textDocument': {
66   \       'uri': ale#path#ToFileURI(expand('%:p')),
67   \       'version': g:ale_lsp_next_version_id - 1,
68   \       'languageId': 'lang',
69   \       'text': "\n",
70   \     },
71   \   }],
72   \   ['command:/foo', 1, 'textDocument/didClose', {
73   \     'textDocument': {
74   \       'uri': ale#path#ToFileURI(expand('%:p')),
75   \     },
76   \   }],
77   \ ],
78   \ g:message_list
79
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')
83
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(''))
88
89   AssertEqual
90   \ [
91   \   ['command:/foo', 1, 'ts@open', {'file': expand('%:p')}],
92   \   ['command:/foo', 1, 'ts@close', {'file': expand('%:p')}],
93   \ ],
94   \ g:message_list
95
96 Execute(Re-opening and closing the documents should work):
97   call ale#lsp#Register('command', '/foo', 'lang', {})
98   call MarkAllConnectionsInitialized()
99
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(''))
104
105   AssertEqual
106   \ [
107   \   ['command:/foo', 1, 'textDocument/didOpen', {
108   \     'textDocument': {
109   \       'uri': ale#path#ToFileURI(expand('%:p')),
110   \       'version': g:ale_lsp_next_version_id - 2,
111   \       'languageId': 'lang',
112   \       'text': "\n",
113   \     },
114   \   }],
115   \   ['command:/foo', 1, 'textDocument/didClose', {
116   \     'textDocument': {
117   \       'uri': ale#path#ToFileURI(expand('%:p')),
118   \     },
119   \   }],
120   \   ['command:/foo', 1, 'textDocument/didOpen', {
121   \     'textDocument': {
122   \       'uri': ale#path#ToFileURI(expand('%:p')),
123   \       'version': g:ale_lsp_next_version_id - 1,
124   \       'languageId': 'lang',
125   \       'text': "\n",
126   \     },
127   \   }],
128   \   ['command:/foo', 1, 'textDocument/didClose', {
129   \     'textDocument': {
130   \       'uri': ale#path#ToFileURI(expand('%:p')),
131   \     },
132   \   }],
133   \ ],
134   \ g:message_list
135
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()
140
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(''))
146
147   AssertEqual
148   \ [
149   \   ['command:/foo', 1, 'textDocument/didOpen', {
150   \     'textDocument': {
151   \       'uri': ale#path#ToFileURI(expand('%:p')),
152   \       'version': g:ale_lsp_next_version_id - 2,
153   \       'languageId': 'lang',
154   \       'text': "\n",
155   \     },
156   \   }],
157   \   ['command:/bar', 1, 'textDocument/didOpen', {
158   \     'textDocument': {
159   \       'uri': ale#path#ToFileURI(expand('%:p')),
160   \       'version': g:ale_lsp_next_version_id - 1,
161   \       'languageId': 'lang',
162   \       'text': "\n",
163   \     },
164   \   }],
165   \   ['command:/bar', 1, 'textDocument/didClose', {
166   \     'textDocument': {
167   \       'uri': ale#path#ToFileURI(expand('%:p')),
168   \     },
169   \   }],
170   \   ['command:/foo', 1, 'textDocument/didClose', {
171   \     'textDocument': {
172   \       'uri': ale#path#ToFileURI(expand('%:p')),
173   \     },
174   \   }],
175   \ ],
176   \ g:message_list