Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for c3-lsp linter #4836

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ale_linters/c3/c3lsp.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
" Author: Koni Marti <[email protected]>
" 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')},
\})
19 changes: 19 additions & 0 deletions autoload/ale/handlers/c3lsp.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
scriptencoding utf-8
" Author: Koni Marti <[email protected]>
" 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
25 changes: 25 additions & 0 deletions doc/ale-c3.txt
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Notes:
* `flawfinder`
* `gcc` (`cc`)
* `uncrustify`
* C3
* `c3-lsp`
* Cairo
* `scarb`!!
* `starknet`
Expand Down
2 changes: 2 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 2 additions & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ formatting.
* [flawfinder](https://www.dwheeler.com/flawfinder/)
* [gcc](https://gcc.gnu.org/)
* [uncrustify](https://github.com/uncrustify/uncrustify)
* C3
* [c3-lsp](https://github.com/pherrymason/c3-lsp)
* Cairo
* [scarb](https://docs.swmansion.com/scarb/) :floppy_disk:
* [starknet](https://starknet.io/docs)
Expand Down
16 changes: 16 additions & 0 deletions test/linter/test_c3_c3lsp.vader
Original file line number Diff line number Diff line change
@@ -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'}