Skip to content

Commit

Permalink
Change the dartfmt_executable to point to "dart format".
Browse files Browse the repository at this point in the history
This is because dartfmt has been replaced by dart format.
  • Loading branch information
Ryan Wiener authored and dbarnett committed Jul 28, 2023
1 parent 6ee1e7e commit d927656
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
13 changes: 11 additions & 2 deletions autoload/codefmt/dartfmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function! codefmt#dartfmt#GetFormatter() abort
let l:formatter = {
\ 'name': 'dartfmt',
\ 'setup_instructions': 'Install the Dart SDK from ' .
\ 'https://www.dartlang.org/tools/sdk/'}
\ 'https://github.com/google/vim-codefmt'}

function l:formatter.IsAvailable() abort
return executable(s:plugin.Flag('dartfmt_executable'))
Expand All @@ -38,7 +38,16 @@ function! codefmt#dartfmt#GetFormatter() abort
" @flag(dartfmt_executable}, only targetting the range from {startline} to
" {endline}
function l:formatter.FormatRange(startline, endline) abort
let l:cmd = [ s:plugin.Flag('dartfmt_executable') ]
let l:dartfmt_executable = s:plugin.Flag('dartfmt_executable')
if type(l:dartfmt_executable) is# type([])
let l:cmd = l:dartfmt_executable
elseif type(l:dartfmt_executable) is# type('')
let l:cmd = [l:dartfmt_executable]
else
throw maktaba#error#WrongType(
\ 'dartfmt_executable flag must be a list or string. Found %s',
\ string(l:dartfmt_executable))
endif
try
" dartfmt does not support range formatting yet:
" https://github.com/dart-lang/dart_style/issues/92
Expand Down
4 changes: 2 additions & 2 deletions doc/codefmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ additionally adjust imports when formatting.
Default: 'gofmt' `

*codefmt:dartfmt_executable*
The path to the dartfmt executable.
Default: 'dartfmt' `
The path to the dartfmt executable. Either a list or string.
Default: ['dart', 'format'] `

*codefmt:js_beautify_executable*
The path to the js-beautify executable.
Expand Down
5 changes: 3 additions & 2 deletions instant/flags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ call s:plugin.Flag('clang_format_style', 'file')
call s:plugin.Flag('gofmt_executable', 'gofmt')

""
" The path to the dartfmt executable.
call s:plugin.Flag('dartfmt_executable', 'dartfmt')
" The path to the dartfmt executable. Either a list or a string.
call s:plugin.Flag('dartfmt_executable', ['dart', 'format'])


""
" The path to the js-beautify executable.
Expand Down
28 changes: 13 additions & 15 deletions vroom/dartfmt.vroom
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,31 @@ examples.

:call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0)


The dartfmt formatter expects the dartfmt executable to be installed on your
The dart formatter expects the dart executable to be installed on your
system.

% main(){}
:FormatCode dartfmt
! dartfmt .*
! dart format .*
$ main(){}

The name or path of the dartfmt executable can be configured via the
dartfmt_executable flag if the default of "dartfmt" doesn't work.
The name, path, or list of the dart format command can be configured via the
dartfmt_executable flag if the default of ["dart", "format"] doesn't work.

:Glaive codefmt dartfmt_executable='mydartfmt'
:Glaive codefmt dartfmt_executable='dartfmt'
:FormatCode dartfmt
! mydartfmt .*
! dartfmt .*
$ main(){}
:Glaive codefmt dartfmt_executable='dartfmt'

:Glaive codefmt dartfmt_executable=`['dart', 'format']`

You can format any buffer with dartfmt specifying the formatter explicitly.
You can format any buffer with dart format specifying the formatter explicitly.

@clear
% main() { print("hello ");<CR>
|print("world\n");}

:FormatCode dartfmt
! dartfmt .*2>.*
! dart format .*2>.*
$ main() {
$ \tprint("hello ");
$ \tprint("world\\n");
Expand All @@ -51,14 +49,14 @@ You can format any buffer with dartfmt specifying the formatter explicitly.
}
@end

The dart filetype will use the dartfmt formatter by default.
The dart filetype will use the dart formatter by default.

@clear
% main(){}

:set filetype=dart
:FormatCode
! dartfmt .*
! dart format .*
$ main(){}

:set filetype=
Expand All @@ -70,7 +68,7 @@ It can format specific line ranges of code using :FormatLines.
|Print("hello "); Print("world\n");}

:1,2FormatLines dartfmt
! dartfmt .*2>.*
! dart format .*2>.*
$ main() {
$ \tprint("hello ");
$ \tprint("world\\n");
Expand All @@ -81,5 +79,5 @@ It can format specific line ranges of code using :FormatLines.
}
@end

NOTE: the dartfmt formatter does not natively support range formatting, so there
NOTE: the dart formatter does not natively support range formatting, so there
are certain limitations like not being able to format misaligned braces.

0 comments on commit d927656

Please sign in to comment.