diff --git a/.github/workflows/unitests.yml b/.github/workflows/unitests.yml index 55067165..3d1073d7 100644 --- a/.github/workflows/unitests.yml +++ b/.github/workflows/unitests.yml @@ -29,6 +29,9 @@ 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 @@ -36,12 +39,6 @@ jobs: 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 diff --git a/test/dummy-lsp/package-lock.json b/test/dummy-lsp/package-lock.json deleted file mode 100644 index f270f295..00000000 --- a/test/dummy-lsp/package-lock.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "dummy-lsp", - "version": "0.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "dummy-lsp", - "version": "0.0.0", - "dependencies": { - "vscode-languageserver": "^9.0.1", - "vscode-languageserver-textdocument": "^1.0.11" - } - }, - "node_modules/vscode-jsonrpc": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz", - "integrity": "sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==", - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/vscode-languageserver": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-9.0.1.tgz", - "integrity": "sha512-woByF3PDpkHFUreUa7Hos7+pUWdeWMXRd26+ZX2A8cFx6v/JPTtd4/uN0/jB6XQHYaOlHbio03NTHCqrgG5n7g==", - "dependencies": { - "vscode-languageserver-protocol": "3.17.5" - }, - "bin": { - "installServerIntoExtension": "bin/installServerIntoExtension" - } - }, - "node_modules/vscode-languageserver-protocol": { - "version": "3.17.5", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.5.tgz", - "integrity": "sha512-mb1bvRJN8SVznADSGWM9u/b07H7Ecg0I3OgXDuLdn307rl/J3A9YD6/eYOssqhecL27hK1IPZAsaqh00i/Jljg==", - "dependencies": { - "vscode-jsonrpc": "8.2.0", - "vscode-languageserver-types": "3.17.5" - } - }, - "node_modules/vscode-languageserver-textdocument": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.11.tgz", - "integrity": "sha512-X+8T3GoiwTVlJbicx/sIAF+yuJAqz8VvwJyoMVhwEMoEKE/fkDmrqUgDMyBECcM2A2frVZIUj5HI/ErRXCfOeA==" - }, - "node_modules/vscode-languageserver-types": { - "version": "3.17.5", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz", - "integrity": "sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==" - } - } -} diff --git a/test/dummy-lsp/package.json b/test/dummy-lsp/package.json deleted file mode 100644 index f6df0fff..00000000 --- a/test/dummy-lsp/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "dummy-lsp", - "version": "0.0.0", - "description": "Mock for LSP server", - "main": "server.js", - "dependencies": { - "vscode-languageserver": "^9.0.1", - "vscode-languageserver-textdocument": "^1.0.11" - } -} diff --git a/test/dummy-lsp/server.js b/test/dummy-lsp/server.js deleted file mode 100755 index 2ac3d339..00000000 --- a/test/dummy-lsp/server.js +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env node - -(async () => { - const { - createConnection, - TextDocuments, - ProposedFeatures, - } = await import('vscode-languageserver'); - const { - TextDocument, - } = await import('vscode-languageserver-textdocument'); - - async function main() { - const connection = createConnection(ProposedFeatures.all); - const documents = new TextDocuments(TextDocument); - - const settings = {}; - - connection.onInitialize((params) => { - - settings.hoverReply = params.initializationOptions?.hoverReply || 'DEFAULT'; - - const result = { - capabilities: { - hoverProvider: true, - } - }; - - return result; - }); - - connection.onHover(param => { - return { - contents: settings.hoverReply, - } - }) - - documents.listen(connection); - connection.listen(); - } - - await main(); -})() diff --git a/test/syntax_stack_lsp_chooser_test.vim b/test/syntax_stack_lsp_chooser_test.vim index 1289faf6..943f5ef0 100644 --- a/test/syntax_stack_lsp_chooser_test.vim +++ b/test/syntax_stack_lsp_chooser_test.vim @@ -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 "\" contained - autocmd Syntax dummy syn keyword DummyB DummyKwB contained | - \ syn match DummyKwB "\" 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 =<< 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 = 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