feat(providers): Inital COC support
Closes #68 Still needs support for code actions/hover/rename etc
This commit is contained in:
@@ -5,7 +5,6 @@ local providers = require('symbols-outline.providers.init')
|
|||||||
local ui = require('symbols-outline.ui')
|
local ui = require('symbols-outline.ui')
|
||||||
local writer = require('symbols-outline.writer')
|
local writer = require('symbols-outline.writer')
|
||||||
local config = require('symbols-outline.config')
|
local config = require('symbols-outline.config')
|
||||||
local lsp_utils = require('symbols-outline.utils.lsp_utils')
|
|
||||||
local utils = require('symbols-outline.utils.init')
|
local utils = require('symbols-outline.utils.init')
|
||||||
local view = require('symbols-outline.view')
|
local view = require('symbols-outline.view')
|
||||||
|
|
||||||
@@ -51,11 +50,6 @@ local function __refresh()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local current_buf = vim.api.nvim_get_current_buf()
|
|
||||||
if lsp_utils.should_not_refresh(current_buf) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local items = parser.parse(response)
|
local items = parser.parse(response)
|
||||||
|
|
||||||
M.state.code_win = vim.api.nvim_get_current_win()
|
M.state.code_win = vim.api.nvim_get_current_win()
|
||||||
@@ -81,17 +75,14 @@ function M._goto_location(change_focus)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M._highlight_current_item(winnr)
|
function M._highlight_current_item(winnr)
|
||||||
local doesnt_have_lsp = not lsp_utils.is_buf_attached_to_lsp(
|
local has_provider = providers.has_provider()
|
||||||
vim.api.nvim_win_get_buf(winnr or 0))
|
|
||||||
|
|
||||||
local is_current_buffer_the_outline =
|
local is_current_buffer_the_outline =
|
||||||
M.state.outline_buf == vim.api.nvim_get_current_buf()
|
M.state.outline_buf == vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
local doesnt_have_outline_buf = not M.state.outline_buf
|
local doesnt_have_outline_buf = not M.state.outline_buf
|
||||||
|
|
||||||
local is_not_markdown = not lsp_utils.is_buf_markdown(0)
|
local should_exit = (not has_provider) or
|
||||||
|
|
||||||
local should_exit = (doesnt_have_lsp and is_not_markdown) or
|
|
||||||
doesnt_have_outline_buf or
|
doesnt_have_outline_buf or
|
||||||
is_current_buffer_the_outline
|
is_current_buffer_the_outline
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ local function parse_result(result, depth, hierarchy)
|
|||||||
deprecated = value.deprecated,
|
deprecated = value.deprecated,
|
||||||
kind = value.kind,
|
kind = value.kind,
|
||||||
icon = symbols.icon_from_kind(value.kind),
|
icon = symbols.icon_from_kind(value.kind),
|
||||||
name = value.name,
|
name = value.name or value.text,
|
||||||
detail = value.detail,
|
detail = value.detail,
|
||||||
line = selectionRange.start.line,
|
line = selectionRange.start.line,
|
||||||
character = selectionRange.start.character,
|
character = selectionRange.start.character,
|
||||||
|
|||||||
24
lua/symbols-outline/providers/coc.lua
Normal file
24
lua/symbols-outline/providers/coc.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
-- local config = require('symbols-outline.config')
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- probably change this
|
||||||
|
function M.should_use_provider(_)
|
||||||
|
local coc_installed = vim.fn.exists("*CocActionAsync")
|
||||||
|
|
||||||
|
if not coc_installed then return end
|
||||||
|
|
||||||
|
local coc_attached = vim.fn.call('CocAction', {'ensureDocument'})
|
||||||
|
local has_symbols = vim.fn.call('CocHasProvider', {'documentSymbol'})
|
||||||
|
|
||||||
|
return coc_attached and has_symbols;
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param on_symbols function
|
||||||
|
function M.request_symbols(on_symbols)
|
||||||
|
vim.fn.call('CocActionAsync', {'documentSymbols', function (_, symbols)
|
||||||
|
on_symbols{[1000000]={result=symbols}}
|
||||||
|
end})
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -2,9 +2,24 @@ local M = {}
|
|||||||
|
|
||||||
local providers = {
|
local providers = {
|
||||||
'symbols-outline/providers/nvim-lsp',
|
'symbols-outline/providers/nvim-lsp',
|
||||||
|
'symbols-outline/providers/coc',
|
||||||
'symbols-outline/providers/markdown'
|
'symbols-outline/providers/markdown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local current_provider;
|
||||||
|
|
||||||
|
function M.has_provider()
|
||||||
|
local ret = false;
|
||||||
|
for _, value in ipairs(providers) do
|
||||||
|
local provider = require(value)
|
||||||
|
if provider.should_use_provider(0) then
|
||||||
|
ret = true;
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
---@param on_symbols function
|
---@param on_symbols function
|
||||||
function M.request_symbols(on_symbols)
|
function M.request_symbols(on_symbols)
|
||||||
for _, value in ipairs(providers) do
|
for _, value in ipairs(providers) do
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ M.kinds = {
|
|||||||
function M.icon_from_kind(kind)
|
function M.icon_from_kind(kind)
|
||||||
local symbols = config.options.symbols
|
local symbols = config.options.symbols
|
||||||
|
|
||||||
|
if type(kind) == 'string' then
|
||||||
|
return symbols[kind].icon
|
||||||
|
end
|
||||||
|
|
||||||
-- If the kind is higher than the available ones then default to 'Object'
|
-- If the kind is higher than the available ones then default to 'Object'
|
||||||
if kind > #M.kinds then kind = 19 end
|
if kind > #M.kinds then kind = 19 end
|
||||||
return symbols[M.kinds[kind]].icon
|
return symbols[M.kinds[kind]].icon
|
||||||
|
|||||||
@@ -36,13 +36,4 @@ function M.is_buf_markdown(bufnr)
|
|||||||
return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown'
|
return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown'
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr number
|
|
||||||
---@return boolean
|
|
||||||
function M.should_not_refresh(bufnr)
|
|
||||||
if (not M.is_buf_markdown(bufnr)) and (not M.is_buf_attached_to_lsp(bufnr)) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user