Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Enable Dart style guide syntax (like 2-space indentation) with
Enable DartFmt execution on buffer save with `let g:dart_format_on_save = v:true`

Configure DartFmt options with `let g:dartfmt_options`
(discover formatter options with `dartfmt -h`)
(discover formatter options with `dartfmt -h`). Override the default formatting
command with `g:dartfmt_command`.

## FAQ

Expand Down
28 changes: 7 additions & 21 deletions autoload/dart.vim
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,15 @@ function! dart#fmt(...) abort
endfunction

function! s:FindDartFmt() abort
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
if exists('g:dartfmt_command')
return type(g:dart_format_command) == v:t_list
\ ? g:dart_format_command
\ : [g:dart_format_command]
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('dart')
return ['dart', 'format']
endif
call s:error('Cannot find a `dartfmt` command')
call s:error('Cannot find a `dart` command')
return []
endfunction

Expand Down