fix: prevent infinite loop when started from non-filesystem buffer (#35)
Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
## 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
This commit is contained in:
parent
f18dfa0a8d
commit
c5c69e9ec2
3 changed files with 13 additions and 4 deletions
4
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
4
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
|
|
@ -65,11 +65,11 @@ body:
|
|||
value: |
|
||||
vim.env.LAZY_STDPATH = '.repro'
|
||||
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()
|
||||
require('lazy.nvim').setup({
|
||||
require('lazy').setup({
|
||||
spec = {
|
||||
{
|
||||
'barrett-ruth/live-server.nvim',
|
||||
opts = {},
|
||||
lazy = false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -6,3 +6,6 @@ node_modules/
|
|||
|
||||
.envrc
|
||||
.direnv
|
||||
|
||||
.repro
|
||||
repro.lua
|
||||
|
|
|
|||
|
|
@ -140,7 +140,11 @@ local function find_cached_dir(dir)
|
|||
if cur == '/' or cur:match('^[A-Z]:\\$') then
|
||||
return nil
|
||||
end
|
||||
cur = vim.fn.fnamemodify(cur, ':h')
|
||||
local parent = vim.fn.fnamemodify(cur, ':h')
|
||||
if parent == cur then
|
||||
return nil
|
||||
end
|
||||
cur = parent
|
||||
end
|
||||
return cur
|
||||
end
|
||||
|
|
@ -156,7 +160,9 @@ end
|
|||
---@return string
|
||||
local function resolve_dir(dir)
|
||||
if not dir or dir == '' then
|
||||
dir = '%:p:h'
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
local uri_path = bufname:match('^%a+://(/.*)')
|
||||
dir = uri_path or '%:p:h'
|
||||
end
|
||||
return vim.fn.expand(vim.fn.fnamemodify(vim.fn.expand(dir), ':p'))
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue