summaryrefslogtreecommitdiff
path: root/test/test_redundant_tsserver_rendering_avoided.vader
blob: 05660d4e1bc9e506704b74cb58823f27dd8ce3a9 (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
170
171
172
173
174
175
176
177
178
Before:
  Save g:ale_buffer_info
  Save g:ale_disable_lsp
  Save g:ale_lsp_suggestions

  let g:ale_disable_lsp = 0
  let g:ale_lsp_suggestions = 1
  unlet! b:ale_disable_lsp

  function! CreateError(type, message) abort
    let l:diagnostics = []

    if !empty(a:message)
      let l:diagnostics = [{
      \ 'start': {'line': 1, 'offset': 1},
      \ 'end': {'line': 1, 'offset':1},
      \ 'text': a:message,
      \ 'code': 1005,
      \}]
    endif

    return {
    \ 'seq': 0,
    \ 'type': 'event',
    \ 'event': a:type,
    \ 'body': {'file': expand('%:p'), 'diagnostics': l:diagnostics},
    \}
  endfunction

  function! CreateLoclist(message) abort
    let l:list = []

    if !empty(a:message)
      let l:list = [{
      \ 'lnum': 1,
      \ 'col': 1,
      \ 'end_lnum': 1,
      \ 'end_col': 1,
      \ 'text': a:message,
      \}]
    endif

    return l:list
  endfunction

  call ale#test#SetDirectory('/testplugin/test')
  call ale#test#SetFilename('filename.ts')

  runtime autoload/ale/engine.vim

  let g:ale_buffer_info = {bufnr(''): {'loclist': [], 'active_linter_list': []}}
  let g:ale_handle_loclist_called = 0

  function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort
    let g:ale_handle_loclist_called = 1
  endfunction

After:
  Restore

  delfunction CreateError
  delfunction CreateLoclist

  call ale#test#RestoreDirectory()

  runtime autoload/ale/engine.vim

Execute(An initial empty list of syntax errors should be ignored):
  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))

  Assert !g:ale_handle_loclist_called

Execute(An initial list of syntax errors should be handled):
  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Subsequent empty lists should be ignored):
  let g:ale_buffer_info[bufnr('')].syntax_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))

  Assert !g:ale_handle_loclist_called

Execute(Empty then non-empty syntax errors should be handled):
  let g:ale_buffer_info[bufnr('')].syntax_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then empty syntax errors should be handled):
  let g:ale_buffer_info[bufnr('')].syntax_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then non-empty syntax errors should be handled):
  let g:ale_buffer_info[bufnr('')].syntax_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(An initial empty list of semantic errors should be ignored):
  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))

  Assert !g:ale_handle_loclist_called

Execute(An initial list of semantic errors should be handled):
  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Subsequent empty lists should be ignored - semantic):
  let g:ale_buffer_info[bufnr('')].semantic_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))

  Assert !g:ale_handle_loclist_called

Execute(Empty then non-empty semantic errors should be handled):
  let g:ale_buffer_info[bufnr('')].semantic_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then empty semantic errors should be handled):
  let g:ale_buffer_info[bufnr('')].semantic_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then non-empty semantic errors should be handled):
  let g:ale_buffer_info[bufnr('')].semantic_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Subsequent empty lists should be ignored - suggestion):
  let g:ale_buffer_info[bufnr('')].suggestion_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('suggestionDiag', ''))

  Assert !g:ale_handle_loclist_called

Execute(You should be able to disable suggestions):
  let g:ale_lsp_suggestions = 0
  let g:ale_buffer_info[bufnr('')].suggestion_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('suggestionDiag', 'x'))

  Assert !g:ale_handle_loclist_called

Execute(Empty then non-empty suggestion messages should be handled):
  let g:ale_buffer_info[bufnr('')].suggestion_loclist = []

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('suggestionDiag', 'x'))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then empt suggestion messages should be handled):
  let g:ale_buffer_info[bufnr('')].suggestion_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('suggestionDiag', ''))

  Assert g:ale_handle_loclist_called

Execute(Non-empty then non-empty suggestion messages should be handled):
  let g:ale_buffer_info[bufnr('')].suggestion_loclist = CreateLoclist('x')

  call ale#lsp_linter#HandleLSPResponse(1, CreateError('suggestionDiag', 'x'))

  Assert g:ale_handle_loclist_called