summaryrefslogtreecommitdiff
path: root/test/lsp/test_lsp_root_detection.vader
blob: 291300f0be165fd983671e547f22ad08743dd8b1 (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
Before:
  Save g:ale_lsp_root
  Save g:ale_root
  Save b:ale_lsp_root
  Save b:ale_root

  unlet! g:ale_lsp_root
  let g:ale_root = {}

  call ale#assert#SetUpLinterTest('c', 'clangd')

  function! Hook1(buffer)
    return 'abc123'
  endfunction

After:
  Restore

  delfunction Hook1

  call ale#assert#TearDownLinterTest()

Execute(The buffer-specific variable can be a string):
  let b:ale_root = '/some/path'
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The buffer-specific variable can be a dictionary):
  let b:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The buffer-specific variable can have funcrefs):
  let b:ale_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject 'abc123'

Execute(The buffer-specific variable can be the old ale_lsp_root setting):
  let b:ale_lsp_root = '/some/path'
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The global variable can be a dictionary):
  let g:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The global variable can have funcrefs):
  let g:ale_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject 'abc123'

Execute(The buffer-specific variable overrides the global variable):
  let b:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
  let g:ale_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The global variable is queried if the buffer-specific has no value):
  let b:ale_root = {'golangserver': '/other/path'}
  let g:ale_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(The global variable can be the old ale_lsp_root setting):
  let g:ale_root = {}
  let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(A non-empty ale_root setting should replace the old ale_lsp_root):
  let g:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
  let g:ale_lsp_root = {'clangd': '/xxx', 'golangserver': '/xxx'}
  call ale#test#SetFilename('other-file.c')

  AssertLSPProject '/some/path'

Execute(No path should be returned by default):
  call ale#test#SetFilename(tempname() . '/other-file.c')

  AssertLSPProject ''