From ab0bf615123da5f5f7eb30d18ee34b0b317aa795 Mon Sep 17 00:00:00 2001 From: Andrew Hayworth Date: Mon, 22 Jul 2019 08:06:55 -0500 Subject: [PATCH] Add support for ink-language-server This commit add support for ink-language-server, which it does by largely copying and pasting from the pure-language-server PR that was merged recently. The most interesting things to note are: - ink-language-server is distributed upstream via npm, which is why we search through node_modules - With some coaxing, it can be installed globally - which is why we search for a global binary. - Ink is a funky language, and users will likely need to add initialization options. - I am not incredibly familiar with vimscript; and I may not have done some of the buffer searching correctly. --- ale_linters/ink/ls.vim | 35 ++++++++++++++++ doc/ale-ink.txt | 40 +++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 2 + doc/ale.txt | 2 + supported-tools.md | 2 + .../command_callback/ink_paths/story/main.ink | 0 .../test_ink_ls_command_callbacks.vader | 22 ++++++++++ 7 files changed, 103 insertions(+) create mode 100644 ale_linters/ink/ls.vim create mode 100644 doc/ale-ink.txt create mode 100644 test/command_callback/ink_paths/story/main.ink create mode 100644 test/command_callback/test_ink_ls_command_callbacks.vader diff --git a/ale_linters/ink/ls.vim b/ale_linters/ink/ls.vim new file mode 100644 index 00000000..1cc93583 --- /dev/null +++ b/ale_linters/ink/ls.vim @@ -0,0 +1,35 @@ +" Author: Andreww Hayworth +" Description: Integrate ALE with ink-language-server + +call ale#Set('ink_ls_executable', 'ink-language-server') +call ale#Set('ink_ls_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('ink_ls_initialization_options', {}) + +function! ale_linters#ink#ls#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'ink_ls', [ + \ 'ink-language-server', + \ 'node_modules/.bin/ink-language-server', + \]) +endfunction + +function! ale_linters#ink#ls#GetCommand(buffer) abort + let l:executable = ale_linters#ink#ls#GetExecutable(a:buffer) + + return ale#Escape(l:executable) . ' --stdio' +endfunction + +function! ale_linters#ink#ls#FindProjectRoot(buffer) abort + let l:main_file = get(ale#Var(a:buffer, 'ink_ls_initialization_options'), 'mainStoryPath', 'main.ink') + let l:config = ale#path#ResolveLocalPath(a:buffer, l:main_file, expand('#' . a:buffer . ':p')) + + return ale#path#Dirname(l:config) +endfunction + +call ale#linter#Define('ink', { +\ 'name': 'ink-language-server', +\ 'lsp': 'stdio', +\ 'executable': function('ale_linters#ink#ls#GetExecutable'), +\ 'command': function('ale_linters#ink#ls#GetCommand'), +\ 'project_root': function('ale_linters#ink#ls#FindProjectRoot'), +\ 'initialization_options': {b -> ale#Var(b, 'ink_ls_initialization_options')}, +\}) diff --git a/doc/ale-ink.txt b/doc/ale-ink.txt new file mode 100644 index 00000000..9412a09f --- /dev/null +++ b/doc/ale-ink.txt @@ -0,0 +1,40 @@ +=============================================================================== +ALE Ink Integration *ale-ink-options* + + +=============================================================================== +ink-language-server *ale-ink-language-server* + +Ink Language Server + (https://github.com/ephraim/ink-language-server) + +g:ale_ink_ls_executable g:ale_ink_ls_executable + b:ale_ink_ls_executable + Type: |String| + Default: `'ink-language-server'` + + Ink language server executable. + +g:ale_ink_ls_initialization_options + g:ale_ink_ls_initialization_options + b:ale_ink_ls_initialization_options + Type: |Dictionary| + Default: `{}` + + Dictionary containing configuration settings that will be passed to the + language server at startup. For certain platforms and certain story + structures, the defaults will suffice. However, many projects will need to + change these settings - see the ink-language-server website for more + information. + + An example of setting non-default options: + { + \ 'ink': { + \ 'mainStoryPath': 'init.ink', + \ 'inklecateExecutablePath': '/usr/local/bin/inklecate', + \ 'runThroughMono': v:false + \ } + \} + +=============================================================================== + 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 d39aaf7e..c6dc2aa7 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -198,6 +198,8 @@ Notes: * `write-good` * Idris * `idris` +* Ink + * `ink-language-server` * ISPC * `ispc`!! * Java diff --git a/doc/ale.txt b/doc/ale.txt index 5541236f..ba5d7b4a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2123,6 +2123,8 @@ documented in additional help files. write-good............................|ale-html-write-good| idris...................................|ale-idris-options| idris.................................|ale-idris-idris| + ink.....................................|ale-ink-options| + ink-language-server...................|ale-ink-language-server| ispc....................................|ale-ispc-options| ispc..................................|ale-ispc-ispc| java....................................|ale-java-options| diff --git a/supported-tools.md b/supported-tools.md index 6cb9f418..11328f7d 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -207,6 +207,8 @@ formatting. * [write-good](https://github.com/btford/write-good) * Idris * [idris](http://www.idris-lang.org/) +* Ink + * [ink-language-server](https://github.com/ephread/ink-language-server) * ISPC * [ispc](https://ispc.github.io/) :floppy_disk: * Java diff --git a/test/command_callback/ink_paths/story/main.ink b/test/command_callback/ink_paths/story/main.ink new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/test_ink_ls_command_callbacks.vader b/test/command_callback/test_ink_ls_command_callbacks.vader new file mode 100644 index 00000000..5074506c --- /dev/null +++ b/test/command_callback/test_ink_ls_command_callbacks.vader @@ -0,0 +1,22 @@ +Before: + call ale#assert#SetUpLinterTest('ink', 'ls') + set ft=ink + +After: + call ale#assert#TearDownLinterTest() + +Execute(should set correct defaults): + AssertLinter 'ink-language-server', ale#Escape('ink-language-server') . ' --stdio' + +Execute(should set correct LSP values): + call ale#test#SetFilename('ink_paths/story/main.ink') + + AssertLSPLanguage 'ink' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#path#Simplify(g:dir . '/ink_paths/story') + +Execute(should accept configuration settings): + AssertLSPConfig {} + let b:ale_ink_ls_initialization_options = {'ink': {'runThroughMono': v:true}} + AssertLSPOptions {'ink': {'runThroughMono': v:true}}