-
Notifications
You must be signed in to change notification settings - Fork 103
Add formatter for lua 5.1 #167
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| " Copyright 2017 Google Inc. All rights reserved. | ||
| " | ||
| " Licensed under the Apache License, Version 2.0 (the "License"); | ||
| " you may not use this file except in compliance with the License. | ||
| " You may obtain a copy of the License at | ||
| " | ||
| " http://www.apache.org/licenses/LICENSE-2.0 | ||
| " | ||
| " Unless required by applicable law or agreed to in writing, software | ||
| " distributed under the License is distributed on an "AS IS" BASIS, | ||
| " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| " See the License for the specific language governing permissions and | ||
| " limitations under the License. | ||
|
|
||
|
|
||
| let s:plugin = maktaba#plugin#Get('codefmt') | ||
|
|
||
|
|
||
| "" | ||
| " @private | ||
| " | ||
| " Formatter provider for lua files using luaformatterfiveone. | ||
| function! codefmt#luaformatterfiveone#GetFormatter() abort | ||
| let l:formatter = { | ||
| \ 'name': 'luaformatterfiveone', | ||
| \ 'setup_instructions': 'Install luaformatterfiveone with luarocks. ' . | ||
| \ '(https://luarocks.org/modules/ElPiloto/formatterfiveone).'} | ||
|
|
||
| function l:formatter.IsAvailable() abort | ||
| return executable(s:plugin.Flag('luaformatterfiveone_executable')) | ||
| endfunction | ||
|
|
||
| function l:formatter.AppliesToBuffer() abort | ||
| return &filetype is# 'lua' | ||
| endfunction | ||
|
|
||
| "" | ||
| " Reformat the current buffer with luaformatterfiveone or the binary named in | ||
| " @flag(luaformatterfiveone_executable) | ||
| " @throws ShellError | ||
| function l:formatter.Format() abort | ||
| let l:cmd = [ s:plugin.Flag('luaformatterfiveone_executable')] | ||
| " Specify we are sending input through stdin | ||
| let l:cmd += ['-i'] | ||
|
|
||
| try | ||
| call codefmt#formatterhelpers#Format(l:cmd) | ||
| catch | ||
| " Parse all the errors and stick them in the quickfix list. | ||
| let l:errors = [] | ||
| for line in split(v:exception, "\n") | ||
| let l:fname_pattern = 'stdin' | ||
| let l:tokens = matchlist(line, | ||
| \ '\C\v^\[string "isCodeValid"\]:(\d+): (.*)') | ||
| if !empty(l:tokens) | ||
| call add(l:errors, { | ||
| \ "filename": @%, | ||
| \ "lnum": l:tokens[1], | ||
| \ "text": l:tokens[2]}) | ||
| endif | ||
| endfor | ||
|
|
||
| if empty(l:errors) | ||
| " Couldn't parse buildifier error format; display it all. | ||
| call maktaba#error#Shout('Error formatting file: %s', v:exception) | ||
| else | ||
| call setqflist(l:errors, 'r') | ||
| cc 1 | ||
| endif | ||
| endtry | ||
| endfunction | ||
|
|
||
| return l:formatter | ||
| endfunction |
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,53 @@ | ||
| luaformatterfiveone" formatter only knows how to format lua 5.1 code. | ||
| If you aren't familiar with basic codefmt usage yet, see main.vroom | ||
|
|
||
| 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) | ||
|
|
||
|
|
||
| luaformatterfiveone expects the lua formatterfiveone executable to be installed | ||
| on your system. | ||
|
|
||
| % function hello() | ||
| % print("world") | ||
| % end | ||
| :FormatCode luaformatterfiveone | ||
| ! luaformatterfiveone -i 2> .* | ||
| $ function hello() | ||
| $ print("world") | ||
| $ end | ||
|
|
||
| The name or path of the luaformatterfiveone executable can be configured via the | ||
| luaformatterfiveone_executable flag if the default of "buildifier" doesn't work. | ||
|
|
||
| :Glaive codefmt luaformatterfiveone_executable='myluaformatterfiveone' | ||
| :FormatCode luaformatterfiveone | ||
| ! myluaformatterfiveone -i 2> .* | ||
| $ function hello() | ||
| $ print("world") | ||
| $ end | ||
| :Glaive codefmt luaformatterfiveone_executable='luaformatterfiveone' | ||
|
|
||
| Errors are reported using the quickfix list. | ||
|
|
||
| @clear | ||
| % 13() | ||
| :FormatCode luaformatterfiveone | ||
| ! luaformatterfiveone -i 2> .* | ||
| ~ (1 of 1): unexpected symbol near '13' | ||
| :echomsg line('.') . ',' . col('.') | ||
| ~ 1,1 | ||
| :echomsg string(map(getqflist(), | ||
| |'v:val.lnum . "," . v:val.text')) | ||
| ~ ['1,unexpected symbol near ''13'''] | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.