diff options
Diffstat (limited to 'autoload/dart.vim')
-rw-r--r-- | autoload/dart.vim | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/autoload/dart.vim b/autoload/dart.vim index 959b67ca..a5733d03 100644 --- a/autoload/dart.vim +++ b/autoload/dart.vim @@ -31,9 +31,9 @@ endfunction function! dart#fmt(...) abort let l:dartfmt = s:FindDartFmt() - if type(l:dartfmt) != type('') | return | endif + if empty(l:dartfmt) | return | endif let buffer_content = getline(1, '$') - let l:cmd = [l:dartfmt, '--stdin-name', shellescape(expand('%'))] + let l:cmd = extend(l:dartfmt, ['--stdin-name', shellescape(expand('%'))]) if exists('g:dartfmt_options') call extend(l:cmd, g:dartfmt_options) endif @@ -64,14 +64,30 @@ function! dart#fmt(...) abort endfunction function! s:FindDartFmt() abort - if executable('dartfmt') | return 'dartfmt' | endif + if executable('dart') + let l:version_text = system('dart --version') + let l:match = matchlist(l:version_text, + \ '\vDart SDK version: (\d+)\.(\d+)\.\d+.*') + if empty(l:match) + call s:error('Unable to determine dart version') + return [] + endif + let l:major = l:match[1] + let l:minor = l:match[2] + if l:major > 2 || l:major == 2 && l:minor >= 14 + return ['dart', 'format'] + endif + endif + " Legacy fallback for Dart SDK pre 2.14 + if executable('dartfmt') | return ['dartfmt'] | endif if executable('flutter') let l:flutter_cmd = resolve(exepath('flutter')) let l:bin = fnamemodify(l:flutter_cmd, ':h') let l:dartfmt = l:bin.'/cache/dart-sdk/bin/dartfmt' - if executable(l:dartfmt) | return l:dartfmt | endif + if executable(l:dartfmt) | return [l:dartfmt] | endif endif call s:error('Cannot find a `dartfmt` command') + return [] endfunction function! dart#analyzer(q_args) abort |