Merge pull request #3069 from nelsyeung/feature/dart-analysis-server

Add dart analysis server to linter
This commit is contained in:
Horacio Sanson 2021-01-23 01:47:38 +09:00 committed by GitHub
commit 1b010bbabb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,29 @@
" Author: Nelson Yeung <nelsyeung@gmail.com>
" Description: Check Dart files with dart analysis server LSP
call ale#Set('dart_analysis_server_executable', 'dart')
function! ale_linters#dart#analysis_server#GetProjectRoot(buffer) abort
" Note: pub only looks for pubspec.yaml, there's no point in adding
" support for pubspec.yml
let l:pubspec = ale#path#FindNearestFile(a:buffer, 'pubspec.yaml')
return !empty(l:pubspec) ? fnamemodify(l:pubspec, ':h:h') : '.'
endfunction
function! ale_linters#dart#analysis_server#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'dart_analysis_server_executable')
let l:dart = resolve(exepath(l:executable))
return '%e '
\ . fnamemodify(l:dart, ':h') . '/snapshots/analysis_server.dart.snapshot'
\ . ' --lsp'
endfunction
call ale#linter#Define('dart', {
\ 'name': 'analysis_server',
\ 'lsp': 'stdio',
\ 'executable': {b -> ale#Var(b, 'dart_analysis_server_executable')},
\ 'command': function('ale_linters#dart#analysis_server#GetCommand'),
\ 'project_root': function('ale_linters#dart#analysis_server#GetProjectRoot'),
\})

View File

@ -2,6 +2,31 @@
ALE Dart Integration *ale-dart-options*
===============================================================================
analysis_server *ale-dart-analysis_server*
Installation
-------------------------------------------------------------------------------
Install Dart via whatever means. `analysis_server` will be included in the SDK.
In case that `dart` is not in your path, try to set the executable option to
its absolute path. : >
" Set the executable path for dart to the absolute path to it.
let g:ale_dart_analysis_server_executable = '/usr/local/bin/dart'
<
Options
-------------------------------------------------------------------------------
g:ale_dart_analysis_server_executable *g:ale_dart_analysis_server_executable*
*b:ale_dart_analysis_server_executable*
Type: |String|
Default: `'dart'`
This variable can be set to change the path of dart.
===============================================================================
dartanalyzer *ale-dart-dartanalyzer*

View File

@ -116,6 +116,7 @@ Notes:
* Dafny
* `dafny`!!
* Dart
* `analysis_server`
* `dartanalyzer`!!
* `dartfmt`!!
* `language_server`

View File

@ -2664,6 +2664,7 @@ documented in additional help files.
dafny...................................|ale-dafny-options|
dafny.................................|ale-dafny-dafny|
dart....................................|ale-dart-options|
analysis_server.......................|ale-dart-analysis_server|
dartanalyzer..........................|ale-dart-dartanalyzer|
dartfmt...............................|ale-dart-dartfmt|
dhall...................................|ale-dhall-options|

View File

@ -125,6 +125,7 @@ formatting.
* Dafny
* [dafny](https://rise4fun.com/Dafny) :floppy_disk:
* Dart
* [analysis_server](https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server)
* [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) :floppy_disk:
* [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt)
* [language_server](https://github.com/natebosch/dart_language_server)

View File

@ -0,0 +1,15 @@
Before:
call ale#assert#SetUpLinterTest('dart', 'analysis_server')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct):
AssertLinter 'dart', ale#Escape('dart')
\ . ' ./snapshots/analysis_server.dart.snapshot --lsp'
Execute(The executable should be configurable):
let g:ale_dart_analysis_server_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar')
\ . ' ./snapshots/analysis_server.dart.snapshot --lsp'