Skip to content

Commit

Permalink
Merge branch 'main' into buffer-stdout-stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
ej-shafran authored Oct 30, 2024
2 parents c0f255a + 27f232d commit 4fe17d8
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Bug Report
description: Create a report to help us improve
title: "[BUG] <title>"
labels: bug
labels:
- bug
assignees: ej-shafran
body:
- type: checkboxes
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main
pull_request:
types:
- opened
- synchronize
branches:
- main

Expand All @@ -18,12 +21,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
Expand All @@ -39,12 +41,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'

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<CMD>q<CR>` and possibly quitting Neovim, it now runs `<CMD>bdelete<CR>`, 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand Down
3 changes: 3 additions & 0 deletions doc/compile-mode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand Down
4 changes: 2 additions & 2 deletions ftplugin/compilation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<cmd>q<cr>")
set("n", "q", "<cmd>bdelete<cr>")
set("n", "<cr>", "<cmd>CompileGotoError<cr>")
set("n", "<C-c>", "<cmd>CompileInterrupt<cr>")
set("n", "<C-q>", "<cmd>QuickfixErrors<cr>")
Expand All @@ -102,7 +102,7 @@ autocmd("CursorMoved", {
autocmd({ "TextChanged", "TextChangedI" }, {
desc = "Error Parsing",
buffer = bufnr,
callback = function ()
callback = function()
compile_mode._parse_errors(bufnr)
end,
})
4 changes: 3 additions & 1 deletion lua/compile-mode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -150,6 +151,7 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback)
stderr_buffered = true,
on_stderr = on_either,
on_exit = function(id, code)
is_exited = true
callback(count, code, id)
end,
env = config.environment,
Expand Down
8 changes: 6 additions & 2 deletions spec/environment_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions spec/multi_step_command_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 = helpers.multi_step_command(first_step_output, second_step_output, wait_seconds)

describe("multi step command", function()
before_each(function()
helpers.setup_tests()
end)

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)
28 changes: 23 additions & 5 deletions spec/test_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ 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", "")
local replaced = line:gsub("%s*\r", "")
return replaced
end, result)
end
Expand All @@ -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

Expand Down Expand Up @@ -129,6 +133,20 @@ function M.compile_multiple_errors(error_strings)
M.compile({ args = "printf '" .. printf_fmt .. "' " .. printf_args })
end

function M.multi_step_command(first_step, second_step, wait_seconds)
if vim.o.shell:match("cmd.exe$") then
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
return ("Write-Output '%s'; Start-Sleep -Seconds %d; Write-Output '%s'"):format(
first_step,
wait_seconds,
second_step
)
else
return ("echo '%s' && sleep %d && echo '%s'"):format(first_step, wait_seconds, second_step)
end
end

---@param expected CreateError
function M.assert_parsed_error(error_string, expected)
---@type CompileModeError|nil
Expand Down
2 changes: 2 additions & 0 deletions todos.org
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4fe17d8

Please sign in to comment.