From b3b530edae1195b363c831c4bc623bd486cdb660 Mon Sep 17 00:00:00 2001 From: Ahmed W Date: Sun, 1 Oct 2023 09:33:35 -0500 Subject: [PATCH] feat(ignore_stdout): option to ignore stdout (#4) --- doc/HELPERS.md | 2 ++ lua/null-ls/helpers/generator_factory.lua | 10 +++++++++- lua/null-ls/helpers/make_builtin.lua | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/HELPERS.md b/doc/HELPERS.md index c7e4e56f..8ccfbe83 100644 --- a/doc/HELPERS.md +++ b/doc/HELPERS.md @@ -254,6 +254,8 @@ with the following changes: - `ignore_stderr`: set to `true` by default. +- `ignore_stdout`: set to `false` by default. + - `on_output`: will always return an edit that will replace the current buffer's content with formatter output. As a result, other options that depend on `on_output`, such as `format`, will not have an effect. diff --git a/lua/null-ls/helpers/generator_factory.lua b/lua/null-ls/helpers/generator_factory.lua index 8c81cd46..9d16d8d6 100644 --- a/lua/null-ls/helpers/generator_factory.lua +++ b/lua/null-ls/helpers/generator_factory.lua @@ -101,13 +101,14 @@ local line_output_wrapper = function(params, done, on_output) end return function(opts) - local command, args, env, on_output, format, ignore_stderr, from_stderr, to_stdin, check_exit_code, timeout, to_temp_file, from_temp_file, use_cache, runtime_condition, cwd, dynamic_command, multiple_files, temp_dir, prepend_extra_args = + local command, args, env, on_output, format, ignore_stderr, ignore_stdout, from_stderr, to_stdin, check_exit_code, timeout, to_temp_file, from_temp_file, use_cache, runtime_condition, cwd, dynamic_command, multiple_files, temp_dir, prepend_extra_args = opts.command, opts.args, opts.env, opts.on_output, opts.format, opts.ignore_stderr, + opts.ignore_stdout, opts.from_stderr, opts.to_stdin, opts.check_exit_code, @@ -148,6 +149,7 @@ return function(opts) }, from_stderr = { from_stderr, "boolean", true }, ignore_stderr = { ignore_stderr, "boolean", true }, + ignore_stdout = { ignore_stdout, "boolean", true }, to_stdin = { to_stdin, "boolean", true }, check_exit_code = { check_exit_code, "function", true }, timeout = { timeout, "number", true }, @@ -205,6 +207,12 @@ return function(opts) log:trace("error output: " .. (error_output or "nil")) log:trace("output: " .. (output or "nil")) + if ignore_stdout then + if error_output then + log:trace("ignoring stdout due to generator options") + end + output = nil + end if ignore_stderr then if error_output then log:trace("ignoring stderr due to generator options") diff --git a/lua/null-ls/helpers/make_builtin.lua b/lua/null-ls/helpers/make_builtin.lua index ce4fe061..1eb046c8 100644 --- a/lua/null-ls/helpers/make_builtin.lua +++ b/lua/null-ls/helpers/make_builtin.lua @@ -36,6 +36,7 @@ local function make_builtin(opts) diagnostics_postprocess = opts.diagnostics_postprocess, dynamic_command = opts.dynamic_command, ignore_stderr = opts.ignore_stderr, + ignore_stdout = opts.ignore_stdout, runtime_condition = opts.runtime_condition, timeout = opts.timeout, to_temp_file = opts.to_temp_file,