diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index bc9cfa5..5381bf6 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -5,7 +5,6 @@ local providers = require('symbols-outline.providers.init') local ui = require('symbols-outline.ui') local writer = require('symbols-outline.writer') local config = require('symbols-outline.config') -local lsp_utils = require('symbols-outline.utils.lsp_utils') local utils = require('symbols-outline.utils.init') local view = require('symbols-outline.view') @@ -51,11 +50,6 @@ local function __refresh() return 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) M.state.code_win = vim.api.nvim_get_current_win() @@ -81,17 +75,14 @@ function M._goto_location(change_focus) end function M._highlight_current_item(winnr) - local doesnt_have_lsp = not lsp_utils.is_buf_attached_to_lsp( - vim.api.nvim_win_get_buf(winnr or 0)) + local has_provider = providers.has_provider() local is_current_buffer_the_outline = M.state.outline_buf == vim.api.nvim_get_current_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 = (doesnt_have_lsp and is_not_markdown) or + local should_exit = (not has_provider) or doesnt_have_outline_buf or is_current_buffer_the_outline diff --git a/lua/symbols-outline/parser.lua b/lua/symbols-outline/parser.lua index 40fb415..4ebea02 100644 --- a/lua/symbols-outline/parser.lua +++ b/lua/symbols-outline/parser.lua @@ -52,7 +52,7 @@ local function parse_result(result, depth, hierarchy) deprecated = value.deprecated, kind = value.kind, icon = symbols.icon_from_kind(value.kind), - name = value.name, + name = value.name or value.text, detail = value.detail, line = selectionRange.start.line, character = selectionRange.start.character, diff --git a/lua/symbols-outline/providers/coc.lua b/lua/symbols-outline/providers/coc.lua new file mode 100644 index 0000000..bb57e1b --- /dev/null +++ b/lua/symbols-outline/providers/coc.lua @@ -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 diff --git a/lua/symbols-outline/providers/init.lua b/lua/symbols-outline/providers/init.lua index 8a39b8f..8c8bba1 100644 --- a/lua/symbols-outline/providers/init.lua +++ b/lua/symbols-outline/providers/init.lua @@ -2,9 +2,24 @@ local M = {} local providers = { 'symbols-outline/providers/nvim-lsp', + 'symbols-outline/providers/coc', '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 function M.request_symbols(on_symbols) for _, value in ipairs(providers) do diff --git a/lua/symbols-outline/symbols.lua b/lua/symbols-outline/symbols.lua index b7f2038..4345bed 100644 --- a/lua/symbols-outline/symbols.lua +++ b/lua/symbols-outline/symbols.lua @@ -12,6 +12,10 @@ M.kinds = { function M.icon_from_kind(kind) 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 kind > #M.kinds then kind = 19 end return symbols[M.kinds[kind]].icon diff --git a/lua/symbols-outline/utils/lsp_utils.lua b/lua/symbols-outline/utils/lsp_utils.lua index 57f6c16..83c410f 100644 --- a/lua/symbols-outline/utils/lsp_utils.lua +++ b/lua/symbols-outline/utils/lsp_utils.lua @@ -36,13 +36,4 @@ function M.is_buf_markdown(bufnr) return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown' 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