Skip to content

Commit

Permalink
chore: wip backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitx committed Dec 27, 2023
1 parent 05b8a47 commit 0670ef7
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 16 deletions.
File renamed without changes.
51 changes: 48 additions & 3 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ M.create_handler = function(buf, win, line, first_undojoin, prefix, cursor)
local skip_first_undojoin = not first_undojoin

local hl_handler_group = "GpHandlerStandout"
vim.cmd("highlight default link " .. hl_handler_group .. " Search")
vim.cmd("highlight default link " .. hl_handler_group .. " search")

local ns_id = vim.api.nvim_create_namespace("GpHandler_" .. M._H.uuid())

Expand Down Expand Up @@ -2520,8 +2520,7 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
selection = table.concat(lines, "\n")

if selection == "" then
M.warning("Please select some text to rewrite")
return
M.warning("Empty selection")
end
end

Expand Down Expand Up @@ -3310,4 +3309,50 @@ M.cmd.LspNewCompletion = function(params)
require("gp.lsp").completion()
end

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

local buf = vim.api.nvim_get_current_buf()
local filetype = vim.api.nvim_buf_get_option(buf, "filetype")
print(filetype)
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)

local ns_id = vim.api.nvim_create_namespace("GpProbe_" .. M._H.uuid())

-- create extmark at the end of the buffer
local ex_id = vim.api.nvim_buf_set_extmark(buf, ns_id, #lines - 1, 0, {
strict = false,
right_gravity = false,
-- for debug
virt_text = { { "GpProbe" } },
virt_text_pos = "overlay",
})

local first_line = vim.api.nvim_buf_get_extmark_by_id(buf, ns_id, ex_id, {})[1]

M.spinner.start_spinner("Runnig LSP...")
local cleanup = function()
vim.schedule(function()
local fl = vim.api.nvim_buf_get_extmark_by_id(buf, ns_id, ex_id, {})[1]
-- delete everything after the fl
M._H.undojoin(buf)
vim.api.nvim_buf_set_lines(buf, fl + 1, -1, false, {})
vim.api.nvim_buf_clear_namespace(buf, ns_id, 0, -1)
M.spinner.stop_spinner()
end)
end
local queue = require("gp.queue").create(cleanup)

-- write probe template
M._H.undojoin(buf)
vim.api.nvim_buf_set_lines(buf, first_line + 1, first_line + 1, false, lsp.probe_template(filetype))

lsp.completion(first_line + 1, 0, buf, function(items)
local tbuf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(tbuf, 0, -1, false, vim.split(vim.inspect(items), "\n"))
vim.api.nvim_win_set_buf(0, tbuf)
queue.runNextTask()
end, lsp.complete_ignored_root_items(filetype))
end

return M
60 changes: 60 additions & 0 deletions lua/gp/lsp/ft/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
return {
template = "func gp_lsp_probe() {\n \n}",
suffixes = { ". " },
root_ignore = {
Class = {
bool = "",
byte = "",
complex128 = "",
complex64 = "",
float32 = "",
float64 = "",
int = "",
int16 = "",
int32 = "",
int64 = "",
int8 = "",
rune = "",
string = "",
uint = "",
uint16 = "",
uint32 = "",
uint64 = "",
uint8 = "",
uintptr = "",
},
Constant = {
["false"] = "",
["true"] = "",
},
Function = {
append = "func(slice []Type, elems ...Type) []Type",
cap = "func(v Type) int",
clear = "func(t T)",
close = "func(c chan<- Type)",
complex = "func(r float64, i float64) complex128",
copy = "func(dst []Type, src []Type) int",
delete = "func(m map[Type]Type1, key Type)",
gp_lsp_probe = "func()",
imag = "func(c complex128) float64",
len = "func(v Type) int",
make = "func(t Type, size ...int) Type",
max = "func(x T, y ...T) T",
min = "func(x T, y ...T) T",
new = "func(Type) *Type",
panic = "func(v any)",
print = "func(args ...Type)",
println = "func(args ...Type)",
real = "func(c complex128) float64",
recover = "func() any",
},
Interface = {
any = "",
comparable = "",
error = "",
},
Variable = {
["nil"] = "",
},
},
}
76 changes: 76 additions & 0 deletions lua/gp/lsp/ft/lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
return {
template = "function gp_lsp_probe() {\n \n}",
suffixes = { ". " },
root_ignore = {
Enum = {
_VERSION = "",
},
Field = {
_G = "",
arg = "",
coroutine = "",
debug = "",
io = "",
loadfile = "",
math = "",
os = "",
package = "",
string = "",
table = "",
utf8 = "",
vim = "",
},
Function = {
["assert(v, message, ...)"] = "",
["collectgarbage(opt, ...)"] = "",
["dofile(filename)"] = "",
["error(message, level)"] = "",
["getfenv(f)"] = "",
["getmetatable(object)"] = "",
["ipairs(t)"] = "",
["load(chunk, chunkname, mode, env)"] = "",
["loadfile(filename, mode, env)"] = "",
["loadstring(text, chunkname)"] = "",
["module(name, ...)"] = "",
["newproxy(proxy)"] = "",
["next(table, index)"] = "",
["pairs(t)"] = "",
["pcall(f, arg1, ...)"] = "",
["print(...)"] = "",
["rawequal(v1, v2)"] = "",
["rawget(table, index)"] = "",
["rawlen(v)"] = "",
["rawset(table, index, value)"] = "",
["require(modname)"] = "",
["select(index, ...)"] = "",
["setfenv(f, table)"] = "",
["setmetatable(table, metatable)"] = "",
["tonumber(e)"] = "",
["tonumber(e, base)"] = "",
["tostring(v)"] = "",
["type(v)"] = "",
["unpack(list, i, j)"] = "",
["warn(message, ...)"] = "",
["xpcall(f, msgh, arg1, ...)"] = "",
},
Keyword = {
["and"] = "",
["break"] = "",
continue = "",
["else"] = "",
["end"] = "",
["false"] = "",
["goto"] = "",
["local"] = "",
["nil"] = "",
["not"] = "",
["or"] = "",
["return"] = "",
["true"] = "",
["until"] = "",
},
Variable = {
_ENV = "",
},
},
}
Loading

0 comments on commit 0670ef7

Please sign in to comment.