|
| 1 | +" don't spam the user when Vim is started in Vi compatibility mode |
| 2 | +let s:cpo_save = &cpo |
| 3 | +set cpo&vim |
| 4 | + |
| 5 | +scriptencoding utf-8 |
| 6 | + |
| 7 | +func! Test_SetBuildTags() abort |
| 8 | + if !go#util#has_job() |
| 9 | + return |
| 10 | + endif |
| 11 | + |
| 12 | + try |
| 13 | + let g:go_def_mode = 'gopls' |
| 14 | + let l:dir = 'test-fixtures/config/buildtags' |
| 15 | + let l:jumpstart = [0, 4, 2, 0] |
| 16 | + |
| 17 | + execute 'e ' . printf('%s/buildtags.go', l:dir) |
| 18 | + let l:jumpstartbuf = bufnr('') |
| 19 | + |
| 20 | + call setpos('.', [l:jumpstartbuf, l:jumpstart[1], l:jumpstart[2], 0]) |
| 21 | + |
| 22 | + let l:expectedfilename = printf('%s/foo.go', l:dir) |
| 23 | + |
| 24 | + let l:expected = [0, 5, 1, 0] |
| 25 | + call assert_notequal(l:expected, l:jumpstart) |
| 26 | + |
| 27 | + call go#def#Jump('', 0) |
| 28 | + |
| 29 | + let l:start = reltime() |
| 30 | + while getpos('.') != l:expected && reltimefloat(reltime(l:start)) < 10 |
| 31 | + sleep 100m |
| 32 | + endwhile |
| 33 | + |
| 34 | + call assert_equal(l:expectedfilename, bufname("%")) |
| 35 | + call assert_equal(l:expected, getpos('.')) |
| 36 | + |
| 37 | + execute 'e ' . printf('%s/buildtags.go', l:dir) |
| 38 | + |
| 39 | + " prepare to wait for the workspace/configuration request |
| 40 | + let g:go_debug=['lsp'] |
| 41 | + |
| 42 | + " set the build constraint |
| 43 | + call go#config#SetBuildTags('constrained') |
| 44 | + |
| 45 | + " wait for the workspace/configuration request |
| 46 | + let l:lsplog = getbufline('__GOLSP_LOG__', 1, '$') |
| 47 | + let l:start = reltime() |
| 48 | + while match(l:lsplog, 'workspace/configuration') == -1 && reltimefloat(reltime(l:start)) < 10 |
| 49 | + sleep 50m |
| 50 | + let l:lsplog = getbufline('__GOLSP_LOG__', 1, '$') |
| 51 | + endwhile |
| 52 | + unlet g:go_debug |
| 53 | + " close the __GOLSP_LOG__ window |
| 54 | + only |
| 55 | + |
| 56 | + " verify the cursor position within buildtags.go |
| 57 | + call setpos('.', [l:jumpstartbuf, l:jumpstart[1], l:jumpstart[2], 0]) |
| 58 | + call assert_equal(l:jumpstart, getpos('.')) |
| 59 | + |
| 60 | + let l:expectedfilename = printf('%s/constrainedfoo.go', l:dir) |
| 61 | + let l:expected = [0, 6, 1, 0] |
| 62 | + call assert_notequal(l:expected, l:jumpstart) |
| 63 | + |
| 64 | + call go#def#Jump('', 0) |
| 65 | + |
| 66 | + let l:start = reltime() |
| 67 | + while getpos('.') != l:expected && reltimefloat(reltime(l:start)) < 10 |
| 68 | + sleep 100m |
| 69 | + endwhile |
| 70 | + |
| 71 | + call assert_equal(l:expectedfilename, bufname("%")) |
| 72 | + call assert_equal(l:expected, getpos('.')) |
| 73 | + |
| 74 | + let l:lsplog = getbufline('__GOLSP_LOG__', 1, '$') |
| 75 | + |
| 76 | + finally |
| 77 | + unlet g:go_def_mode |
| 78 | + endtry |
| 79 | +endfunc |
| 80 | + |
| 81 | +" restore Vi compatibility settings |
| 82 | +let &cpo = s:cpo_save |
| 83 | +unlet s:cpo_save |
| 84 | + |
| 85 | +" vim: sw=2 ts=2 et |
0 commit comments