Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the dartfmt_executable to point to "dart format". #224

Merged
merged 2 commits into from
Jul 28, 2023
Merged
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
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://dart.dev/get-dart'}

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.
Loading