File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,12 @@ function! codefmt#buildifier#GetFormatter() abort
3939 " @flag(buildifier)
4040 " @throws ShellError
4141 function l: formatter .Format () abort
42- let l: cmd = s: plugin .Flag (' buildifier_executable' )
42+ let l: cmd = [ s: plugin .Flag (' buildifier_executable' ) ]
43+ let l: fname = expand (' %:p' )
44+ if ! empty (l: fname )
45+ let l: cmd += [' -path' , l: fname ]
46+ endif
47+
4348 let l: input = join (getline (1 , line (' $' )), " \n " )
4449 try
4550 let l: result = maktaba#syscall#Create (l: cmd ).WithStdin (l: input ).Call ()
Original file line number Diff line number Diff line change 1- The built-in buildifier formatter knows how to format Bazel BUILD files. If you
2- aren't familiar with basic codefmt usage yet, see main.vroom first.
1+ The built-in buildifier formatter knows how to format Bazel BUILD and .bzl
2+ files. If you aren't familiar with basic codefmt usage yet, see main.vroom
3+ first.
34
45We'll set up codefmt and configure the vroom environment, then jump into some
56examples.
@@ -38,14 +39,17 @@ buildifier_executable flag if the default of "buildifier" doesn't work.
3839 $ )
3940 :Glaive codefmt buildifier_executable='buildifier'
4041
41- The bzl filetype will use the buildifier formatter by default.
42+ The bzl filetype will use the buildifier formatter by default. The path to the
43+ file being edited is passed to buildifier so that it can adjust to whether the
44+ file is a BUILD or .bzl file.
4245
4346 @clear
4447 % foo_library(name = "foo", srcs = ["bar.js"],)
4548
49+ :silent file /foo/bar/BUILD
4650 :set filetype=bzl
4751 :FormatCode
48- ! buildifier .*
52+ ! buildifier -path /foo/bar/BUILD .*
4953 $ foo_library(
5054 $ name = "foo",
5155 $ srcs = ["bar.js"],
You can’t perform that action at this time.
0 commit comments