Skip to content

Commit

Permalink
chore: wip backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitx committed Jan 13, 2024
1 parent 00b9f9e commit 2ff9db3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
26 changes: 25 additions & 1 deletion lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3486,7 +3486,31 @@ M.cmd.LspProbe = function(params)
vim.split(vim.inspect(results) .. "\n\n" .. vim.json.encode(results), "\n")
)
vim.api.nvim_win_set_buf(0, tbuf)
end, 2, false)
end, 2, true)
end

M.cmd.LspWorkspaceSymbols = function(params)
local lsp = require("gp.lsp")

local buf = vim.api.nvim_get_current_buf()

lsp.workspace_symbols(buf, "", function(results)
local tbuf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(tbuf, 0, -1, false, vim.split(vim.inspect(results), "\n"))
vim.api.nvim_win_set_buf(0, tbuf)
end)
end

M.cmd.LspDocumentSymbols = function(params)
local lsp = require("gp.lsp")

local buf = vim.api.nvim_get_current_buf()

lsp.root_document_symbols(buf, function(results)
local tbuf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(tbuf, 0, -1, false, vim.split(vim.inspect(results), "\n"))
vim.api.nvim_win_set_buf(0, tbuf)
end)
end

return M
9 changes: 9 additions & 0 deletions lua/gp/lsp/ft/cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ return {
Function = {
["gp_lsp_probe()"] = "void",
},
Module = {
std = {},
},
Struct = {
["std::uses_allocator<typename, typename>"] = {},
},
Class = {
["std::uniform_int_distribution<typename IntType>"] = {},
},
Interface = {
Class = {},
FILE = {},
Expand Down
41 changes: 41 additions & 0 deletions lua/gp/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,45 @@ M.completion = function(row, col, bufnr, callback, filtered)
end
end)
end

---@param bufnr integer|nil buffer handle or 0 for current, defaults to current
---@param callback function | nil receives document symbol result
---@param filtered table | nil filtered out items with given label
M.root_document_symbols = function(bufnr, callback, filtered)
local params = M.make_given_position_param(0, 0, bufnr)

vim.lsp.buf_request_all(
bufnr,
"textDocument/documentSymbol",
{ textDocument = params.textDocument },
function(results)
local items = {}
for _, r in pairs(results) do
local result = r.result and r.result or {}
for _, item in ipairs(result) do
local kind = vim.lsp.protocol.SymbolKind[item.kind] or ""
local label = item.name:match("^[%s•]*(.-)[%s•]*$")
local detail = item.detail or ""
if not (filtered and filtered[kind] and filtered[kind][label]) then
items[kind] = items[kind] or {}
items[kind][label] = detail or ""
end
end
end
if callback then
callback(items)
end
end
)
end

M.workspace_symbols = function(bufnr, query, callback)
local params = { query = query or "" }
vim.lsp.buf_request_all(bufnr, "workspace/symbol", params, function(results)
if callback then
callback(results)
end
end)
end

return M
2 changes: 1 addition & 1 deletion lua/gp/spinner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function M.stop_spinner()
M._spinner_timer:stop()
M._spinner_timer:close()
M._spinner_timer = nil
vim.api.nvim_echo({ { " ", "Normal" } }, false, {})
vim.api.nvim_echo({ { " ", "Normal" } }, false, {})
end
end

Expand Down

0 comments on commit 2ff9db3

Please sign in to comment.