]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/lsp/test_did_save_event.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_did_save_event.vader
1 Before:
2   Save g:ale_lint_on_save
3   Save g:ale_enabled
4   Save g:ale_linters
5   Save g:ale_run_synchronously
6   Save g:ale_disable_lsp
7
8   call ale#test#SetDirectory('/testplugin/test/completion')
9   call ale#test#SetFilename('dummy.txt')
10
11   runtime autoload/ale/lsp.vim
12   runtime autoload/ale/lsp_linter.vim
13
14   let g:ale_disable_lsp = 0
15   unlet! b:ale_disable_lsp
16   let g:ale_lint_on_save = 1
17   let b:ale_enabled = 1
18   let g:ale_lsp_next_message_id = 1
19   let g:ale_run_synchronously = 1
20   let g:conn_id = v:null
21   let g:message_list = []
22
23   function! LanguageCallback() abort
24     return 'foobar'
25   endfunction
26
27   function! ProjectRootCallback() abort
28     return expand('.')
29   endfunction
30
31   call ale#linter#Define('foobar', {
32   \ 'name': 'dummy_linter',
33   \ 'lsp': 'stdio',
34   \ 'command': 'cat - > /dev/null',
35   \ 'executable': has('win32') ? 'cmd' : 'echo',
36   \ 'language': function('LanguageCallback'),
37   \ 'project_root': function('ProjectRootCallback'),
38   \ })
39   let g:ale_linters = {'foobar': ['dummy_linter']}
40
41   function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
42     let g:conn_id = ale#lsp#Register('executable', '/foo/bar', 'foobar', {})
43     call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
44     let l:details = {
45     \ 'command': 'foobar',
46     \ 'buffer': a:buffer,
47     \ 'connection_id': g:conn_id,
48     \ 'project_root': '/foo/bar',
49     \}
50
51     call a:Callback(a:linter, l:details)
52
53     return 1
54   endfunction
55
56   " Replace the Send function for LSP, so we can monitor calls to it.
57   function! ale#lsp#Send(conn_id, message) abort
58     call add(g:message_list, a:message)
59   endfunction
60
61 After:
62   Restore
63
64   if g:conn_id isnot v:null
65     call ale#lsp#RemoveConnectionWithID(g:conn_id)
66   endif
67
68   unlet! b:ale_enabled
69   unlet! b:ale_linters
70   unlet! g:message_list
71   unlet! b:ale_save_event_fired
72
73   delfunction LanguageCallback
74   delfunction ProjectRootCallback
75
76   call ale#test#RestoreDirectory()
77   call ale#linter#Reset()
78
79   " Stop any timers we left behind.
80   " This stops the tests from failing randomly.
81   call ale#completion#StopTimer()
82
83   runtime autoload/ale/completion.vim
84   runtime autoload/ale/lsp.vim
85   runtime autoload/ale/lsp_linter.vim
86
87 Given foobar (Some imaginary filetype):
88   <contents>
89
90 Execute(Server should be notified on save):
91   call ale#events#SaveEvent(bufnr(''))
92
93   AssertEqual
94   \ [
95   \   [1, 'textDocument/didChange', {
96   \     'textDocument': {
97   \       'uri': ale#path#ToFileURI(expand('%:p')),
98   \       'version': g:ale_lsp_next_version_id - 1,
99   \     },
100   \     'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}],
101   \   }],
102   \ ],
103   \ g:message_list
104
105 Execute(Server should be notified on save with didSave is supported by server):
106
107   " Replace has capability function to simulate didSave server capability
108   function! ale#lsp#HasCapability(conn_id, capability) abort
109       if a:capability == 'did_save'
110           return 1
111       endif
112       return 0
113   endfunction
114
115   call ale#events#SaveEvent(bufnr(''))
116
117   AssertEqual
118   \ [
119   \   [1, 'textDocument/didChange', {
120   \     'textDocument': {
121   \       'uri': ale#path#ToFileURI(expand('%:p')),
122   \       'version': g:ale_lsp_next_version_id - 1,
123   \     },
124   \     'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}],
125   \   }],
126   \   [1, 'textDocument/didSave', {
127   \     'textDocument': {
128   \       'uri': ale#path#ToFileURI(expand('%:p')),
129   \     },
130   \   }],
131   \ ],
132   \ g:message_list
133
134 Execute(Server should be notified on change):
135   call ale#events#FileChangedEvent(bufnr(''))
136
137   AssertEqual
138   \ [
139   \   [1, 'textDocument/didChange', {
140   \     'textDocument': {
141   \       'uri': ale#path#ToFileURI(expand('%:p')),
142   \       'version': g:ale_lsp_next_version_id - 1,
143   \     },
144   \     'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}],
145   \   }],
146   \ ],
147   \ g:message_list