Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Commit

Permalink
fix(builtins): handle buf's lack of stdin support
Browse files Browse the repository at this point in the history
See this issue for info: bufbuild/buf#1035
For formatting, the fix is to write to and read from a temp file.
Diagnostics require project context, which a temp file can't provide, so
the diagnostics source now runs only on save.
  • Loading branch information
Jose Alvarez committed May 22, 2022
1 parent 27e0dfc commit 558415e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lua/null-ls/builtins/diagnostics/buf.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")

local DIAGNOSTICS = methods.internal.DIAGNOSTICS
local DIAGNOSTICS_ON_SAVE = methods.internal.DIAGNOSTICS_ON_SAVE

return h.make_builtin({
name = "buf_lint",
meta = {
url = "https://github.com/bufbuild/buf",
description = "A new way of working with Protocol Buffers.",
},
method = DIAGNOSTICS,
method = DIAGNOSTICS_ON_SAVE,
filetypes = { "proto" },
generator_opts = {
command = "buf",
Expand Down
4 changes: 3 additions & 1 deletion lua/null-ls/builtins/formatting/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ return h.make_builtin({
description = "A new way of working with Protocol Buffers.",
},
method = FORMATTING,
to_temp_file = true,
from_temp_file = true,
filetypes = { "proto" },
generator_opts = {
command = "buf",
args = {
"format",
"-w",
"$FILENAME",
},
to_stdin = true,
},
factory = h.formatter_factory,
})

2 comments on commit 558415e

@jan-xyz
Copy link

@jan-xyz jan-xyz commented on 558415e Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the fix! Should this be undone once buf supports stdin? I can keep an eye out for it.

@jose-elias-alvarez
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the fix! Should this be undone once buf supports stdin? I can keep an eye out for it.

Sure, thanks - moving back to stdin would be ideal once it's supported.

Please # to comment.