-
Notifications
You must be signed in to change notification settings - Fork 107
feat: add luaformatter formatter #54
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc0e9dd
feat: add luaformatter formatter
actionless c82c38a
feat(formatters: js,lua): honor 'shiftwidth'
actionless 10426ab
fix(vroom: luaformatter): fix range and shiftwidth tests
actionless e2983b3
test(formatters: jsbeautify): add shiftwidth
actionless File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
The built-in luaformatter formatter knows how to format lua code. | ||
If you aren't familiar with basic codefmt usage yet, see main.vroom first. | ||
|
||
We'll set up codefmt and configure the vroom environment, then jump into some | ||
examples. | ||
|
||
:source $VROOMDIR/setupvroom.vim | ||
|
||
:let g:repeat_calls = [] | ||
:function FakeRepeat(...)<CR> | ||
| call add(g:repeat_calls, a:000)<CR> | ||
:endfunction | ||
:call maktaba#test#Override('repeat#set', 'FakeRepeat') | ||
|
||
:call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0) | ||
|
||
|
||
The luaformatter formatter expects the luaformatter executable to be installed | ||
on your system. | ||
|
||
% f() | ||
:FormatCode luaformatter | ||
! luaformatter .* | ||
$ f() | ||
|
||
The name or path of the luaformatter executable can be configured via the | ||
luaformatter_executable flag if the default of "luaformatter" doesn't work. | ||
|
||
:Glaive codefmt luaformatter_executable='myjsb' | ||
:FormatCode luaformatter | ||
! myjsb .* | ||
$ f() | ||
:Glaive codefmt luaformatter_executable='luaformatter' | ||
|
||
|
||
You can format any buffer with luaformatter specifying the formatter explicitly. | ||
|
||
@clear | ||
% for i = 0,max do<CR> | ||
|a=1234 + 5678 + i<CR> | ||
| b = 1234*5678+i<CR> | ||
| c=1234/2+i<CR> | ||
| end | ||
|
||
|
||
:FormatCode luaformatter | ||
! luaformatter .*2>.* | ||
$ for i = 0,max do | ||
$ a=1234 + 5678 + i | ||
$ b = 1234*5678+i | ||
$ c=1234/2+i | ||
$ end | ||
for i = 0,max do | ||
a=1234 + 5678 + i | ||
b = 1234*5678+i | ||
c=1234/2+i | ||
end | ||
@end | ||
|
||
NOTE: unfortunately luaformatter don't format punctuation. | ||
|
||
Lua filetype will use the luaformatter formatter by default: | ||
|
||
@clear | ||
% f(); | ||
|
||
:set filetype=lua | ||
:FormatCode | ||
! luaformatter .* | ||
$ f(); | ||
|
||
:set filetype= | ||
|
||
|
||
It can format specific line ranges of code using :FormatLines. | ||
|
||
@clear | ||
% for i = 0,max do<CR> | ||
|a=1234 + 5678 + i<CR> | ||
| b = 1234*5678+i<CR> | ||
| c=1234/2+i<CR> | ||
| end | ||
|
||
:2,2FormatLines luaformatter | ||
! luaformatter .*2>.* | ||
$ a=1234 + 5678 + i | ||
$ b = 1234*5678+i | ||
for i = 0,max do | ||
a=1234 + 5678 + i | ||
b = 1234*5678+i | ||
c=1234/2+i | ||
end | ||
@end | ||
|
||
NOTE: the luaformatter formatter does not natively support range formatting, | ||
so there are certain limitations like not being able to format misaligned | ||
braces. | ||
|
||
|
||
Shitftwidth will be used for indentation: | ||
|
||
@clear | ||
% for i = 0,max do<CR> | ||
|a=1234 + 5678 + i<CR> | ||
| b = 1234*5678+i<CR> | ||
| c=1234/2+i<CR> | ||
| end | ||
|
||
|
||
:sw=8 | ||
:FormatCode luaformatter | ||
! luaformatter .*2>.* | ||
$ for i = 0,max do | ||
$ a=1234 + 5678 + i | ||
$ b = 1234*5678+i | ||
$ c=1234/2+i | ||
$ end | ||
for i = 0,max do | ||
a=1234 + 5678 + i | ||
b = 1234*5678+i | ||
c=1234/2+i | ||
end | ||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunate typo here.