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 9, 2024
1 parent 33e3b3f commit 3b08cf2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 192 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/unitests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ 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
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.

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: 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: '/usr/bin/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 3b08cf2

Please sign in to comment.