summaryrefslogtreecommitdiff
path: root/test/lsp/test_reset_lsp.vader
blob: c6be47e60dc649435e80c4f05d9e518ea65a14eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Before:
  Save g:ale_enabled
  Save g:ale_set_signs
  Save g:ale_set_quickfix
  Save g:ale_set_loclist
  Save g:ale_set_highlights
  Save g:ale_echo_cursor
  Save g:ale_buffer_info

  let g:ale_enabled = 0
  let g:ale_set_signs = 0
  let g:ale_set_quickfix = 0
  let g:ale_set_loclist = 0
  let g:ale_set_highlights = 0
  let g:ale_echo_cursor = 0
  let g:expr_list = []

  function EmptyString() abort
    return ''
  endfunction

  runtime autoload/ale/util.vim

  function! ale#util#Execute(expr) abort
    call add(g:expr_list, a:expr)
  endfunction

  call ale#engine#InitBufferInfo(bufnr(''))
  " Call this function first, to clear LSP data.
  call ale#lsp_linter#ClearLSPData()

  call ale#linter#Define('testft', {
  \   'name': 'lsplinter',
  \   'lsp': 'tsserver',
  \   'executable': function('EmptyString'),
  \   'command': function('EmptyString'),
  \   'project_root': function('EmptyString'),
  \   'language': function('EmptyString'),
  \})
  call ale#linter#Define('testft', {
  \   'name': 'lsplinter2',
  \   'lsp': 'tsserver',
  \   'executable': function('EmptyString'),
  \   'command': function('EmptyString'),
  \   'project_root': function('EmptyString'),
  \   'language': function('EmptyString'),
  \})
  call ale#linter#Define('testft', {
  \ 'name': 'otherlinter',
  \ 'callback': 'TestCallback',
  \ 'executable': has('win32') ? 'cmd': 'true',
  \ 'command': 'true',
  \ 'read_buffer': 0,
  \})

After:
  Restore

  delfunction EmptyString
  unlet! g:expr_list
  unlet! b:ale_save_event_fired

  " Clear LSP data after tests.
  call ale#lsp_linter#ClearLSPData()

  runtime autoload/ale/util.vim

  call ale#linter#Reset()

Given testft(Some file with an imaginary filetype):
Execute(ALEStopAllLSPs should clear the loclist):
  " For these tests we only need to set the keys we need.
  let g:ale_buffer_info[bufnr('')].loclist = [
  \ {'linter_name': 'lsplinter'},
  \ {'linter_name': 'otherlinter'},
  \]
  let g:ale_buffer_info[bufnr('')].active_linter_list = [
  \ {'name': 'lsplinter'},
  \ {'name': 'otherlinter'},
  \]

  ALEStopAllLSPs

  " The loclist should be updated.
  AssertEqual
  \ ['otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')

  " The LSP linter should be removed from the active linter list.
  AssertEqual
  \ ['otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')

Execute(ALEStopLSP should stop a named LSP):
  let g:ale_buffer_info[bufnr('')].loclist = [
  \ {'linter_name': 'lsplinter'},
  \ {'linter_name': 'lsplinter2'},
  \ {'linter_name': 'otherlinter'},
  \]
  let g:ale_buffer_info[bufnr('')].active_linter_list = [
  \ {'name': 'lsplinter'},
  \ {'name': 'lsplinter2'},
  \ {'name': 'otherlinter'},
  \]
  call ale#lsp_linter#SetLSPLinterMap({
  \ 'conn1': {'name': 'lsplinter'},
  \ 'conn2': {'name': 'lsplinter2'},
  \ 'conn3': {'name': 'lsplinter'},
  \})

  ALEStopLSP lsplinter

  " We should remove only the items for this linter.
  AssertEqual
  \ ['lsplinter2', 'otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')

  " The linter should be removed from the active linter list.
  AssertEqual
  \ ['lsplinter2', 'otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')

  " The connections linters with this name should be removed.
  AssertEqual
  \ {'conn2': {'name': 'lsplinter2'}},
  \ ale#lsp_linter#GetLSPLinterMap()

Execute(ALEStopLSP should not clear results for linters not running):
  let g:ale_buffer_info[bufnr('')].loclist = [
  \ {'linter_name': 'lsplinter'},
  \ {'linter_name': 'otherlinter'},
  \]
  let g:ale_buffer_info[bufnr('')].active_linter_list = [
  \ {'name': 'lsplinter'},
  \ {'name': 'otherlinter'},
  \]

  ALEStopLSP lsplinter

  " We should emit a message saying the server isn't running.
  AssertEqual
  \ ['echom ''No running language server with name: lsplinter'''],
  \ g:expr_list

  " We should keep the linter items.
  AssertEqual
  \ ['lsplinter', 'otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
  AssertEqual
  \ ['lsplinter', 'otherlinter'],
  \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')

Execute(ALEStopLSP with a bang should not emit warnings):
  ALEStopLSP! lsplinter

  AssertEqual [], g:expr_list

Execute(ALEStopLSP's completion function should suggest running linter names):
  call ale#lsp_linter#SetLSPLinterMap({
  \ 'conn1': {'name': 'pyright'},
  \ 'conn2': {'name': 'pylsp'},
  \ 'conn3': {'name': 'imaginaryserver'},
  \})

  AssertEqual
  \ ['imaginaryserver', 'pylsp', 'pyright'],
  \ ale#lsp#reset#Complete('', '', 42)
  AssertEqual ['imaginaryserver'], ale#lsp#reset#Complete('inary', '', 42)
  AssertEqual ['pylsp'], ale#lsp#reset#Complete('LSP', '', 42)