From ebf90dc9ee62878092c27b4285274711bff91fe6 Mon Sep 17 00:00:00 2001 From: hedy Date: Fri, 24 Nov 2023 14:59:45 +0800 Subject: [PATCH] fix(markdown): Don't include next heading in previous heading's range Somehow marksman also does this? As for treesitter (norg) it may be because treesitter includes the newline and the next line indent until the next heading, so the line of the next heading is included in the range of the previous heading. We manually -1 on the range end line to fix it. --- CHANGELOG.md | 5 +++++ lua/outline/providers/markdown.lua | 14 +++++--------- lua/outline/providers/norg.lua | 5 +++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10eaea2..9e6ae3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ - A built-in provider for `norg` files that displays headings in the outline is now provided. This requires `norg` parser to be installed for treesitter - Outline.nvim now supports per-tabpage outlines + ([#37](https://github.com/hedyhli/outline.nvim/issues/37)) ### Fixes @@ -99,6 +100,10 @@ ([#19](https://github.com/hedyhli/outline.nvim/issues/19)) - Fixed display of JSX Fragments due to recent update from `javascript` TS parser +- Markdown parser included the next heading when setting the end range for + previous heading. So when cursor was on the next heading, the previous heading + would also be highlighted in the outline. This is now fixed, but marksman LSP + would still do this. A "fix" is to add marksman into lsp client blacklist. ### Performance diff --git a/lua/outline/providers/markdown.lua b/lua/outline/providers/markdown.lua index f4a0d2d..876b331 100644 --- a/lua/outline/providers/markdown.lua +++ b/lua/outline/providers/markdown.lua @@ -80,8 +80,11 @@ function M.handle_markdown() for i = depth, max_level do if level_symbols[i] ~= nil then - level_symbols[i].selectionRange['end'].line = line - 1 - level_symbols[i].range['end'].line = line - 1 + -- -1 for 0-index, -1 to not include current line + -- TODO: This fix can be removed when we let highlight_hovered_item + -- account for current column position in addition to the line + level_symbols[i].selectionRange['end'].line = line - 2 + level_symbols[i].range['end'].line = line - 2 level_symbols[i] = nil end end @@ -106,13 +109,6 @@ function M.handle_markdown() ::nextline:: end - for i = 2, max_level do - if level_symbols[i] ~= nil then - level_symbols[i].selectionRange['end'].line = #lines - level_symbols[i].range['end'].line = #lines - end - end - return level_symbols[1].children end diff --git a/lua/outline/providers/norg.lua b/lua/outline/providers/norg.lua index 1de1ee8..451e8cd 100644 --- a/lua/outline/providers/norg.lua +++ b/lua/outline/providers/norg.lua @@ -102,6 +102,11 @@ function M.request_symbols(callback, opts) local current = { kind = 15, name = title, + -- Treesitter includes the last newline in the end range which spans + -- until the next heading, so we -1 + -- TODO: This fix can be removed when we let highlight_hovered_item + -- account for current column position in addition to the line. + -- FIXME: By the way the end character should be the EOL selectionRange = { start = { character = col1, line = row1 }, ['end'] = { character = col2, line = row2 - 1 },