Skip to content

fix: prevent infinite loop when started from non-filesystem buffer#35

Merged
barrettruth merged 5 commits intomainfrom
fix/oil-infinite-loop
Mar 6, 2026
Merged

fix: prevent infinite loop when started from non-filesystem buffer#35
barrettruth merged 5 commits intomainfrom
fix/oil-infinite-loop

Conversation

@barrettruth
Copy link
Owner

@barrettruth barrettruth commented Mar 6, 2026

Problem

Calling `:LiveServerStart` from an oil.nvim buffer (or any URI-scheme buffer) caused two issues: first, `find_cached_dir` entered an infinite loop as `fnamemodify(cur, ':h')` degenerated to `.`, freezing Neovim and pegging the CPU; second, even after fixing the loop, the server would error out instead of doing the right thing — serving the directory being browsed.

Solution

Add a progress check to `find_cached_dir` so it bails if the path stops changing. Fix `resolve_dir` to detect URI-scheme buffer names (e.g. `oil:///path/to/dir`) and extract the real filesystem path from them, so `:LiveServerStart` correctly serves the browsed directory. Also corrects the bug report repro template (`require('lazy')`, `lazy = false`, no deprecated `opts`) and ignores `repro.lua`.

Closes #34

…ffers

Problem: calling `:LiveServerStart` from a buffer whose name is a
non-filesystem URI (e.g. oil.nvim's `oil:///path/to/dir`) causes
`find_cached_dir` to spin forever. `fnamemodify(cur, ':h')` eventually
degenerates to `.`, which maps back to itself, so the loop never
terminates — freezing Neovim and pegging the CPU.

Solution: store the result of `fnamemodify(cur, ':h')` and bail out
if it equals `cur`, indicating the path cannot be traversed further.
Problem: buffers like oil.nvim use URI-scheme names (e.g.
`oil:///path/to/dir`) instead of plain filesystem paths. `resolve_dir`
fell back to `%:p:h`, which expanded the URI literally rather than
the directory being browsed, causing the server to fail or error.

Solution: when no explicit dir is given, check the current buffer name
for a URI scheme and extract the real path from it. Falls back to
`%:p:h` for normal file buffers.
@barrettruth barrettruth merged commit c5c69e9 into main Mar 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: The plugin crashes when executing :LiveServerStart in oil.nvim window

1 participant