Skip to content

Commit

Permalink
Fix test for syntax associated lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
Indelog committed Apr 10, 2024
1 parent 33e3b3f commit 810a53e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 194 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/unitests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@ jobs:
mkdir -p ~/.local/bin
curl -L https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip -c - > ~/.local/bin/rust-analyzer
chmod +x ~/.local/bin/rust-analyzer
# install markdown language server
curl -L https://github.com/artempyanykh/marksman/releases/latest/download/marksman-linux-x64 -o ~/.local/bin/marksman
chmod +x ~/.local/bin/marksman
- name: Setup Vim
uses: rhysd/action-setup-vim@v1
id: vim
with:
version: ${{ matrix.vim }}
- name: Checkout LSP plugin Code
uses: actions/checkout@v4
- name: Prepare Tests
run: |
# install deps for the dummy lsp
cd ./test/dummy-lsp/
npm install
cd -
- name: Run Tests
run: |
uname -a
~/.local/bin/rust-analyzer --version
export VIMPRG=${{ steps.vim.outputs.executable }}
$VIMPRG --version
cd test
echo 'THIS IS FOR DEBUG PURPOSE, THIS WILL BE REMOVED'
cat /tmp/mytest
./run_tests.sh
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ test/X*.cpp
# test/Xtest.c
# test/Xtest.cpp
test/results.txt
test/dummy-lsp/node_modules/
6 changes: 6 additions & 0 deletions autoload/lsp/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ enddef
def SelectLSPBySyntaxNames(possibleLSPs: list<dict<any>>): dict<any>
var synnameStack = util.ListSynstackNamesAtPoint(line('.'), col('.'))->reverse()

writefile([json_encode(synnameStack)], '/tmp/mytest', 'a')

if synnameStack->empty()
return {}
endif
Expand Down Expand Up @@ -237,6 +239,10 @@ def SelectLSPBySyntaxNames(possibleLSPs: list<dict<any>>): dict<any>
endfor
endfor

if ! selected->empty()
writefile([selected.name, selected.path], '/tmp/mytest', 'a')
endif

return selected
enddef

Expand Down
54 changes: 0 additions & 54 deletions test/dummy-lsp/package-lock.json

This file was deleted.

10 changes: 0 additions & 10 deletions test/dummy-lsp/package.json

This file was deleted.

43 changes: 0 additions & 43 deletions test/dummy-lsp/server.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi

VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term"

TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim rust_tests.vim syntax_stack_lsp_chooser_test.vim"
TESTS="syntax_stack_lsp_chooser_test.vim"

RunTestsInFile() {
testfile=$1
Expand Down
112 changes: 33 additions & 79 deletions test/syntax_stack_lsp_chooser_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,61 @@ vim9script
import '../autoload/lsp/buffer.vim' as buf
import '../autoload/lsp/util.vim' as util

augroup dummy_syntax
autocmd BufRead,BufNewFile *.dummy setlocal ft=dummy
autocmd FileType dummy syntax region DummyA start='start_a' end='end_a' contains=DummyB,DummyKwA
autocmd FileType dummy syntax region DummyB start='start_b' end='end_b' contains=DummyKwB,DummyA
autocmd Syntax dummy syn keyword DummyA DummyKwA contained |
\ syn match DummyKwA "\<dummy_a\>" contained
autocmd Syntax dummy syn keyword DummyB DummyKwB contained |
\ syn match DummyKwB "\<dummy_b\>" contained
augroup end

source common.vim

g:markdown_fenced_languages = ['c']

var lspServers = [
{
name: 'default',
filetype: 'dummy',
path: expand('%:p:h') .. '/dummy-lsp/server.js',
args: ['--stdio'],
initializationOptions: {hoverReply: 'default'},
name: 'marksman',
filetype: 'markdown',
path: (exepath('marksman') ?? expand('~') .. '/.local/bin/marksman'),
args: ['server'],
},
{
name: 'dummy_a',
filetype: 'dummy',
path: expand('%:p:h') .. '/dummy-lsp/server.js',
args: ['--stdio'],
initializationOptions: {hoverReply: 'dummy_a'},
syntaxAssociatedLSP: [
'DummyA',
],
},
{
name: 'dummy_b',
filetype: 'dummy',
path: expand('%:p:h') .. '/dummy-lsp/server.js',
args: ['--stdio'],
initializationOptions: {hoverReply: 'dummy_b'},
syntaxAssociatedLSP: [
'DummyB',
],
name: 'clangd',
filetype: 'markdown',
path: (exepath('clangd-15') ?? exepath('clangd')),
args: ['--background-index', '--clang-tidy'],
syntaxAssociatedLSP: ['markdownHighlight_c'],

},
]
call LspAddServer(lspServers)

def FillDummyFile()
:silent edit mock.dummy
:silent edit dummy.md
sleep 200m
var items = [
'start_a',
'dummy_a',
'start_b',
'start_a',
'dummy_a',
'end_a',
'dummy_b',
'end_b',
'end_a',
'default',
]
setline(1, items->join(' '))
enddef

def g:Test_DoNotChooseLsp_if_no_matching_syntax_found()
FillDummyFile()
search('default')
var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover')
assert_true(selected_lsp->has_key('name'))
assert_equal(selected_lsp.name, 'default')
var lines: list<string> =<< trim END
# Title

```c
int f1() {
int x;
int y;
x = 1;
y = 2;
return x + y;
}
```
END
setline(1, lines)
enddef

def g:Test_ChooseLsp_using_topmost_syntax_item()
def g:Test_ChoseDefaultLspIfNoSyntaxMatch()
FillDummyFile()
search('dummy_a')
search('Title')
var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover')
assert_true(selected_lsp->has_key('name'))
assert_equal(selected_lsp.name, 'dummy_a')
assert_equal(selected_lsp.name, 'marksman')
enddef

def g:Test_ChooseCorrectLsp_for_nested_syntax_element()
def g:Test_ChooseCorrectLspIfSyntaxMatch()
FillDummyFile()
search('dummy_b')
search('int')
var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover')
assert_true(selected_lsp->has_key('name'))
assert_equal(selected_lsp.name, 'dummy_b')
enddef

def g:Test_ChooseCorrectLsp_for_deeply_nested_syntax_element()
FillDummyFile()
search('dummy_a')
search('dummy_a')
var selected_lsp = buf.BufLspServerGet(bufnr(), 'hover')
assert_true(selected_lsp->has_key('name'))
assert_equal(selected_lsp.name, 'dummy_a')
enddef

def g:TestCallsCorrectLsp_on_hover()
FillDummyFile()
search('dummy_b')
var output = execute(':LspHover')->split("\n")
var p: list<number> = popup_list()
assert_equal(1, p->len())
assert_equal(['dummy_b'], getbufline(winbufnr(p[0]), 1, '$'))
assert_equal(selected_lsp.name, 'clangd')
enddef

# Only here to because the test runner needs it
Expand Down

0 comments on commit 810a53e

Please sign in to comment.