Merge pull request #131 from onion108/0.11-patch

fix: migrating to 0.11
This commit is contained in:
~hedy
2025-04-19 21:00:41 +08:00
committed by GitHub
15 changed files with 211 additions and 87 deletions

View File

@@ -1,3 +1,4 @@
syntax = 'Lua52'
column_width = 100 column_width = 100
line_endings = 'Unix' line_endings = 'Unix'
indent_type = 'Spaces' indent_type = 'Spaces'

View File

@@ -918,7 +918,8 @@ symbols = {
```lua ```lua
symbols = { symbols = {
icon_fetcher = function(kind, bufnr, symbol) icon_fetcher = function(kind, bufnr, symbol)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') -- Use nvim_buf_get_option(bufnr, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value('ft', { buf = bufnr })
-- ... -- ...
end, end,
} }
@@ -1112,7 +1113,8 @@ and `icons` as fallback.
```lua ```lua
symbols = { symbols = {
icon_fetcher = function(kind, bufnr) icon_fetcher = function(kind, bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') -- Use nvim_buf_get_option(bufnr, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value('ft', { buf = bufnr })
-- ... -- ...
end, end,
} }
@@ -1152,7 +1154,8 @@ other filetypes.
```lua ```lua
symbols = { symbols = {
icon_fetcher = function(k, buf) icon_fetcher = function(k, buf)
local ft = vim.api.nvim_buf_get_option(buf, "ft") -- Use nvim_buf_get_option(bufnr, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
if ft == 'markdown' then if ft == 'markdown' then
return "" return ""
end end

View File

@@ -500,7 +500,7 @@ and uses regex; the built-in norg <./lua/outline/providers/norg.lua> provider
is an example which uses treesitter. is an example which uses treesitter.
All providers should support at least nvim 0.7. You can make use of All providers should support at least nvim 0.7. You can make use of
`_G._outline_nvim_has` with fields `[8]`, `[9]`, and `[10]`. For instance, `_G._outline_nvim_has` with fields `[8]`, `[9]`, `[10]`, and `[11]`. For instance,
`_G._outline_nvim_has[8]` is equivalent to: `vim.fn.has('nvim-0.8') == 1`. `_G._outline_nvim_has[8]` is equivalent to: `vim.fn.has('nvim-0.8') == 1`.
If a higher nvim version is required, it is recommended to check for this If a higher nvim version is required, it is recommended to check for this
@@ -806,7 +806,8 @@ based on the filetype.
>lua >lua
symbols = { symbols = {
icon_fetcher = function(kind, bufnr, symbol) icon_fetcher = function(kind, bufnr, symbol)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') -- Use nvim_buf_get_option_value(buf, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value('ft', { buf = bufnr })
-- ... -- ...
end, end,
} }
@@ -1007,7 +1008,8 @@ DIFFERENT ICONS BASED ON FILETYPE ~
>lua >lua
symbols = { symbols = {
icon_fetcher = function(kind, bufnr) icon_fetcher = function(kind, bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') -- Use nvim_buf_get_option_value(buf, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value('ft', { buf = bufnr })
-- ... -- ...
end, end,
} }
@@ -1048,7 +1050,8 @@ other filetypes.
>lua >lua
symbols = { symbols = {
icon_fetcher = function(k, buf) icon_fetcher = function(k, buf)
local ft = vim.api.nvim_buf_get_option(buf, "ft") -- Use nvim_buf_get_option_value(buf, 'ft') for nvim 0.7 users
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
if ft == 'markdown' then if ft == 'markdown' then
return "" return ""
end end

View File

@@ -208,7 +208,7 @@ end
---@param bufnr integer ---@param bufnr integer
---@return boolean include ---@return boolean include
function M.should_include_symbol(kind, bufnr) function M.should_include_symbol(kind, bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') local ft = utils.buf_get_option(bufnr, 'ft')
-- There can only be one kind in markdown and norg as of now -- There can only be one kind in markdown and norg as of now
if ft == 'markdown' or ft == 'norg' or kind == nil then if ft == 'markdown' or ft == 'norg' or kind == nil then
return true return true
@@ -232,7 +232,7 @@ function M.should_include_symbol(kind, bufnr)
return filter_table[kind] ~= false return filter_table[kind] ~= false
end end
---@param client lsp.client|number ---@param client vim.lsp.Client|number
function M.is_client_blacklisted(client) function M.is_client_blacklisted(client)
if not client then if not client then
return false return false

View File

@@ -1,6 +1,8 @@
---@class outline.Float ---@class outline.Float
local Float = {} local Float = {}
local utils = require('outline.utils')
---@class outline.Float ---@class outline.Float
---@field bufnr integer ---@field bufnr integer
---@field winnr integer ---@field winnr integer
@@ -19,7 +21,7 @@ function Float:open(lines, hl, title, indent)
indent = indent or 0 indent = indent or 0
self.bufnr = vim.api.nvim_create_buf(false, true) self.bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(self.bufnr, 'bufhidden', 'delete') utils.buf_set_option(self.bufnr, 'bufhidden', 'delete')
local maxwidth = 0 local maxwidth = 0
for _, l in ipairs(lines) do for _, l in ipairs(lines) do
@@ -60,22 +62,33 @@ function Float:open(lines, hl, title, indent)
end end
end end
vim.api.nvim_win_set_option(self.winnr, 'winfixwidth', true) utils.win_set_option(self.winnr, 'winfixwidth', true)
vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines) vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines)
vim.api.nvim_buf_set_option(self.bufnr, 'modifiable', false) utils.buf_set_option(self.bufnr, 'modifiable', false)
vim.api.nvim_buf_set_option(self.bufnr, 'ft', 'OutlineHelp') utils.buf_set_option(self.bufnr, 'ft', 'OutlineHelp')
if hl then if hl then
self.ns = vim.api.nvim_create_namespace('OutlineHelp') self.ns = vim.api.nvim_create_namespace('OutlineHelp')
for _, h in ipairs(hl) do for _, h in ipairs(hl) do
vim.api.nvim_buf_add_highlight( if _G._outline_nvim_has[11] then
self.bufnr, vim.hl.range(
self.ns, self.bufnr,
h.name, self.ns,
h.line, h.name,
h.from + indent, { h.line, h.from + indent },
(h.to ~= -1 and h.to + indent) or -1 { h.line, (h.to ~= -1 and h.to + indent) or -1 }
) )
else
---@diagnostic disable-next-line:deprecated
vim.api.nvim_buf_add_highlight(
self.bufnr,
self.ns,
h.name,
h.line,
h.from + indent,
(h.to ~= -1 and h.to + indent) or -1
)
end
end end
end end
end end

View File

@@ -10,7 +10,9 @@ local M = {
---@param bufnr integer ---@param bufnr integer
function M.clear_all_ns(bufnr) function M.clear_all_ns(bufnr)
if vim.api.nvim_buf_is_valid(bufnr) then if vim.api.nvim_buf_is_valid(bufnr) then
pcall(function() vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1) end) pcall(function()
vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1)
end)
end end
end end
@@ -29,9 +31,14 @@ function M.hovers(bufnr, nodes)
for line, node in ipairs(nodes) do for line, node in ipairs(nodes) do
if node.hovered then if node.hovered then
-- stylua: ignore start -- stylua: ignore start
vim.api.nvim_buf_add_highlight( if _G._outline_nvim_has[11] then
bufnr, M.ns.hover, 'OutlineCurrent', line - 1, node.prefix_length, -1 vim.hl.range(bufnr, M.ns.hover, 'OutlineCurrent', { line - 1, node.prefix_length }, { line - 1, -1 })
) else
---@diagnostic disable-next-line:deprecated
vim.api.nvim_buf_add_highlight(
bufnr, M.ns.hover, 'OutlineCurrent', line - 1, node.prefix_length, -1
)
end
-- stylua: ignore end -- stylua: ignore end
end end
end end
@@ -43,9 +50,14 @@ end
function M.items(bufnr, hl_list) function M.items(bufnr, hl_list)
for _, h in ipairs(hl_list) do for _, h in ipairs(hl_list) do
-- stylua: ignore start -- stylua: ignore start
vim.api.nvim_buf_add_highlight( if _G._outline_nvim_has[11] then
bufnr, M.ns.items, h.name, h.line - 1, h.from, h.to vim.hl.range(bufnr, M.ns.items, h.name, { h.line - 1, h.from }, { h.line - 1, h.to })
) else
---@diagnostic disable-next-line:deprecated
vim.api.nvim_buf_add_highlight(
bufnr, M.ns.items, h.name, h.line - 1, h.from, h.to
)
end
-- stylua: ignore end -- stylua: ignore end
end end
end end

View File

@@ -3,7 +3,7 @@ local cfg = require('outline.config')
local highlight = require('outline.highlight') local highlight = require('outline.highlight')
local providers = require('outline.providers.init') local providers = require('outline.providers.init')
local symbols = require('outline.symbols') local symbols = require('outline.symbols')
local utils = require('outline.utils.init') local utils = require('outline.utils')
local M = { local M = {
---@type outline.Sidebar[] ---@type outline.Sidebar[]
@@ -278,7 +278,7 @@ function M.show_status()
} }
if buf and vim.api.nvim_buf_is_valid(buf) then if buf and vim.api.nvim_buf_is_valid(buf) then
ctx.ft = vim.api.nvim_buf_get_option(buf, 'ft') ctx.ft = utils.buf_get_option(buf, 'ft')
ctx.filter = cfg.o.symbols.user_config_filter[ctx.ft] ctx.filter = cfg.o.symbols.user_config_filter[ctx.ft]
-- 'else' is handled in help.lua -- 'else' is handled in help.lua
end end
@@ -351,6 +351,7 @@ function M.setup(opts)
[8] = minor >= 8, [8] = minor >= 8,
[9] = minor >= 9, [9] = minor >= 9,
[10] = minor >= 10, [10] = minor >= 10,
[11] = minor >= 11,
} }
cfg.setup(opts) cfg.setup(opts)

View File

@@ -1,4 +1,5 @@
local cfg = require('outline.config') local cfg = require('outline.config')
local utils = require('outline.utils')
-- A floating window to preview the location of a symbol from the outline. -- A floating window to preview the location of a symbol from the outline.
-- Classical preview reads entire lines into a new buffer for preview. Live -- Classical preview reads entire lines into a new buffer for preview. Live
@@ -151,12 +152,12 @@ end
---Set buf & win options, and setup highlight ---Set buf & win options, and setup highlight
function Preview:setup() function Preview:setup()
vim.api.nvim_win_set_option(self.win, 'winhl', self.conf.winhl) utils.win_set_option(self.win, 'winhl', self.conf.winhl)
vim.api.nvim_win_set_option(self.win, 'winblend', self.conf.winblend) utils.win_set_option(self.win, 'winblend', self.conf.winblend)
local code_buf = self.s.code.buf local code_buf = self.s.code.buf
local ft = vim.api.nvim_buf_get_option(code_buf, 'filetype') local ft = utils.buf_get_option(code_buf, 'filetype')
vim.api.nvim_buf_set_option(self.buf, 'syntax', ft) utils.buf_set_option(self.buf, 'syntax', ft)
local ts_highlight_fn = vim.treesitter.start local ts_highlight_fn = vim.treesitter.start
if not _G._outline_nvim_has[8] then if not _G._outline_nvim_has[8] then
@@ -167,9 +168,9 @@ function Preview:setup()
end end
pcall(ts_highlight_fn, self.buf, ft) pcall(ts_highlight_fn, self.buf, ft)
vim.api.nvim_buf_set_option(self.buf, 'bufhidden', 'delete') utils.buf_set_option(self.buf, 'bufhidden', 'delete')
vim.api.nvim_buf_set_option(self.buf, 'modifiable', false) utils.buf_set_option(self.buf, 'modifiable', false)
vim.api.nvim_win_set_option(self.win, 'cursorline', true) utils.win_set_option(self.win, 'cursorline', true)
end end
function Preview:update() function Preview:update()
@@ -180,9 +181,9 @@ function Preview:update()
local lines = vim.api.nvim_buf_get_lines(self.s.code.buf, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(self.s.code.buf, 0, -1, false)
if self.buf ~= nil then if self.buf ~= nil then
vim.api.nvim_buf_set_option(self.buf, 'modifiable', true) utils.buf_set_option(self.buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines) vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(self.buf, 'modifiable', false) utils.buf_set_option(self.buf, 'modifiable', false)
vim.api.nvim_win_set_cursor(self.win, { node.line + 1, node.character }) vim.api.nvim_win_set_cursor(self.win, { node.line + 1, node.character })
end end
end end
@@ -221,7 +222,7 @@ end
---Creates new preview window and sets the content. Calls setup and set_lines. ---Creates new preview window and sets the content. Calls setup and set_lines.
function LivePreview:create() function LivePreview:create()
self.codewin = self.s.code.win self.codewin = self.s.code.win
self.initial_cursorline = vim.api.nvim_win_get_option(self.s.code.win, 'cursorline') self.initial_cursorline = utils.win_get_option(self.s.code.win, 'cursorline')
self.outline_height = vim.api.nvim_win_get_height(self.s.view.win) self.outline_height = vim.api.nvim_win_get_height(self.s.view.win)
self.width = cfg.get_preview_width(self.conf) self.width = cfg.get_preview_width(self.conf)
self.height = cfg.get_preview_height(self.conf, self.outline_height) self.height = cfg.get_preview_height(self.conf, self.outline_height)
@@ -256,9 +257,9 @@ end
---Set buf & win options, and autocmds ---Set buf & win options, and autocmds
function LivePreview:setup() function LivePreview:setup()
vim.api.nvim_win_set_option(self.win, 'winhl', self.conf.winhl) utils.win_set_option(self.win, 'winhl', self.conf.winhl)
vim.api.nvim_win_set_option(self.win, 'winblend', self.conf.winblend) utils.win_set_option(self.win, 'winblend', self.conf.winblend)
vim.api.nvim_win_set_option(self.win, 'cursorline', true) utils.win_set_option(self.win, 'cursorline', true)
vim.api.nvim_create_autocmd('WinClosed', { vim.api.nvim_create_autocmd('WinClosed', {
pattern = tostring(self.win), pattern = tostring(self.win),
@@ -273,7 +274,7 @@ function LivePreview:setup()
once = true, once = true,
callback = function() callback = function()
-- This doesn't work at all? -- This doesn't work at all?
vim.api.nvim_win_set_option(self.win, 'cursorline', self.initial_cursorline) utils.win_set_option(self.win, 'cursorline', self.initial_cursorline)
end, end,
}) })
end end
@@ -286,7 +287,7 @@ end
function LivePreview:focus() function LivePreview:focus()
vim.api.nvim_set_current_win(self.win) vim.api.nvim_set_current_win(self.win)
-- Remove this when the autocmd for WinEnter works above -- Remove this when the autocmd for WinEnter works above
vim.api.nvim_win_set_option(self.win, 'cursorline', self.initial_cursorline) utils.win_set_option(self.win, 'cursorline', self.initial_cursorline)
end end
---Create, focus, or update preview ---Create, focus, or update preview

View File

@@ -15,11 +15,13 @@ local M = {
name = 'markdown', name = 'markdown',
} }
local utils = require('outline.utils')
---@param bufnr integer ---@param bufnr integer
---@param config table? ---@param config table?
---@return boolean ft_is_markdown ---@return boolean ft_is_markdown
function M.supports_buffer(bufnr, config) function M.supports_buffer(bufnr, config)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft') local ft = utils.buf_get_option(bufnr, 'ft')
if config and config.filetypes then if config and config.filetypes then
for _, ft_check in ipairs(config.filetypes) do for _, ft_check in ipairs(config.filetypes) do
if ft_check == ft then if ft_check == ft then
@@ -27,7 +29,7 @@ function M.supports_buffer(bufnr, config)
end end
end end
end end
return ft == "markdown" return ft == 'markdown'
end end
-- Parses markdown files and returns a table of SymbolInformation[] which is -- Parses markdown files and returns a table of SymbolInformation[] which is
@@ -47,8 +49,8 @@ function M.handle_markdown()
goto nextline goto nextline
end end
local next_value = lines[line+1] local next_value = lines[line + 1]
local is_emtpy_line = #value:gsub("^%s*(.-)%s*$", "%1") == 0 local is_emtpy_line = #value:gsub('^%s*(.-)%s*$', '%1') == 0
local header, title = string.match(value, '^(#+)%s+(.+)$') local header, title = string.match(value, '^(#+)%s+(.+)$')
if not header and next_value and not is_emtpy_line then if not header and next_value and not is_emtpy_line then

View File

@@ -17,11 +17,12 @@ local M = {
] ]
]], ]],
} }
local utils = require('outline.utils')
---@param bufnr integer ---@param bufnr integer
---@param config table? ---@param config table?
function M.supports_buffer(bufnr, config) function M.supports_buffer(bufnr, config)
if vim.api.nvim_buf_get_option(bufnr, 'ft') ~= 'norg' then if utils.buf_get_option(bufnr, 'ft') ~= 'norg' then
return false return false
end end

View File

@@ -1,6 +1,7 @@
local cfg = require('outline.config') local cfg = require('outline.config')
local jsx = require('outline.providers.jsx') local jsx = require('outline.providers.jsx')
local lsp_utils = require('outline.utils.lsp') local lsp_utils = require('outline.utils.lsp')
local utils = require('outline.utils')
local l = vim.lsp local l = vim.lsp
@@ -18,7 +19,7 @@ function M.get_status(info)
return { 'client: ' .. info.client.name } return { 'client: ' .. info.client.name }
end end
---@param client lsp.client ---@param client vim.lsp.Client
---@param capability string ---@param capability string
---@return boolean ---@return boolean
local function _check_client(client, capability) local function _check_client(client, capability)
@@ -30,7 +31,7 @@ end
---@param bufnr integer ---@param bufnr integer
---@param capability string ---@param capability string
---@return lsp.client? ---@return vim.lsp.Client?
local function get_appropriate_client(bufnr, capability) local function get_appropriate_client(bufnr, capability)
local clients, use_client local clients, use_client
@@ -38,6 +39,7 @@ local function get_appropriate_client(bufnr, capability)
if _G._outline_nvim_has[10] then if _G._outline_nvim_has[10] then
clients = l.get_clients({ bufnr = bufnr }) clients = l.get_clients({ bufnr = bufnr })
else else
---@diagnostic disable-next-line: deprecated
clients = l.get_active_clients({ bufnr = bufnr }) clients = l.get_active_clients({ bufnr = bufnr })
end end
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
@@ -97,14 +99,22 @@ function M.request_symbols(on_symbols, opts, info)
textDocument = l.util.make_text_document_params(), textDocument = l.util.make_text_document_params(),
} }
-- XXX: Is bufnr=0 ok here? -- XXX: Is bufnr=0 ok here?
local status = info.client.request('textDocument/documentSymbol', params, function(err, response) local method = 'textDocument/documentSymbol'
local callback = function(err, response)
if err or not response then if err or not response then
on_symbols(response, opts) on_symbols(response, opts)
else else
response = postprocess_symbols(response) response = postprocess_symbols(response)
on_symbols(response, opts) on_symbols(response, opts)
end end
end, 0) end
local bufnr = 0
local status
if _G._outline_nvim_has[11] then
status = info.client:request(method, params, callback, bufnr)
else
status = info.client.request(method, params, callback, bufnr)
end
if not status then if not status then
on_symbols(nil, opts) on_symbols(nil, opts)
end end
@@ -134,7 +144,7 @@ end
---@see rename_symbol ---@see rename_symbol
---@param sidebar outline.Sidebar ---@param sidebar outline.Sidebar
---@param client lsp.client ---@param client vim.lsp.Client
---@param node outline.FlatSymbol ---@param node outline.FlatSymbol
---@return boolean success ---@return boolean success
local function legacy_rename(sidebar, client, node) local function legacy_rename(sidebar, client, node)
@@ -150,8 +160,15 @@ local function legacy_rename(sidebar, client, node)
bufnr = sidebar.code.buf, bufnr = sidebar.code.buf,
newName = new_name, newName = new_name,
} }
local status, err = local status, err
client.request_sync('textDocument/rename', params, request_timeout, sidebar.code.buf) if _G._outline_nvim_has[11] then
status, err =
client:request_sync('textDocument/rename', params, request_timeout, sidebar.code.buf)
else
---@diagnostic disable-next-line
status, err =
client.request_sync('textDocument/rename', params, request_timeout, sidebar.code.buf)
end
if status == nil or status.err or err or status.result == nil then if status == nil or status.err or err or status.result == nil then
return false return false
end end
@@ -210,13 +227,23 @@ function M.show_hover(sidebar)
bufnr = sidebar.code.buf, bufnr = sidebar.code.buf,
} }
local status, err = client.request_sync('textDocument/hover', params, request_timeout) local status, err
if _G._outline_nvim_has[11] then
status, err = client:request_sync('textDocument/hover', params, request_timeout)
else
status, err = client.request_sync('textDocument/hover', params, request_timeout)
end
if status == nil or status.err or err or not status.result or not status.result.contents then if status == nil or status.err or err or not status.result or not status.result.contents then
return false return false
end end
local md_lines = l.util.convert_input_to_markdown_lines(status.result.contents) local md_lines = l.util.convert_input_to_markdown_lines(status.result.contents)
md_lines = l.util.trim_empty_lines(md_lines) if _G._outline_nvim_has[10] then
md_lines = vim.split(status.result.contents, '\n', { trimempty = true })
else
---@diagnostic disable-next-line:deprecated
md_lines = l.util.trim_empty_lines(md_lines)
end
if vim.tbl_isempty(md_lines) then if vim.tbl_isempty(md_lines) then
-- Request was successful, but there is no hover content -- Request was successful, but there is no hover content
return true return true
@@ -226,7 +253,7 @@ function M.show_hover(sidebar)
border = cfg.o.preview_window.border, border = cfg.o.preview_window.border,
width = code_width, width = code_width,
}) })
vim.api.nvim_win_set_option(winnr, 'winhighlight', cfg.o.preview_window.winhl) utils.win_set_option(winnr, 'winhighlight', cfg.o.preview_window.winhl)
return true return true
end end

View File

@@ -5,7 +5,7 @@ local folding = require('outline.folding')
local parser = require('outline.parser') local parser = require('outline.parser')
local providers = require('outline.providers.init') local providers = require('outline.providers.init')
local symbols = require('outline.symbols') local symbols = require('outline.symbols')
local utils = require('outline.utils.init') local utils = require('outline.utils')
local strlen = vim.fn.strlen local strlen = vim.fn.strlen
@@ -249,7 +249,7 @@ function Sidebar:update_cursor_style()
local hide_cursor = type(cl) ~= 'string' local hide_cursor = type(cl) ~= 'string'
if cl == 'focus_in_outline' or cl == 'focus_in_code' then if cl == 'focus_in_outline' or cl == 'focus_in_code' then
vim.api.nvim_win_set_option(0, 'cursorline', cl == 'focus_in_outline') utils.win_set_option(0, 'cursorline', cl == 'focus_in_outline')
hide_cursor = cl == 'focus_in_outline' hide_cursor = cl == 'focus_in_outline'
end end
@@ -265,7 +265,7 @@ function Sidebar:reset_cursor_style()
local cl = cfg.o.outline_window.show_cursorline local cl = cfg.o.outline_window.show_cursorline
if cl == 'focus_in_outline' or cl == 'focus_in_code' then if cl == 'focus_in_outline' or cl == 'focus_in_code' then
vim.api.nvim_win_set_option(0, 'cursorline', cl ~= 'focus_in_outline') utils.win_set_option(0, 'cursorline', cl ~= 'focus_in_outline')
end end
-- vim.opt doesn't seem to provide a way to remove last item, like a pop() -- vim.opt doesn't seem to provide a way to remove last item, like a pop()
-- vim.o.guicursor = vim.o.guicursor:gsub(",n.-:.-$", "") -- vim.o.guicursor = vim.o.guicursor:gsub(",n.-:.-$", "")
@@ -344,8 +344,8 @@ function Sidebar:__refresh()
if focused_outline or not self.view:is_open() then if focused_outline or not self.view:is_open() then
return return
end end
local ft = vim.api.nvim_buf_get_option(buf, 'ft') local ft = utils.buf_get_option(buf, 'ft')
local listed = vim.api.nvim_buf_get_option(buf, 'buflisted') local listed = utils.buf_get_option(buf, 'ft')
if ft == 'OutlineHelp' or not (listed or ft == 'help') then if ft == 'OutlineHelp' or not (listed or ft == 'help') then
return return
end end

View File

@@ -38,7 +38,14 @@ function M.flash_highlight(winnr, lnum, durationMs, hl_group)
durationMs = 400 durationMs = 400
end end
local bufnr = vim.api.nvim_win_get_buf(winnr) local bufnr = vim.api.nvim_win_get_buf(winnr)
local ns = vim.api.nvim_buf_add_highlight(bufnr, 0, hl_group, lnum - 1, 0, -1) local ns
if _G._outline_nvim_has[11] then
ns = vim.api.nvim_create_namespace('_outline_nvim_flash')
vim.hl.range(bufnr, ns, hl_group, { lnum - 1, 0 }, { lnum - 1, -1 })
else
---@diagnostic disable-next-line:deprecated
ns = vim.api.nvim_buf_add_highlight(bufnr, 0, hl_group, lnum - 1, 0, -1)
end
local remove_highlight = function() local remove_highlight = function()
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns, 0, -1) pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns, 0, -1)
end end
@@ -116,4 +123,54 @@ function M.deepcopy_excluding(t, keys)
return res return res
end end
--- Get option value of given buffer.
--- @param bufnr integer
--- @param name string
--- @return any
function M.buf_get_option(bufnr, name)
if _G._outline_nvim_has[10] then
return vim.api.nvim_get_option_value(name, { buf = bufnr })
else
---@diagnostic disable-next-line:deprecated
return vim.api.nvim_buf_get_option(bufnr, name)
end
end
--- Set option value of given buffer.
--- @param bufnr integer
--- @param name string
function M.buf_set_option(bufnr, name, value)
if _G._outline_nvim_has[10] then
return vim.api.nvim_set_option_value(name, value, { buf = bufnr })
else
---@diagnostic disable-next-line:deprecated
return vim.api.nvim_buf_set_option(bufnr, name, value)
end
end
--- Get option value of given window.
--- @param winnr integer
--- @param name string
--- @return any
function M.win_get_option(winnr, name)
if _G._outline_nvim_has[10] then
return vim.api.nvim_get_option_value(name, { win = winnr })
else
---@diagnostic disable-next-line:deprecated
return vim.api.nvim_buf_get_option(winnr, name)
end
end
--- Set option value of given window.
--- @param winnr integer
--- @param name string
function M.win_set_option(winnr, name, value)
if _G._outline_nvim_has[10] then
return vim.api.nvim_set_option_value(name, value, { win = winnr })
else
---@diagnostic disable-next-line:deprecated
return vim.api.nvim_win_set_option(winnr, name, value)
end
end
return M return M

View File

@@ -1,4 +1,5 @@
local config = require('outline.config') local config = require('outline.config')
local utils = require('outline.utils')
local M = {} local M = {}
@@ -7,13 +8,14 @@ function M.is_buf_attached_to_lsp(bufnr)
if _G._outline_nvim_has[10] then if _G._outline_nvim_has[10] then
clients = vim.lsp.get_clients({ bufnr = bufnr or 0 }) clients = vim.lsp.get_clients({ bufnr = bufnr or 0 })
else else
---@diagnostic disable-next-line: deprecated
clients = vim.lsp.get_active_clients({ bufnr = bufnr or 0 }) clients = vim.lsp.get_active_clients({ bufnr = bufnr or 0 })
end end
return clients ~= nil and #clients > 0 return clients ~= nil and #clients > 0
end end
function M.is_buf_markdown(bufnr) function M.is_buf_markdown(bufnr)
return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown' return utils.buf_get_option(bufnr, 'ft') == 'markdown'
end end
--- Merge all client token lists in an LSP response --- Merge all client token lists in an LSP response

View File

@@ -1,5 +1,6 @@
local cfg = require('outline.config') local cfg = require('outline.config')
local highlight = require('outline.highlight') local highlight = require('outline.highlight')
local utils = require('outline.utils')
---@class outline.View ---@class outline.View
local View = {} local View = {}
@@ -19,10 +20,10 @@ function View:setup_view(split_command)
self.buf = vim.api.nvim_create_buf(false, true) self.buf = vim.api.nvim_create_buf(false, true)
-- set filetype -- set filetype
vim.api.nvim_buf_set_option(self.buf, 'filetype', 'Outline') utils.buf_set_option(self.buf, 'filetype', 'Outline')
-- delete buffer when window is closed / buffer is hidden -- delete buffer when window is closed / buffer is hidden
vim.api.nvim_buf_set_option(self.buf, 'bufhidden', 'delete') utils.buf_set_option(self.buf, 'bufhidden', 'delete')
-- create a split -- create a split
vim.cmd(split_command) vim.cmd(split_command)
@@ -38,38 +39,38 @@ function View:setup_view(split_command)
end end
-- window stuff -- window stuff
vim.api.nvim_win_set_option(self.win, 'spell', false) utils.win_set_option(self.win, 'spell', false)
vim.api.nvim_win_set_option(self.win, 'signcolumn', 'no') utils.win_set_option(self.win, 'signcolumn', 'no')
vim.api.nvim_win_set_option(self.win, 'foldcolumn', '0') utils.win_set_option(self.win, 'foldcolumn', '0')
vim.api.nvim_win_set_option(self.win, 'number', false) utils.win_set_option(self.win, 'number', false)
vim.api.nvim_win_set_option(self.win, 'relativenumber', false) utils.win_set_option(self.win, 'relativenumber', false)
vim.api.nvim_win_set_option(self.win, 'winfixwidth', true) utils.win_set_option(self.win, 'winfixwidth', true)
vim.api.nvim_win_set_option(self.win, 'list', false) utils.win_set_option(self.win, 'list', false)
vim.api.nvim_win_set_option(self.win, 'wrap', cfg.o.outline_window.wrap) utils.win_set_option(self.win, 'wrap', cfg.o.outline_window.wrap)
vim.api.nvim_win_set_option(self.win, 'winhl', cfg.o.outline_window.winhl) utils.win_set_option(self.win, 'winhl', cfg.o.outline_window.winhl)
vim.api.nvim_win_set_option(self.win, 'linebreak', true) -- only has effect when wrap=true utils.win_set_option(self.win, 'linebreak', true) -- only has effect when wrap=true
vim.api.nvim_win_set_option(self.win, 'breakindent', true) -- only has effect when wrap=true utils.win_set_option(self.win, 'breakindent', true) -- only has effect when wrap=true
-- Would be nice to use guides.markers.vertical as part of showbreak to keep -- Would be nice to use guides.markers.vertical as part of showbreak to keep
-- continuity of the tree UI, but there's currently no way to style the -- continuity of the tree UI, but there's currently no way to style the
-- color, apart from globally overriding hl-NonText, which will potentially -- color, apart from globally overriding hl-NonText, which will potentially
-- mess with other theme/user settings. So just use empty spaces for now. -- mess with other theme/user settings. So just use empty spaces for now.
vim.api.nvim_win_set_option(self.win, 'showbreak', ' ') -- only has effect when wrap=true. utils.win_set_option(self.win, 'showbreak', ' ') -- only has effect when wrap=true.
-- buffer stuff -- buffer stuff
local tab = vim.api.nvim_get_current_tabpage() local tab = vim.api.nvim_get_current_tabpage()
vim.api.nvim_buf_set_name(self.buf, 'OUTLINE_' .. tostring(tab)) vim.api.nvim_buf_set_name(self.buf, 'OUTLINE_' .. tostring(tab))
vim.api.nvim_buf_set_option(self.buf, 'modifiable', false) utils.buf_set_option(self.buf, 'modifiable', false)
if cfg.o.outline_window.show_numbers or cfg.o.outline_window.show_relative_numbers then if cfg.o.outline_window.show_numbers or cfg.o.outline_window.show_relative_numbers then
vim.api.nvim_win_set_option(self.win, 'nu', true) utils.win_set_option(self.win, 'nu', true)
end end
if cfg.o.outline_window.show_relative_numbers then if cfg.o.outline_window.show_relative_numbers then
vim.api.nvim_win_set_option(self.win, 'rnu', true) utils.win_set_option(self.win, 'rnu', true)
end end
local cl = cfg.o.outline_window.show_cursorline local cl = cfg.o.outline_window.show_cursorline
if cl == true or cl == 'focus_in_outline' then if cl == true or cl == 'focus_in_outline' then
vim.api.nvim_win_set_option(self.win, 'cursorline', true) utils.win_set_option(self.win, 'cursorline', true)
end end
end end
@@ -100,9 +101,9 @@ end
---@param lines string[] ---@param lines string[]
function View:rewrite_lines(lines) function View:rewrite_lines(lines)
if self.buf and vim.api.nvim_buf_is_valid(self.buf) then if self.buf and vim.api.nvim_buf_is_valid(self.buf) then
vim.api.nvim_buf_set_option(self.buf, 'modifiable', true) utils.buf_set_option(self.buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines) vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(self.buf, 'modifiable', false) utils.buf_set_option(self.buf, 'modifiable', false)
end end
end end