Skip to content

Commit 76d0e2d

Browse files
committed
feat: openscad-lsp support
1 parent 9e2efaa commit 76d0e2d

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
" Author: Johan Niklasson <johan@niklasson-embedded.se>
2+
" Description: openscad-lsp support for OpenSCAD
3+
4+
call ale#Set('openscad_openscad_lsp_executable', 'openscad-lsp')
5+
call ale#Set('openscad_openscad_lsp_use_global', get(g:, 'ale_use_global_executables', 0))
6+
call ale#Set('openscad_openscad_lsp_options', '')
7+
8+
function! ale_linters#openscad#openscad_lsp#GetProjectRoot(buffer) abort
9+
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
10+
11+
if !empty(l:git_path)
12+
return fnamemodify(l:git_path, ':h')
13+
endif
14+
15+
let l:buf_dir = fnamemodify(bufname(a:buffer), ':p:h')
16+
17+
return !empty(l:buf_dir) ? l:buf_dir : getcwd()
18+
endfunction
19+
20+
call ale#linter#Define('openscad', {
21+
\ 'name': 'openscad_lsp',
22+
\ 'lsp': 'stdio',
23+
\ 'executable': {b -> ale#path#FindExecutable(b, 'openscad_openscad_lsp', [
24+
\ 'openscad-lsp',
25+
\ ])},
26+
\ 'command': {b -> '%e --stdio' . ale#Pad(ale#Var(b, 'openscad_openscad_lsp_options'))},
27+
\ 'project_root': function('ale_linters#openscad#openscad_lsp#GetProjectRoot'),
28+
\})

doc/ale-openscad.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22
ALE OpenSCAD Integration *ale-openscad-options*
33

44

5+
===============================================================================
6+
openscad-lsp *ale-openscad-openscad_lsp*
7+
8+
`openscad-lsp` is a Language Server Protocol implementation for OpenSCAD.
9+
10+
g:ale_openscad_openscad_lsp_executable *g:ale_openscad_openscad_lsp_executable*
11+
*b:ale_openscad_openscad_lsp_executable*
12+
Type: |String|
13+
Default: `'openscad-lsp'`
14+
15+
This variable can be changed to use a different executable for openscad-lsp.
16+
17+
18+
g:ale_openscad_openscad_lsp_options *g:ale_openscad_openscad_lsp_options*
19+
*b:ale_openscad_openscad_lsp_options*
20+
Type: |String|
21+
Default: `''`
22+
23+
This variable can be changed to pass additional flags to openscad-lsp.
24+
25+
526
===============================================================================
627
sca2d *ale-openscad-sca2d*
728

doc/ale-supported-languages-and-tools.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ Notes:
504504
* `yamllint`
505505
* OpenSCAD
506506
* `SCA2D`
507+
* `openscad-lsp`
507508
* `scadformat`
508509
* Packer
509510
* `packer-fmt-fixer`

supported-tools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ formatting.
514514
* [yamllint](https://yamllint.readthedocs.io/)
515515
* OpenSCAD
516516
* [SCA2D](https://gitlab.com/bath_open_instrumentation_group/sca2d) :floppy_disk:
517+
* [openscad-lsp](https://github.com/Leathong/openscad-LSP)
517518
* [scadformat](https://github.com/hugheaves/scadformat)
518519
* Packer (HCL)
519520
* [packer-fmt-fixer](https://github.com/hashicorp/packer)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Before:
2+
call ale#assert#SetUpLinterTest('openscad', 'openscad_lsp')
3+
4+
After:
5+
call ale#assert#TearDownLinterTest()
6+
7+
Execute(The default command should be correct):
8+
AssertLinter 'openscad-lsp', ale#Escape('openscad-lsp') . ' --stdio'
9+
10+
Execute(The executable should be configurable):
11+
let g:ale_openscad_openscad_lsp_executable = '/custom/path/openscad-lsp'
12+
13+
AssertLinter '/custom/path/openscad-lsp',
14+
\ ale#Escape('/custom/path/openscad-lsp') . ' --stdio'
15+
16+
Execute(Options should be appended to the command):
17+
let b:ale_openscad_openscad_lsp_options = '--ignore-default'
18+
19+
AssertLinter 'openscad-lsp',
20+
\ ale#Escape('openscad-lsp') . ' --stdio --ignore-default'

0 commit comments

Comments
 (0)