From 50fce1b0d80ce84da6b16479f411576dd22cd8c0 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Tue, 10 Sep 2024 09:40:00 +0300 Subject: [PATCH 01/25] Add TODO --- todos.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todos.org b/todos.org index 071b96e..e83b6fd 100644 --- a/todos.org +++ b/todos.org @@ -227,3 +227,5 @@ This gets tacked on the end of the generated expressions.") * TODO Make some logs trace-level +* TODO Add ability to customize entering-leaving regex + From 2fc58c363e19783008e76480067ec90e39bcbe7d Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Sat, 12 Oct 2024 01:25:14 +0300 Subject: [PATCH 02/25] Stop outputting lines after exit --- lua/compile-mode/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/compile-mode/init.lua b/lua/compile-mode/init.lua index c3443f4..38f5c52 100644 --- a/lua/compile-mode/init.lua +++ b/lua/compile-mode/init.lua @@ -118,9 +118,10 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) local count = 0 local partial_line = "" + local is_exited = false local on_either = a.void(function(_, data) - if not data or #data < 1 or (#data == 1 and data[1] == "") then + if is_exited or not data or #data < 1 or (#data == 1 and data[1] == "") then return end @@ -148,6 +149,7 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) on_stdout = on_either, on_stderr = on_either, on_exit = function(id, code) + is_exited = true callback(count, code, id) end, env = config.environment, From 789eac1c2497b87733252789994dfa6b6719a608 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Sat, 12 Oct 2024 01:25:55 +0300 Subject: [PATCH 03/25] Don't close Neovim when pressing `q` --- ftplugin/compilation.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/compilation.lua b/ftplugin/compilation.lua index eefcdfd..9560bfd 100644 --- a/ftplugin/compilation.lua +++ b/ftplugin/compilation.lua @@ -80,7 +80,7 @@ command("CompileNextFile", compile_mode.move_to_next_file, { count = 1 }) command("CompilePrevError", compile_mode.move_to_prev_error, { count = 1 }) command("CompilePrevFile", compile_mode.move_to_prev_file, { count = 1 }) -set("n", "q", "q") +set("n", "q", "bdelete") set("n", "", "CompileGotoError") set("n", "", "CompileInterrupt") set("n", "", "QuickfixErrors") @@ -102,7 +102,7 @@ autocmd("CursorMoved", { autocmd({ "TextChanged", "TextChangedI" }, { desc = "Error Parsing", buffer = bufnr, - callback = function () + callback = function() compile_mode._parse_errors(bufnr) end, }) From 16560179d8ee4082b8862e8f2ccaa3203297684e Mon Sep 17 00:00:00 2001 From: ejshafran Date: Sun, 13 Oct 2024 12:03:20 +0300 Subject: [PATCH 04/25] Revert 1 commits 2fc58c3 'Stop outputting lines after exit' --- lua/compile-mode/init.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/compile-mode/init.lua b/lua/compile-mode/init.lua index 38f5c52..c3443f4 100644 --- a/lua/compile-mode/init.lua +++ b/lua/compile-mode/init.lua @@ -118,10 +118,9 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) local count = 0 local partial_line = "" - local is_exited = false local on_either = a.void(function(_, data) - if is_exited or not data or #data < 1 or (#data == 1 and data[1] == "") then + if not data or #data < 1 or (#data == 1 and data[1] == "") then return end @@ -149,7 +148,6 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) on_stdout = on_either, on_stderr = on_either, on_exit = function(id, code) - is_exited = true callback(count, code, id) end, env = config.environment, From 2ccf348874b1d0fe4f8e6cb5eb49e43924a0f5e9 Mon Sep 17 00:00:00 2001 From: ejshafran Date: Sun, 13 Oct 2024 12:06:11 +0300 Subject: [PATCH 05/25] Revert "Revert 1 commits" This reverts commit 16560179d8ee4082b8862e8f2ccaa3203297684e. --- lua/compile-mode/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/compile-mode/init.lua b/lua/compile-mode/init.lua index c3443f4..38f5c52 100644 --- a/lua/compile-mode/init.lua +++ b/lua/compile-mode/init.lua @@ -118,9 +118,10 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) local count = 0 local partial_line = "" + local is_exited = false local on_either = a.void(function(_, data) - if not data or #data < 1 or (#data == 1 and data[1] == "") then + if is_exited or not data or #data < 1 or (#data == 1 and data[1] == "") then return end @@ -148,6 +149,7 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) on_stdout = on_either, on_stderr = on_either, on_exit = function(id, code) + is_exited = true callback(count, code, id) end, env = config.environment, From 607f032d392cbae3bf26d6002a2c0b7721490395 Mon Sep 17 00:00:00 2001 From: ejshafran Date: Sun, 13 Oct 2024 12:09:07 +0300 Subject: [PATCH 06/25] Fix tests on macOS --- spec/environment_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/environment_spec.lua b/spec/environment_spec.lua index 30841f8..7ba23c5 100644 --- a/spec/environment_spec.lua +++ b/spec/environment_spec.lua @@ -50,7 +50,11 @@ end) describe("`clear_environment` option", function() it("should override existing environment variables", function() - helpers.setup_tests({ clear_environment = true }) + helpers.setup_tests({ + clear_environment = true, + -- NOTE: this is required or tests fail on macOS, because Homebrew needs $HOME to be set + environment = { HOME = "/" }, + }) local cmd = env_variable("OTHER") vim.env.OTHER = "some value" From 95a871602001456f28a41ca5c9abcbc57f9637c7 Mon Sep 17 00:00:00 2001 From: ejshafran Date: Sun, 13 Oct 2024 16:01:51 +0300 Subject: [PATCH 07/25] 5.3.0 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f32fe..ca416a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to ## [Unreleased] +## [5.3.0] - 2024-10-13 + +### Changed + +- The behavior of the `q` mapping within the compilation buffer; instead of running `q` and possibly quitting Neovim, it now runs `bdelete`, which won't close out the entire editor. +- No longer outputs additional lines created by the process once interrupted/exited. + ## [5.2.0] - 2024-08-27 ### Added @@ -392,6 +399,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to API functions [unreleased]: https://github.com/ej-shafran/compile-mode.nvim/compare/latest...nightly +[5.3.0]: https://github.com/ej-shafran/compile-mode.nvim/compare/v5.2.0...v5.3.0 [5.2.0]: https://github.com/ej-shafran/compile-mode.nvim/compare/v5.1.0...v5.2.0 [5.1.0]: https://github.com/ej-shafran/compile-mode.nvim/compare/v5.0.2...v5.1.0 [5.0.2]: https://github.com/ej-shafran/compile-mode.nvim/compare/v5.0.1...v5.0.2 From 9639852ad9e90af014993ab9dbf787987e8c0084 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Mon, 21 Oct 2024 02:17:59 +0300 Subject: [PATCH 08/25] Try running tests with `nvim_version` matrix as well --- .github/workflows/test.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f4decf..d00f07c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,12 +18,11 @@ jobs: - ubuntu-latest - macos-latest - windows-latest + nvim_version: + - 0.10.0 runs-on: ${{ matrix.os }} - env: - NVIM_VERSION: 0.10.0 - steps: - name: Checkout Code uses: actions/checkout@v4 @@ -39,12 +38,12 @@ jobs: - name: Install Neovim uses: MunifTanjim/setup-neovim-action@v1 with: - tag: v${{ env.NVIM_VERSION }} + tag: v${{ matrix.nvim_version }} if: matrix.os != 'windows-latest' - name: Install Neovim (Windows) run: | - choco install neovim --version=${{ env.NVIM_VERSION }} + choco install neovim --version=${{ matrix.nvim_version }} echo 'C:\tools\neovim\nvim-win64\bin' | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append if: matrix.os == 'windows-latest' From 7e31c11dd185ccbcfb0bd3b21fde76e3a90eea96 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Mon, 21 Oct 2024 02:22:54 +0300 Subject: [PATCH 09/25] Add 0.9.5 to tested Neovim versions --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d00f07c..686a46f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,7 @@ jobs: - macos-latest - windows-latest nvim_version: + - 0.9.5 - 0.10.0 runs-on: ${{ matrix.os }} From 632c3fee0946bda9cb7a06cfd98627e1e1ad5876 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Mon, 21 Oct 2024 02:32:06 +0300 Subject: [PATCH 10/25] Use custom `list_contains` function --- lua/compile-mode/config/check.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/compile-mode/config/check.lua b/lua/compile-mode/config/check.lua index e14031c..ba4d36c 100644 --- a/lua/compile-mode/config/check.lua +++ b/lua/compile-mode/config/check.lua @@ -2,6 +2,18 @@ local check = {} local compile_mode = require("compile-mode") +---@param lst unknown[] +---@param value unknown +---@return boolean +local function list_contains(lst, value) + for _, item in ipairs(lst) do + if item == value then + return true + end + end + return false +end + ---@param tbl table the table to validate ---@see vim.validate ---@return boolean is_valid @@ -143,12 +155,12 @@ function check.unrecognized_keys(tbl, default_tbl) local keys = {} for k, _ in pairs(tbl) do - if not vim.list_contains(skipped_keys, k) then + if not list_contains(skipped_keys, k) then keys[k] = true end end for k, _ in pairs(default_tbl) do - if not vim.list_contains(skipped_keys, k) then + if not list_contains(skipped_keys, k) then keys[k] = false end end From 752117509775034e12614a891daac0710930ebe1 Mon Sep 17 00:00:00 2001 From: ej-shafran Date: Mon, 21 Oct 2024 02:46:22 +0300 Subject: [PATCH 11/25] Update docs to note minimum Neovim version --- .github/ISSUE_TEMPLATE/bug_report.yml | 5 +++-- .github/ISSUE_TEMPLATE/feature_request.yml | 3 ++- CONTRIBUTING.md | 4 ++++ README.md | 4 ++++ doc/compile-mode.txt | 3 +++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index d1dd30a..9a02951 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,7 +1,8 @@ name: Bug Report description: Create a report to help us improve title: "[BUG] " -labels: bug +labels: + - bug assignees: ej-shafran body: - type: checkboxes @@ -47,7 +48,7 @@ body: - type: textarea attributes: label: Neovim Version - description: Include the result of `nvim -v` here. + description: Include the result of `nvim -v` here. Please note that `compile-mode.nvim` only supports Neovim versions v0.10.0 and higher. render: markdown validations: required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 6290b8c..9415da9 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,7 +1,8 @@ name: Feature Request description: Request a feature you would like to see title: "[FEAT] <title>" -labels: enhancement +labels: + - enhancement assignees: ej-shafran body: - type: checkboxes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92da45f..13ed270 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,10 @@ Thank you for wanting to contribute to `compile-mode.nvim`! Generally, I want to keep this plugin pretty close to the features of Emacs' Compilation Mode, with better quality of life where possible, so I'd recommend you have some familiarity with it if you want to contribute. Bug fixes are always welcome, of course, but new features should either be things that exist in the Emacs mode or things that unambiguously make the plugin nicer to use. +> [!NOTE] +> +> As specified in the README, `compile-mode.nvim` only officially supports Neovim versions v0.10.0 and higher. However, if you'd like to contribute some code that makes the plugin work for earlier versions (and isn't too much of a hassle to maintain) I'll be glad to merge it. + ## The development process ### Cloning the repository diff --git a/README.md b/README.md index 0ea4bfc..59d0bb9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ rerun that command over and over again as much as you need. Use your favorite plugin manager. `compile-mode.nvim` depends on [plenary.nvim](https://github.com/nvim-lua/plenary.nvim). +> [!WARNING] +> +> `compile-mode.nvim` only supports Neovim versions v0.10.0 and higher, and isn't expected to work for earlier versions. + Here's an example of a [Lazy](https://github.com/folke/lazy.nvim) config for `compile-mode.nvim`: diff --git a/doc/compile-mode.txt b/doc/compile-mode.txt index 73404b1..c520488 100644 --- a/doc/compile-mode.txt +++ b/doc/compile-mode.txt @@ -90,6 +90,9 @@ Use your favorite plugin manager. `compile-mode.nvim` depends on plenary.nvim <https://github.com/nvim-lua/plenary.nvim> (and optionally baleia.nvim <https://github.com/m00qek/baleia.nvim>). +WARNING: `compile-mode.nvim` only supports Neovim versions v0.10.0 and higher, +and isn't expected to work for earlier versions. + Here’s an example of a Lazy <https://github.com/folke/lazy.nvim> config for `compile-mode.nvim`: From ca75dbd070f2eee6318fc9246ee8970f804cb851 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Mon, 21 Oct 2024 02:46:41 +0300 Subject: [PATCH 12/25] Revert 2 commits 7e31c11 'Add 0.9.5 to tested Neovim versions' 632c3fe 'Use custom `list_contains` function' --- .github/workflows/test.yml | 1 - lua/compile-mode/config/check.lua | 16 ++-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 686a46f..d00f07c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,6 @@ jobs: - macos-latest - windows-latest nvim_version: - - 0.9.5 - 0.10.0 runs-on: ${{ matrix.os }} diff --git a/lua/compile-mode/config/check.lua b/lua/compile-mode/config/check.lua index ba4d36c..e14031c 100644 --- a/lua/compile-mode/config/check.lua +++ b/lua/compile-mode/config/check.lua @@ -2,18 +2,6 @@ local check = {} local compile_mode = require("compile-mode") ----@param lst unknown[] ----@param value unknown ----@return boolean -local function list_contains(lst, value) - for _, item in ipairs(lst) do - if item == value then - return true - end - end - return false -end - ---@param tbl table the table to validate ---@see vim.validate ---@return boolean is_valid @@ -155,12 +143,12 @@ function check.unrecognized_keys(tbl, default_tbl) local keys = {} for k, _ in pairs(tbl) do - if not list_contains(skipped_keys, k) then + if not vim.list_contains(skipped_keys, k) then keys[k] = true end end for k, _ in pairs(default_tbl) do - if not list_contains(skipped_keys, k) then + if not vim.list_contains(skipped_keys, k) then keys[k] = false end end From fd445bdef1c9ff5263195e3d4d638d48dd8bfc1b Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Mon, 21 Oct 2024 02:54:40 +0300 Subject: [PATCH 13/25] TEMPORARY: test running with `swapfile` enabled in CI --- spec/configs/ci.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configs/ci.vim b/spec/configs/ci.vim index c59aff5..d4e4365 100644 --- a/spec/configs/ci.vim +++ b/spec/configs/ci.vim @@ -2,6 +2,6 @@ set rtp+=. set rtp+=../plenary.nvim -set noswapfile +" set noswapfile runtime! plugin/plenary.vim From e24c873c433583008134b3bd4f2a2abe59a134b7 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Mon, 21 Oct 2024 02:59:18 +0300 Subject: [PATCH 14/25] Revert 1 commits fd445bd 'TEMPORARY: test running with `swapfile` enabled in CI' --- spec/configs/ci.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configs/ci.vim b/spec/configs/ci.vim index d4e4365..c59aff5 100644 --- a/spec/configs/ci.vim +++ b/spec/configs/ci.vim @@ -2,6 +2,6 @@ set rtp+=. set rtp+=../plenary.nvim -" set noswapfile +set noswapfile runtime! plugin/plenary.vim From 312eba7d13b7f4c9840fcf9f34edf9655d976b2b Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:41:11 +0200 Subject: [PATCH 15/25] Add test for multi-step commands See [this comment](https://github.com/ej-shafran/compile-mode.nvim/pull/44#issuecomment-2446075858) --- spec/multi_step_command_spec.lua | 22 ++++++++++++++++++++++ spec/test_helpers.lua | 20 ++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 spec/multi_step_command_spec.lua diff --git a/spec/multi_step_command_spec.lua b/spec/multi_step_command_spec.lua new file mode 100644 index 0000000..7d2f525 --- /dev/null +++ b/spec/multi_step_command_spec.lua @@ -0,0 +1,22 @@ +local helpers = require("spec.test_helpers") +local assert = require("luassert") + +local first_step_output = "hello" +local wait_seconds = 1 +local second_step_output = "goodbye" +local cmd = ("echo %s && %s && echo %s"):format( + first_step_output, + helpers.sleep_command(wait_seconds), + second_step_output +) + +describe("multi step command", function() + before_each(helpers.setup_tests) + + it("should output the command step-by-step", function() + helpers.compile({ args = cmd }) + assert.are.same({ cmd, first_step_output }, helpers.get_output(nil, -2)) + helpers.wait(wait_seconds * 1000 + 100) + assert.are.same({ cmd, first_step_output, second_step_output }, helpers.get_output()) + end) +end) diff --git a/spec/test_helpers.lua b/spec/test_helpers.lua index 0c3293e..eb17dbd 100644 --- a/spec/test_helpers.lua +++ b/spec/test_helpers.lua @@ -60,9 +60,12 @@ function M.get_compilation_bufnr() return vim.fn.bufadd(config.buffer_name) end -function M.get_output() +function M.get_output(start_line, end_line) + start_line = start_line or 3 + end_line = end_line or -4 + local bufnr = M.get_compilation_bufnr() - local result = vim.api.nvim_buf_get_lines(bufnr, 3, -4, false) + local result = vim.api.nvim_buf_get_lines(bufnr, start_line, end_line, false) return vim.tbl_map(function(line) local replaced = line:gsub("\r", "") return replaced @@ -76,11 +79,12 @@ function M.setup_tests(opts) package.loaded["compile-mode.config.internal"] = nil end -function M.wait() +function M.wait(ms) + ms = ms or 100 local co = coroutine.running() vim.defer_fn(function() coroutine.resume(co) - end, 100) + end, ms) coroutine.yield(co) end @@ -129,6 +133,14 @@ function M.compile_multiple_errors(error_strings) M.compile({ args = "printf '" .. printf_fmt .. "' " .. printf_args }) end +function M.sleep_command(seconds) + if vim.o.shell:match("cmd.exe$") then + return ("timeout /T %d"):format(seconds) + else + return ("sleep %d"):format(seconds) + end +end + ---@param expected CreateError function M.assert_parsed_error(error_string, expected) ---@type CompileModeError|nil From adbeccfbdfc0ca849652b0a1b0b4d9b106972bfe Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:46:39 +0200 Subject: [PATCH 16/25] Use semicolon --- spec/multi_step_command_spec.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/multi_step_command_spec.lua b/spec/multi_step_command_spec.lua index 7d2f525..9a1d972 100644 --- a/spec/multi_step_command_spec.lua +++ b/spec/multi_step_command_spec.lua @@ -4,11 +4,7 @@ local assert = require("luassert") local first_step_output = "hello" local wait_seconds = 1 local second_step_output = "goodbye" -local cmd = ("echo %s && %s && echo %s"):format( - first_step_output, - helpers.sleep_command(wait_seconds), - second_step_output -) +local cmd = ("echo %s; %s; echo %s"):format(first_step_output, helpers.sleep_command(wait_seconds), second_step_output) describe("multi step command", function() before_each(helpers.setup_tests) From 9b31ab1ff46436d15ed08cd15de9aae6704cf209 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:48:02 +0200 Subject: [PATCH 17/25] Revert 1 commits adbeccf 'Use semicolon' --- spec/multi_step_command_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/multi_step_command_spec.lua b/spec/multi_step_command_spec.lua index 9a1d972..7d2f525 100644 --- a/spec/multi_step_command_spec.lua +++ b/spec/multi_step_command_spec.lua @@ -4,7 +4,11 @@ local assert = require("luassert") local first_step_output = "hello" local wait_seconds = 1 local second_step_output = "goodbye" -local cmd = ("echo %s; %s; echo %s"):format(first_step_output, helpers.sleep_command(wait_seconds), second_step_output) +local cmd = ("echo %s && %s && echo %s"):format( + first_step_output, + helpers.sleep_command(wait_seconds), + second_step_output +) describe("multi step command", function() before_each(helpers.setup_tests) From fe67cd40d16119fa0df41a19207c6431d1cdd065 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:50:23 +0200 Subject: [PATCH 18/25] Try to remove space before `&&` --- spec/multi_step_command_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/multi_step_command_spec.lua b/spec/multi_step_command_spec.lua index 7d2f525..bb85987 100644 --- a/spec/multi_step_command_spec.lua +++ b/spec/multi_step_command_spec.lua @@ -4,7 +4,7 @@ local assert = require("luassert") local first_step_output = "hello" local wait_seconds = 1 local second_step_output = "goodbye" -local cmd = ("echo %s && %s && echo %s"):format( +local cmd = ("echo %s&& %s && echo %s"):format( first_step_output, helpers.sleep_command(wait_seconds), second_step_output From 9117a6ff99207bf09454fc5fb7c65aeca2fadf62 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:53:48 +0200 Subject: [PATCH 19/25] Try to fix Windows command --- spec/test_helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/test_helpers.lua b/spec/test_helpers.lua index eb17dbd..108b2a9 100644 --- a/spec/test_helpers.lua +++ b/spec/test_helpers.lua @@ -135,7 +135,7 @@ end function M.sleep_command(seconds) if vim.o.shell:match("cmd.exe$") then - return ("timeout /T %d"):format(seconds) + return ("timeout %d"):format(seconds) else return ("sleep %d"):format(seconds) end From de4327ff12a65fdc8f0ca5c1f3958bc20d879f50 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:57:10 +0200 Subject: [PATCH 20/25] Try forcing bash shell --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d00f07c..3834c48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,6 +48,7 @@ jobs: if: matrix.os == 'windows-latest' - name: Run Tests + shell: bash run: | cd compile-mode.nvim make setup-ci From 5768f99a6fab899ae9199bc8572fcf104cdccb69 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 12:58:50 +0200 Subject: [PATCH 21/25] Try explicitly setting trigger type --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3834c48..62362a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,9 @@ on: branches: - main pull_request: + types: + - opened + - synchronize branches: - main From 00460c8e2e64cbd30547bd8e3c7461d7cac55fa0 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 13:08:33 +0200 Subject: [PATCH 22/25] Use totally different commands for different shells --- spec/environment_spec.lua | 2 +- spec/multi_step_command_spec.lua | 10 ++++------ spec/test_helpers.lua | 10 +++++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/environment_spec.lua b/spec/environment_spec.lua index 7ba23c5..8a2993b 100644 --- a/spec/environment_spec.lua +++ b/spec/environment_spec.lua @@ -3,7 +3,7 @@ local helpers = require("spec.test_helpers") local function env_variable(var) if vim.o.shell:match("cmd.exe$") then return "echo %" .. var .. "%" - elseif vim.o.shell:match("pwdh$") or vim.o.shell:match("powershell$") then + elseif vim.o.shell:match("pwsh$") or vim.o.shell:match("powershell$") then return "echo $Env:" .. var else return "echo $" .. var diff --git a/spec/multi_step_command_spec.lua b/spec/multi_step_command_spec.lua index bb85987..170f8f8 100644 --- a/spec/multi_step_command_spec.lua +++ b/spec/multi_step_command_spec.lua @@ -4,14 +4,12 @@ local assert = require("luassert") local first_step_output = "hello" local wait_seconds = 1 local second_step_output = "goodbye" -local cmd = ("echo %s&& %s && echo %s"):format( - first_step_output, - helpers.sleep_command(wait_seconds), - second_step_output -) +local cmd = helpers.multi_step_command(first_step_output, second_step_output, wait_seconds) describe("multi step command", function() - before_each(helpers.setup_tests) + before_each(function() + helpers.setup_tests() + end) it("should output the command step-by-step", function() helpers.compile({ args = cmd }) diff --git a/spec/test_helpers.lua b/spec/test_helpers.lua index 108b2a9..53ecc39 100644 --- a/spec/test_helpers.lua +++ b/spec/test_helpers.lua @@ -133,12 +133,16 @@ function M.compile_multiple_errors(error_strings) M.compile({ args = "printf '" .. printf_fmt .. "' " .. printf_args }) end -function M.sleep_command(seconds) +function M.multi_step_command(first_step, second_step, wait_seconds) + local fmt if vim.o.shell:match("cmd.exe$") then - return ("timeout %d"):format(seconds) + fmt = 'echo "%s" && timeout /t %d && echo "%s"' + elseif vim.o.shell:match("pwsh$") or vim.o.shell:match("powershell$") then + fmt = "Write-Output '%s'; Start-Sleep -Seconds %d; Write-Output '%s'" else - return ("sleep %d"):format(seconds) + fmt = "echo '%s' && sleep %d && echo '%s'" end + return fmt:format(first_step, wait_seconds, second_step) end ---@param expected CreateError From 7061323ebacb7b0d292cb147bad9a41a26eb30cf Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 13:08:39 +0200 Subject: [PATCH 23/25] Revert 1 commits de4327f 'Try forcing bash shell' --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62362a1..4f70c68 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,7 +51,6 @@ jobs: if: matrix.os == 'windows-latest' - name: Run Tests - shell: bash run: | cd compile-mode.nvim make setup-ci From efcc7120ecc93fcc157992657ad75efd2f033674 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 13:18:15 +0200 Subject: [PATCH 24/25] Try changing to a working command --- spec/test_helpers.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/test_helpers.lua b/spec/test_helpers.lua index 53ecc39..421e3b6 100644 --- a/spec/test_helpers.lua +++ b/spec/test_helpers.lua @@ -134,15 +134,17 @@ function M.compile_multiple_errors(error_strings) end function M.multi_step_command(first_step, second_step, wait_seconds) - local fmt if vim.o.shell:match("cmd.exe$") then - fmt = 'echo "%s" && timeout /t %d && echo "%s"' + return ("echo %s && ping 127.0.0.1 -n %d > nul && echo %s"):format(first_step, wait_seconds + 1, second_step) elseif vim.o.shell:match("pwsh$") or vim.o.shell:match("powershell$") then - fmt = "Write-Output '%s'; Start-Sleep -Seconds %d; Write-Output '%s'" + return ("Write-Output '%s'; Start-Sleep -Seconds %d; Write-Output '%s'"):format( + first_step, + wait_seconds, + second_step + ) else - fmt = "echo '%s' && sleep %d && echo '%s'" + return ("echo '%s' && sleep %d && echo '%s'"):format(first_step, wait_seconds, second_step) end - return fmt:format(first_step, wait_seconds, second_step) end ---@param expected CreateError From 475de3b1f5c282eb09f445a03501fbffb7f3b7e2 Mon Sep 17 00:00:00 2001 From: ej-shafran <ejshafran@hilma.tech> Date: Wed, 30 Oct 2024 13:21:09 +0200 Subject: [PATCH 25/25] Try to trim out Windows strings --- spec/test_helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/test_helpers.lua b/spec/test_helpers.lua index 421e3b6..08d86b3 100644 --- a/spec/test_helpers.lua +++ b/spec/test_helpers.lua @@ -67,7 +67,7 @@ function M.get_output(start_line, end_line) local bufnr = M.get_compilation_bufnr() local result = vim.api.nvim_buf_get_lines(bufnr, start_line, end_line, false) return vim.tbl_map(function(line) - local replaced = line:gsub("\r", "") + local replaced = line:gsub("%s*\r", "") return replaced end, result) end