From 3fc3c1ddaaef198d911106d6a30b3e398193e17f Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 23 Sep 2024 14:55:23 +0200 Subject: [PATCH] Add support for c3-lsp linter Add support for c3-lang with the c3-lsp language server. Link: http://github.com/pherrymason/c3-lsp Link: http://c3-lang.org --- ale_linters/c3/c3lsp.vim | 14 +++++++++++++ autoload/ale/handlers/c3lsp.vim | 19 +++++++++++++++++ doc/ale-c3.txt | 25 +++++++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 2 ++ doc/ale.txt | 2 ++ supported-tools.md | 2 ++ test/linter/test_c3_c3lsp.vader | 16 +++++++++++++++ 7 files changed, 80 insertions(+) create mode 100644 ale_linters/c3/c3lsp.vim create mode 100644 autoload/ale/handlers/c3lsp.vim create mode 100644 doc/ale-c3.txt create mode 100644 test/linter/test_c3_c3lsp.vader diff --git a/ale_linters/c3/c3lsp.vim b/ale_linters/c3/c3lsp.vim new file mode 100644 index 0000000000..58ec07bd2d --- /dev/null +++ b/ale_linters/c3/c3lsp.vim @@ -0,0 +1,14 @@ +" Author: Koni Marti +" Description: A Language Server implementation for C3 + +call ale#Set('c3_c3lsp_executable', 'c3-lsp') +call ale#Set('c3_c3lsp_init_options', {}) + +call ale#linter#Define('c3', { +\ 'name': 'c3lsp', +\ 'lsp': 'stdio', +\ 'executable': {b -> ale#Var(b, 'c3_c3lsp_executable')}, +\ 'command': '%e', +\ 'project_root': function('ale#handlers#c3lsp#GetProjectRoot'), +\ 'lsp_config': {b -> ale#handlers#c3lsp#GetInitOpts(b, 'c3_c3lsp_init_options')}, +\}) diff --git a/autoload/ale/handlers/c3lsp.vim b/autoload/ale/handlers/c3lsp.vim new file mode 100644 index 0000000000..3405daf947 --- /dev/null +++ b/autoload/ale/handlers/c3lsp.vim @@ -0,0 +1,19 @@ +scriptencoding utf-8 +" Author: Koni Marti +" Description: Utilities for c3-lsp + +function! ale#handlers#c3lsp#GetProjectRoot(buffer) abort + let l:config = ale#path#FindNearestFile(a:buffer, 'project.json') + + if !empty(l:config) + return fnamemodify(l:config, ':h') + endif + + return expand('#' . a:buffer . ':p:h') +endfunction + +function! ale#handlers#c3lsp#GetInitOpts(buffer, init_options_var) abort + let l:init_options = {} + + return extend(l:init_options, ale#Var(a:buffer, a:init_options_var)) +endfunction diff --git a/doc/ale-c3.txt b/doc/ale-c3.txt new file mode 100644 index 0000000000..319d282e75 --- /dev/null +++ b/doc/ale-c3.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE C3 Integration *ale-c3-options* + +=============================================================================== +c3-lsp *ale-c3-c3lsp* + +g:ale_c3_c3lsp_executable *g:ale_c3_c3lsp_executable* + *b:ale_c3_c3lsp_executable* + Type: |String| + Default: `c3-lsp` + + This variable can be changed to set the path to c3-lsp. + + +g:ale_c3_c3lsp_init_options *g:ale_c3_c3lsp_init_options* + *b:ale_c3_c3lsp_init_options* + Type: |Dictionary| + Default: `{}` + + Dictionary containing configuration settings that will be passed to the + language server. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index ec787d22f1..09af09a936 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -143,6 +143,8 @@ Notes: * `cypher-lint` * Cython (pyrex filetype) * `cython` +* C3 + * `c3-lsp` * D * `dfmt` * `dls` diff --git a/doc/ale.txt b/doc/ale.txt index d9be76821b..b616258bd9 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2979,6 +2979,8 @@ documented in additional help files. clang-format..........................|ale-cuda-clangformat| clangd................................|ale-cuda-clangd| nvcc..................................|ale-cuda-nvcc| + c3......................................|ale-c3-options| + c3-lsp................................|ale-c3-c3lsp| d.......................................|ale-d-options| dfmt..................................|ale-d-dfmt| dls...................................|ale-d-dls| diff --git a/supported-tools.md b/supported-tools.md index f49b5a02ab..a2d0aa8e6e 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -152,6 +152,8 @@ formatting. * [cypher-lint](https://github.com/cleishm/libcypher-parser) * Cython (pyrex filetype) * [cython](http://cython.org/) +* C3 + * [c3-lsp](https://github.com/pherrymason/c3-lsp) * D * [dfmt](https://github.com/dlang-community/dfmt) * [dls](https://github.com/d-language-server/dls) diff --git a/test/linter/test_c3_c3lsp.vader b/test/linter/test_c3_c3lsp.vader new file mode 100644 index 0000000000..32b9dfdf10 --- /dev/null +++ b/test/linter/test_c3_c3lsp.vader @@ -0,0 +1,16 @@ +Before: + call ale#assert#SetUpLinterTest('c3', 'c3lsp') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default c3-lsp settings should be correct): + AssertLinter 'c3-lsp', ale#Escape('c3-lsp') + AssertLSPConfig {} + +Execute(c3-lsp should be configurable): + let b:ale_c3_c3lsp_executable = 'billy' + let b:ale_c3_c3lsp_init_options = {'x': 'y'} + + AssertLinter 'billy', ale#Escape('billy') + AssertLSPConfig {'x': 'y'}