feat: automatically restart lsp server (opt-in)
This commit is contained in:
parent
440a7cc432
commit
7c198a1b36
7 changed files with 105 additions and 69 deletions
|
|
@ -1,51 +0,0 @@
|
|||
local r = require "gopher._utils.runner"
|
||||
local c = require("gopher.config").commands
|
||||
local u = require "gopher._utils"
|
||||
local gocmd = {}
|
||||
|
||||
---@param args string[]
|
||||
---@return string[]
|
||||
local function if_get(args)
|
||||
for i, arg in ipairs(args) do
|
||||
local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
|
||||
table.remove(args, i)
|
||||
table.insert(args, i, m)
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
---@param args unknown[]
|
||||
---@return string[]
|
||||
local function if_generate(args)
|
||||
if #args == 1 and args[1] == "%" then
|
||||
args[1] = vim.fn.expand "%"
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
---@param subcmd string
|
||||
---@param args string[]
|
||||
---@return string
|
||||
function gocmd.run(subcmd, args)
|
||||
if #args == 0 and subcmd ~= "generate" then
|
||||
error "please provide any arguments"
|
||||
end
|
||||
|
||||
if subcmd == "get" then
|
||||
args = if_get(args)
|
||||
end
|
||||
|
||||
if subcmd == "generate" then
|
||||
args = if_generate(args)
|
||||
end
|
||||
|
||||
local rs = r.sync { c.go, subcmd, unpack(args) }
|
||||
if rs.code ~= 0 then
|
||||
error("go " .. subcmd .. " failed: " .. rs.stderr)
|
||||
end
|
||||
|
||||
u.notify(c.go .. " " .. subcmd .. " ran successful")
|
||||
return rs.stdout
|
||||
end
|
||||
|
||||
return gocmd
|
||||
11
lua/gopher/_utils/lsp.lua
Normal file
11
lua/gopher/_utils/lsp.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
local lsp = {}
|
||||
|
||||
local gopls = "gopls"
|
||||
|
||||
-- Restarts gopls server (see: `:h lsp-restart`)
|
||||
function lsp.restart()
|
||||
vim.lsp.enable(gopls, false)
|
||||
vim.lsp.enable(gopls, true)
|
||||
end
|
||||
|
||||
return lsp
|
||||
Loading…
Add table
Add a link
Reference in a new issue