feat: Better provider info and fix LSP deprecated warnings

- Provider priorities can now be configured through `providers.priority`

- Each provider can have a get_status() function that returns a string
  for its status. For LSP it returns the client name.

- :OutlineStatus logic refactored, together with provider checking
  functions in `providers/init.lua`

- Switch from vim.lsp.buf_get_clients to vim.lsp.get_active_clients
  (former was deprecated)

- Fixed a careless mistake from symbols-outline that seems to be an
  unreachable bug (lsp)
This commit is contained in:
hedy
2023-11-16 15:41:37 +08:00
parent 22051b6555
commit 5278eb5b2b
6 changed files with 120 additions and 54 deletions

View File

@@ -1,44 +1,43 @@
local M = {}
local cfg = require "outline.config"
-- NOTE: There is in fact a markdown LSP that can provide symbols. However on
-- buffer open the LSP may not be attached immediately. Before the LSP is ready
-- if the user opens the outline, our own markdown provider will be used. After
-- refreshing/reopening, the provider will then switch to the LSP (if the user
-- has a markdown LSP).
local providers = {
'outline/providers/nvim-lsp',
'outline/providers/coc',
'outline/providers/markdown',
}
local M = {}
local import_prefix = "outline/providers/"
_G._outline_current_provider = nil
function M.has_provider()
local ret = false
for _, value in ipairs(providers) do
local provider = require(value)
function M.find_provider()
if not M.providers then
M.providers = vim.tbl_map(function(p) return import_prefix..p end, cfg.get_providers())
end
for _, name in ipairs(M.providers) do
local provider = require(name)
if provider.should_use_provider(0) then
ret = true
break
return provider, name
end
end
return ret
return nil, nil
end
---@return boolean found_provider
function M.has_provider()
return M.find_provider() ~= nil
end
---@param on_symbols function
---@param opts outline.OutlineOpts?
---@return boolean found_provider
function M.request_symbols(on_symbols, opts)
for _, value in ipairs(providers) do
local provider = require(value)
if provider.should_use_provider(0) then
_G._outline_current_provider = provider
_G._outline_current_provider.name = value
provider.request_symbols(on_symbols, opts)
return true
end
local provider, name = M.find_provider()
if not provider then
return false
end
return false
_G._outline_current_provider = provider
if not provider.name then
_G._outline_current_provider.name = name
end
provider.request_symbols(on_symbols, opts)
return true
end
return M