Skip to content

Commit

Permalink
fix: add 0.9 compatible lsp start
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed May 21, 2024
1 parent bc076ef commit 6fe4cc9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lua/sg/cody/rpc.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local rpc = vim.lsp.rpc

local auth = require "sg.auth"
local config = require "sg.config"
local log = require "sg.log"
local protocol = require "sg.cody.protocol"

local rpc_start = require("sg.utils").rpc_start

local M = {}

--- Whether the current cody connection is ready for requests
Expand Down Expand Up @@ -151,7 +151,7 @@ M.start = function(opts, callback)
M.messages = {}
M.server_info = {}

M.client = rpc.start(cody_args, {
M.client = rpc_start(cody_args, {
notification = function(method, data)
if notification_handlers[method] then
notification_handlers[method](data)
Expand Down
5 changes: 2 additions & 3 deletions lua/sg/request.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local rpc = vim.lsp.rpc

local log = require "sg.log"

local rpc_start = require("sg.utils").rpc_start
local bin_sg_nvim = require("sg.config").get_nvim_agent()

local M = {}
Expand Down Expand Up @@ -51,7 +50,7 @@ M.start = function(opts)
end

-- Verify that the environment is properly configured
M.client = rpc.start({ bin_sg_nvim }, {
M.client = rpc_start({ bin_sg_nvim }, {
notification = function(method, data)
log.info("got notification", method, data)
if notification_handlers[method] then
Expand Down
28 changes: 24 additions & 4 deletions lua/sg/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ utils.execute_keystrokes = function(keys)
end

-- COMPAT(0.10.0)
utils.joinpath = vim.fs.joinpath or function(...)
return (table.concat({ ... }, "/"):gsub("//+", "/"))
end
utils.joinpath = vim.fs.joinpath
or function(...)
return (table.concat({ ... }, "/"):gsub("//+", "/"))
end

-- COMPAT(0.10.0)
-- So far only handle stdout, no other items are handled.
Expand Down Expand Up @@ -152,7 +153,8 @@ utils._validate_node_output = function(output)
if version then
local min_node_version = assert(vim.version.parse "v18")
if not vim.version.gt(version, min_node_version) then
return false, string.format("node version must be >= %s. Got: %s", min_node_version, version)
return false,
string.format("node version must be >= %s. Got: %s", min_node_version, version)
end

return true, version
Expand Down Expand Up @@ -181,4 +183,22 @@ utils.replace_markdown_link = function(str)
end)
end

--- Start the LSP server, compatible with nvim 0.9 still
---@param cmd string[]: Command to start the LSP server.
---@param dispatchers? vim.lsp.rpc.Dispatchers
---@param extra_spawn_params? vim.lsp.rpc.ExtraSpawnParams
---@return vim.lsp.rpc.PublicClient
utils.rpc_start = function(cmd, dispatchers, extra_spawn_params)
local version = vim.version()
if version.major == 0 and version.minor >= 10 then
return vim.lsp.rpc.start(cmd, dispatchers, extra_spawn_params)
else
local executable = table.remove(cmd, 1)

-- Compatbility line
---@diagnostic disable-next-line: redundant-parameter, param-type-mismatch
return vim.lsp.rpc.start(executable, cmd, dispatchers, extra_spawn_params)
end
end

return utils

0 comments on commit 6fe4cc9

Please sign in to comment.