MAJOR: Project rename and preparation for v1.0.0
I hope I haven't missed any for the renames!
This commit is contained in:
96
lua/outline/providers/coc.lua
Normal file
96
lua/outline/providers/coc.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
local M = {}
|
||||
|
||||
function M.should_use_provider(_)
|
||||
local not_coc_installed = vim.fn.exists '*CocActionAsync' == 0
|
||||
local not_coc_service_initialized = vim.g.coc_service_initialized == 0
|
||||
|
||||
if not_coc_installed or not_coc_service_initialized 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
|
||||
|
||||
function M.hover_info(_, _, on_info)
|
||||
on_info(nil, {
|
||||
contents = {
|
||||
kind = 'markdown',
|
||||
contents = { 'No extra information availaible!' },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
---@param result table
|
||||
local function convert_symbols(result)
|
||||
local s = {}
|
||||
local kinds_index = {}
|
||||
-- create a inverse indexing of symbols.kind
|
||||
local symbols = require("outline.symbols")
|
||||
for k, v in pairs(symbols.kinds) do
|
||||
kinds_index[v] = k
|
||||
end
|
||||
-- rebuild coc.nvim symbol list hierarchy according to the 'level' key
|
||||
for _, value in pairs(result) do
|
||||
value.children = {}
|
||||
value.kind = kinds_index[value.kind]
|
||||
if #s == 0 then
|
||||
table.insert(s, value)
|
||||
goto continue
|
||||
end
|
||||
if value.level == s[#s].level then
|
||||
if value.level == 0 then
|
||||
table.insert(s, value)
|
||||
goto continue
|
||||
end
|
||||
local tmp = s[#s]
|
||||
table.remove(s)
|
||||
table.insert(s[#s].children, tmp)
|
||||
table.insert(s, value)
|
||||
elseif value.level == s[#s].level + 1 then
|
||||
table.insert(s[#s].children, value)
|
||||
elseif value.level == s[#s].level + 2 then
|
||||
local tmp = s[#s].children[#(s[#s].children)]
|
||||
table.remove(s[#s].children)
|
||||
table.insert(s, tmp)
|
||||
table.insert(s[#s].children, value)
|
||||
elseif value.level < s[#s].level then
|
||||
while value.level < s[#s].level do
|
||||
local tmp = s[#s]
|
||||
table.remove(s)
|
||||
table.insert(s[#s].children, tmp)
|
||||
end
|
||||
if s[#s].level ~= 0 then
|
||||
local tmp = s[#s]
|
||||
table.remove(s)
|
||||
table.insert(s[#s].children, tmp)
|
||||
table.insert(s, value)
|
||||
else
|
||||
table.insert(s, value)
|
||||
end
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
local top = s[#s]
|
||||
while top.level ~= 0 do
|
||||
table.remove(s)
|
||||
table.insert(s[#s].children, top)
|
||||
top = s[#s]
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
---@param opts table
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
vim.fn.call('CocActionAsync', {
|
||||
'documentSymbols',
|
||||
function(_, symbols)
|
||||
on_symbols({ [1000000] = { result = convert_symbols(symbols) } }, opts)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
38
lua/outline/providers/init.lua
Normal file
38
lua/outline/providers/init.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
local M = {}
|
||||
|
||||
local providers = {
|
||||
'outline/providers/nvim-lsp',
|
||||
'outline/providers/coc',
|
||||
'outline/providers/markdown',
|
||||
}
|
||||
|
||||
_G._symbols_outline_current_provider = nil
|
||||
|
||||
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
|
||||
---@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._symbols_outline_current_provider = provider
|
||||
_G._symbols_outline_current_provider.name = value
|
||||
provider.request_symbols(on_symbols, opts)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
return M
|
||||
25
lua/outline/providers/markdown.lua
Normal file
25
lua/outline/providers/markdown.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
local md_parser = require 'outline.markdown'
|
||||
|
||||
local M = {}
|
||||
|
||||
-- probably change this
|
||||
function M.should_use_provider(bufnr)
|
||||
return string.match(vim.api.nvim_buf_get_option(bufnr, 'ft'), 'markdown')
|
||||
end
|
||||
|
||||
function M.hover_info(_, _, on_info)
|
||||
on_info(nil, {
|
||||
contents = {
|
||||
kind = 'markdown',
|
||||
contents = { 'No extra information availaible!' },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
---@param opts table
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
on_symbols(md_parser.handle_markdown(), opts)
|
||||
end
|
||||
|
||||
return M
|
||||
84
lua/outline/providers/nvim-lsp.lua
Normal file
84
lua/outline/providers/nvim-lsp.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
local config = require 'outline.config'
|
||||
local lsp_utils = require 'outline.utils.lsp_utils'
|
||||
local jsx = require 'outline.utils.jsx'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function getParams()
|
||||
return { textDocument = vim.lsp.util.make_text_document_params() }
|
||||
end
|
||||
|
||||
function M.hover_info(bufnr, params, on_info)
|
||||
local clients = vim.lsp.buf_get_clients(bufnr)
|
||||
local used_client
|
||||
|
||||
for id, client in pairs(clients) do
|
||||
if config.is_client_blacklisted(id) then
|
||||
goto continue
|
||||
else
|
||||
if client.server_capabilities.hoverProvider then
|
||||
used_client = client
|
||||
break
|
||||
end
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
|
||||
if not used_client then
|
||||
on_info(nil, {
|
||||
contents = {
|
||||
kind = 'markdown',
|
||||
content = { 'No extra information availaible!' },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
used_client.request('textDocument/hover', params, on_info, bufnr)
|
||||
end
|
||||
|
||||
-- probably change this
|
||||
function M.should_use_provider(bufnr)
|
||||
local clients = vim.lsp.buf_get_clients(bufnr)
|
||||
local ret = false
|
||||
|
||||
for id, client in pairs(clients) do
|
||||
if config.is_client_blacklisted(id) then
|
||||
goto continue
|
||||
else
|
||||
if client.server_capabilities.documentSymbolProvider then
|
||||
ret = true
|
||||
break
|
||||
end
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
function M.postprocess_symbols(response)
|
||||
local symbols = lsp_utils.flatten_response(response)
|
||||
|
||||
local jsx_symbols = jsx.get_symbols()
|
||||
|
||||
if #jsx_symbols > 0 then
|
||||
return lsp_utils.merge_symbols(symbols, jsx_symbols)
|
||||
else
|
||||
return symbols
|
||||
end
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
vim.lsp.buf_request_all(
|
||||
0,
|
||||
'textDocument/documentSymbol',
|
||||
getParams(),
|
||||
function (response)
|
||||
response = M.postprocess_symbols(response)
|
||||
on_symbols(response, opts)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user