Skip to content

Commit 93880a8

Browse files
committed
fix: LSP attach to 'nowrite' buffer
1 parent 7352178 commit 93880a8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
nvim -c 'helptags doc' -c 'quit'
4848
4949
- name: Push Changes
50-
uses: stefanzweifel/git-auto-commit-action@v5
50+
uses: stefanzweifel/git-auto-commit-action@v7
5151
with:
5252
commit_message: "docs: Auto-generate user / API documentation + vimtags"
5353
commit_user_name: "github-actions[bot]"

lua/lua-console.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ local get_or_create_buffer = function()
1818
vim.bo[buf].swapfile = false
1919
vim.bo[buf].buflisted = false
2020
vim.bo[buf].bufhidden = 'hide'
21-
vim.bo[buf].buftype = 'nowrite'
2221

2322
vim.api.nvim_buf_set_name(buf, buf_name) -- the name is only needed so the buffer is picked up by Lsp with correct root
2423

2524
injections.set_highlighting()
2625
vim.api.nvim_set_option_value('filetype', 'lua', { buf = buf })
2726
vim.api.nvim_set_option_value('syntax', 'lua', { buf = buf })
2827

28+
vim.bo[buf].buftype = 'nowrite' -- must be last, otherwise LSP will not attach
29+
2930
vim.diagnostic.enable(false, { bufnr = buf })
3031

3132
mappings.set_console_mappings(buf)

lua/lua-console/utils.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ local function strip_local(lines)
359359
local ts = vim.treesitter
360360
local ret = {}
361361

362-
local start_row = math.max(0, vim.fn.line('.') - 1 - #lines)
362+
local start_row = math.max(-1, vim.fn.line('.') - 1 - #lines)
363363

364364
for i, line in ipairs(lines) do
365365
local cs, ce = 1, 1
@@ -368,8 +368,10 @@ local function strip_local(lines)
368368
cs, ce = line:find('local%s', ce)
369369

370370
if cs then
371-
local node = ts.get_node { pos = { start_row + i - 1, cs } }
372-
if node and node:parent():type() == 'chunk' then line = line:sub(1, cs - 1) .. line:sub(ce + 1) end
371+
local node = ts.get_node { pos = { start_row + i, cs } }
372+
if node and node:parent() and node:parent():type() == 'chunk' then
373+
line = line:sub(1, cs - 1) .. line:sub(ce + 1)
374+
end
373375
end
374376
end
375377

0 commit comments

Comments
 (0)