Add kotlin language server support (#1725)

* Add kotlin languageserver linter definition
* Added kotlin languageserver references in docs, fix missing !! on other linters
* Added Vader tests for root path detection in Kotlin Language Server
This commit is contained in:
MTDL9 2018-07-15 19:54:18 +02:00 committed by w0rp
parent a42999a639
commit 5df735555c
7 changed files with 83 additions and 2 deletions

View File

@ -133,7 +133,7 @@ formatting.
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) |
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) | JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) | | JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) |
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !!, [languageserver](https://github.com/fwcd/KotlinLanguageServer) see `:help ale-integration-kotlin` for configuration instructions |
| LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) |
| Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) |
| LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) |

View File

@ -0,0 +1,38 @@
" Author: MTDL9 <https://github.com/MTDL9>
" Description: Support for the Kotlin language server https://github.com/fwcd/KotlinLanguageServer
call ale#Set('kotlin_languageserver_executable', 'kotlin-language-server')
function! ale_linters#kotlin#languageserver#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'kotlin_languageserver_executable')
endfunction
function! ale_linters#kotlin#languageserver#GetCommand(buffer) abort
let l:executable = ale_linters#kotlin#languageserver#GetExecutable(a:buffer)
return ale#Escape(l:executable)
endfunction
function! ale_linters#kotlin#languageserver#GetProjectRoot(buffer) abort
let l:gradle_root = ale#gradle#FindProjectRoot(a:buffer)
if !empty(l:gradle_root)
return l:gradle_root
endif
let l:maven_pom_file = ale#path#FindNearestFile(a:buffer, 'pom.xml')
if !empty(l:maven_pom_file)
return fnamemodify(l:maven_pom_file, ':h')
endif
return ''
endfunction
call ale#linter#Define('kotlin', {
\ 'name': 'languageserver',
\ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#kotlin#languageserver#GetExecutable',
\ 'command_callback': 'ale_linters#kotlin#languageserver#GetCommand',
\ 'language': 'kotlin',
\ 'project_root_callback': 'ale_linters#kotlin#languageserver#GetProjectRoot',
\})

View File

@ -87,4 +87,19 @@ g:ale_kotlin_ktlint_rulesets *g:ale_kotlin_ktlint_rulesets*
let g:ale_kotlin_ktlint_rulesets = ['/path/to/custom-rulset.jar', let g:ale_kotlin_ktlint_rulesets = ['/path/to/custom-rulset.jar',
'com.ktlint.rulesets:mycustomrule:1.0.0'] 'com.ktlint.rulesets:mycustomrule:1.0.0']
===============================================================================
languageserver *ale-kotlin-languageserver*
g:ale_kotlin_languageserver_executable *g:ale_kotlin_languageserver_executable*
Type: |String|
Default: `''`
The kotlin-language-server executable.
Executables are located inside the bin/ folder of the language server
release.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -131,6 +131,7 @@ CONTENTS *ale-contents*
kotlin................................|ale-kotlin-options| kotlin................................|ale-kotlin-options|
kotlinc.............................|ale-kotlin-kotlinc| kotlinc.............................|ale-kotlin-kotlinc|
ktlint..............................|ale-kotlin-ktlint| ktlint..............................|ale-kotlin-ktlint|
languageserver......................|ale-kotlin-languageserver|
latex.................................|ale-latex-options| latex.................................|ale-latex-options|
write-good..........................|ale-latex-write-good| write-good..........................|ale-latex-write-good|
less..................................|ale-less-options| less..................................|ale-less-options|
@ -368,7 +369,7 @@ Notes:
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD` * Java: `checkstyle`, `javac`, `google-java-format`, `PMD`
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo` * JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo`
* JSON: `fixjson`, `jsonlint`, `jq`, `prettier` * JSON: `fixjson`, `jsonlint`, `jq`, `prettier`
* Kotlin: `kotlinc`, `ktlint` * Kotlin: `kotlinc`!!, `ktlint`!!, `languageserver`
* LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good` * LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good`
* Less: `lessc`, `prettier`, `stylelint` * Less: `lessc`, `prettier`, `stylelint`
* LLVM: `llc` * LLVM: `llc`

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,25 @@
Before:
call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/kotlin/languageserver.vim
After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(Detect root of gradle project with build.gradle correctly):
call ale#test#SetFilename('gradle-test-files/build-gradle-project/src/main/kotlin/dummy.kt')
AssertEqual
\ ale#path#Simplify(g:dir . '/gradle-test-files/build-gradle-project'),
\ ale_linters#kotlin#languageserver#GetProjectRoot(bufnr(''))
Execute(Detect root of maven project with pom.xml correctly):
call ale#test#SetFilename('maven-test-files/maven-kotlin-project/src/main/kotlin/dummy.kt')
AssertEqual
\ ale#path#Simplify(g:dir . '/maven-test-files/maven-kotlin-project'),
\ ale_linters#kotlin#languageserver#GetProjectRoot(bufnr(''))
Execute(Detect no root in case of non maven/gradle project):
call ale#test#SetFilename('gradle-test-files/non-gradle-project/src/main/kotlin/dummy.kt')
AssertEqual
\ '',
\ ale_linters#kotlin#languageserver#GetProjectRoot(bufnr(''))