]> git.madduck.net Git - etc/vim.git/blob - test/lsp/test_reset_lsp.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / lsp / test_reset_lsp.vader
1 Before:
2   Save g:ale_enabled
3   Save g:ale_set_signs
4   Save g:ale_set_quickfix
5   Save g:ale_set_loclist
6   Save g:ale_set_highlights
7   Save g:ale_echo_cursor
8   Save g:ale_buffer_info
9
10   let g:ale_enabled = 0
11   let g:ale_set_signs = 0
12   let g:ale_set_quickfix = 0
13   let g:ale_set_loclist = 0
14   let g:ale_set_highlights = 0
15   let g:ale_echo_cursor = 0
16   let g:expr_list = []
17
18   function EmptyString() abort
19     return ''
20   endfunction
21
22   runtime autoload/ale/util.vim
23
24   function! ale#util#Execute(expr) abort
25     call add(g:expr_list, a:expr)
26   endfunction
27
28   call ale#engine#InitBufferInfo(bufnr(''))
29   " Call this function first, to clear LSP data.
30   call ale#lsp_linter#ClearLSPData()
31
32   call ale#linter#Define('testft', {
33   \   'name': 'lsplinter',
34   \   'lsp': 'tsserver',
35   \   'executable': function('EmptyString'),
36   \   'command': function('EmptyString'),
37   \   'project_root': function('EmptyString'),
38   \   'language': function('EmptyString'),
39   \})
40   call ale#linter#Define('testft', {
41   \   'name': 'lsplinter2',
42   \   'lsp': 'tsserver',
43   \   'executable': function('EmptyString'),
44   \   'command': function('EmptyString'),
45   \   'project_root': function('EmptyString'),
46   \   'language': function('EmptyString'),
47   \})
48   call ale#linter#Define('testft', {
49   \ 'name': 'otherlinter',
50   \ 'callback': 'TestCallback',
51   \ 'executable': has('win32') ? 'cmd': 'true',
52   \ 'command': 'true',
53   \ 'read_buffer': 0,
54   \})
55
56 After:
57   Restore
58
59   delfunction EmptyString
60   unlet! g:expr_list
61   unlet! b:ale_save_event_fired
62
63   " Clear LSP data after tests.
64   call ale#lsp_linter#ClearLSPData()
65
66   runtime autoload/ale/util.vim
67
68   call ale#linter#Reset()
69
70 Given testft(Some file with an imaginary filetype):
71 Execute(ALEStopAllLSPs should clear the loclist):
72   " For these tests we only need to set the keys we need.
73   let g:ale_buffer_info[bufnr('')].loclist = [
74   \ {'linter_name': 'lsplinter'},
75   \ {'linter_name': 'otherlinter'},
76   \]
77   let g:ale_buffer_info[bufnr('')].active_linter_list = [
78   \ {'name': 'lsplinter'},
79   \ {'name': 'otherlinter'},
80   \]
81
82   ALEStopAllLSPs
83
84   " The loclist should be updated.
85   AssertEqual
86   \ ['otherlinter'],
87   \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
88
89   " The LSP linter should be removed from the active linter list.
90   AssertEqual
91   \ ['otherlinter'],
92   \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
93
94 Execute(ALEStopLSP should stop a named LSP):
95   let g:ale_buffer_info[bufnr('')].loclist = [
96   \ {'linter_name': 'lsplinter'},
97   \ {'linter_name': 'lsplinter2'},
98   \ {'linter_name': 'otherlinter'},
99   \]
100   let g:ale_buffer_info[bufnr('')].active_linter_list = [
101   \ {'name': 'lsplinter'},
102   \ {'name': 'lsplinter2'},
103   \ {'name': 'otherlinter'},
104   \]
105   call ale#lsp_linter#SetLSPLinterMap({
106   \ 'conn1': {'name': 'lsplinter'},
107   \ 'conn2': {'name': 'lsplinter2'},
108   \ 'conn3': {'name': 'lsplinter'},
109   \})
110
111   ALEStopLSP lsplinter
112
113   " We should remove only the items for this linter.
114   AssertEqual
115   \ ['lsplinter2', 'otherlinter'],
116   \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
117
118   " The linter should be removed from the active linter list.
119   AssertEqual
120   \ ['lsplinter2', 'otherlinter'],
121   \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
122
123   " The connections linters with this name should be removed.
124   AssertEqual
125   \ {'conn2': {'name': 'lsplinter2'}},
126   \ ale#lsp_linter#GetLSPLinterMap()
127
128 Execute(ALEStopLSP should not clear results for linters not running):
129   let g:ale_buffer_info[bufnr('')].loclist = [
130   \ {'linter_name': 'lsplinter'},
131   \ {'linter_name': 'otherlinter'},
132   \]
133   let g:ale_buffer_info[bufnr('')].active_linter_list = [
134   \ {'name': 'lsplinter'},
135   \ {'name': 'otherlinter'},
136   \]
137
138   ALEStopLSP lsplinter
139
140   " We should emit a message saying the server isn't running.
141   AssertEqual
142   \ ['echom ''No running language server with name: lsplinter'''],
143   \ g:expr_list
144
145   " We should keep the linter items.
146   AssertEqual
147   \ ['lsplinter', 'otherlinter'],
148   \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
149   AssertEqual
150   \ ['lsplinter', 'otherlinter'],
151   \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
152
153 Execute(ALEStopLSP with a bang should not emit warnings):
154   ALEStopLSP! lsplinter
155
156   AssertEqual [], g:expr_list
157
158 Execute(ALEStopLSP's completion function should suggest running linter names):
159   call ale#lsp_linter#SetLSPLinterMap({
160   \ 'conn1': {'name': 'pyright'},
161   \ 'conn2': {'name': 'pylsp'},
162   \ 'conn3': {'name': 'imaginaryserver'},
163   \})
164
165   AssertEqual
166   \ ['imaginaryserver', 'pylsp', 'pyright'],
167   \ ale#lsp#reset#Complete('', '', 42)
168   AssertEqual ['imaginaryserver'], ale#lsp#reset#Complete('inary', '', 42)
169   AssertEqual ['pylsp'], ale#lsp#reset#Complete('LSP', '', 42)