]> git.madduck.net Git - etc/vim.git/blobdiff - .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 '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / lsp / test_closing_documents.vader
diff --git a/.vim/bundle/ale/test/lsp/test_closing_documents.vader b/.vim/bundle/ale/test/lsp/test_closing_documents.vader
new file mode 100644 (file)
index 0000000..2937776
--- /dev/null
@@ -0,0 +1,176 @@
+Before:
+  runtime autoload/ale/lsp.vim
+
+  let g:message_list = []
+
+  function! MarkAllConnectionsInitialized() abort
+    for l:conn in values(ale#lsp#GetConnections())
+      let l:conn.initialized = 1
+    endfor
+  endfunction
+
+  function! MarkDocumentOpened() abort
+    for l:conn in values(ale#lsp#GetConnections())
+      let l:conn.open_documents[bufnr('')] = 1
+    endfor
+  endfunction
+
+  function! ale#lsp#Send(conn_id, message) abort
+    let l:connections = ale#lsp#GetConnections()
+
+    if !l:connections[a:conn_id].initialized
+        throw 'LSP server not initialized yet!'
+    endif
+
+    call add(g:message_list, [a:conn_id] + a:message)
+  endfunction
+
+  call ale#lsp#ResetConnections()
+
+After:
+  unlet! g:message_list
+  delfunction MarkAllConnectionsInitialized
+  delfunction MarkDocumentOpened
+
+  call ale#lsp#ResetConnections()
+
+  runtime autoload/ale/lsp.vim
+
+Execute(No errors should be thrown if the connection is not initialized):
+  call ale#lsp#Register('command', '/foo', '', {})
+  call MarkDocumentOpened()
+
+  call ale#engine#Cleanup(bufnr(''))
+  AssertEqual [], g:message_list
+
+Execute(No messages should be sent if the document wasn't opened):
+  call ale#lsp#Register('command', '/foo', '', {})
+  call MarkAllConnectionsInitialized()
+
+  call ale#engine#Cleanup(bufnr(''))
+  AssertEqual [], g:message_list
+
+Execute(A message should be sent if the document was opened):
+  call ale#lsp#Register('command', '/foo', 'lang', {})
+  call MarkAllConnectionsInitialized()
+
+  call ale#lsp#OpenDocument('command:/foo', bufnr(''))
+  call ale#engine#Cleanup(bufnr(''))
+  " We should only send the message once.
+  call ale#engine#Cleanup(bufnr(''))
+
+  AssertEqual
+  \ [
+  \   ['command:/foo', 1, 'textDocument/didOpen', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \       'version': g:ale_lsp_next_version_id - 1,
+  \       'languageId': 'lang',
+  \       'text': "\n",
+  \     },
+  \   }],
+  \   ['command:/foo', 1, 'textDocument/didClose', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \     },
+  \   }],
+  \ ],
+  \ g:message_list
+
+Execute(A message should be sent if the document was opened for tsserver):
+  call ale#lsp#Register('command', '/foo', 'lang', {})
+  call ale#lsp#MarkConnectionAsTsserver('command:/foo')
+
+  call ale#lsp#OpenDocument('command:/foo', bufnr(''))
+  call ale#engine#Cleanup(bufnr(''))
+  " We should only send the message once.
+  call ale#engine#Cleanup(bufnr(''))
+
+  AssertEqual
+  \ [
+  \   ['command:/foo', 1, 'ts@open', {'file': expand('%:p')}],
+  \   ['command:/foo', 1, 'ts@close', {'file': expand('%:p')}],
+  \ ],
+  \ g:message_list
+
+Execute(Re-opening and closing the documents should work):
+  call ale#lsp#Register('command', '/foo', 'lang', {})
+  call MarkAllConnectionsInitialized()
+
+  call ale#lsp#OpenDocument('command:/foo', bufnr(''))
+  call ale#engine#Cleanup(bufnr(''))
+  call ale#lsp#OpenDocument('command:/foo', bufnr(''))
+  call ale#engine#Cleanup(bufnr(''))
+
+  AssertEqual
+  \ [
+  \   ['command:/foo', 1, 'textDocument/didOpen', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \       'version': g:ale_lsp_next_version_id - 2,
+  \       'languageId': 'lang',
+  \       'text': "\n",
+  \     },
+  \   }],
+  \   ['command:/foo', 1, 'textDocument/didClose', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \     },
+  \   }],
+  \   ['command:/foo', 1, 'textDocument/didOpen', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \       'version': g:ale_lsp_next_version_id - 1,
+  \       'languageId': 'lang',
+  \       'text': "\n",
+  \     },
+  \   }],
+  \   ['command:/foo', 1, 'textDocument/didClose', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \     },
+  \   }],
+  \ ],
+  \ g:message_list
+
+Execute(Messages for closing documents should be sent to each server):
+  call ale#lsp#Register('command', '/foo', 'lang', {})
+  call ale#lsp#Register('command', '/bar', 'lang', {})
+  call MarkAllConnectionsInitialized()
+
+  call ale#lsp#OpenDocument('command:/foo', bufnr(''))
+  call ale#lsp#OpenDocument('command:/bar', bufnr(''))
+  call ale#engine#Cleanup(bufnr(''))
+  " We should only send the message once.
+  call ale#engine#Cleanup(bufnr(''))
+
+  AssertEqual
+  \ [
+  \   ['command:/foo', 1, 'textDocument/didOpen', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \       'version': g:ale_lsp_next_version_id - 2,
+  \       'languageId': 'lang',
+  \       'text': "\n",
+  \     },
+  \   }],
+  \   ['command:/bar', 1, 'textDocument/didOpen', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \       'version': g:ale_lsp_next_version_id - 1,
+  \       'languageId': 'lang',
+  \       'text': "\n",
+  \     },
+  \   }],
+  \   ['command:/bar', 1, 'textDocument/didClose', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \     },
+  \   }],
+  \   ['command:/foo', 1, 'textDocument/didClose', {
+  \     'textDocument': {
+  \       'uri': ale#path#ToFileURI(expand('%:p')),
+  \     },
+  \   }],
+  \ ],
+  \ g:message_list