From 7848f3fab7588f4e899415f332a20a6445e491de Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 12:13:03 +0200 Subject: [PATCH 1/6] fix: set root_dir using find_git_ancestor from lspconfig.util --- lua/copilot/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index df948ccf..eb49e9ce 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -180,7 +180,7 @@ local function prepare_client_config(overrides) node, agent_path, }, - root_dir = vim.loop.cwd(), + root_dir = require("lspconfig.util").find_git_ancestor, name = "copilot", get_language_id = function(_, filetype) return util.language_for_file_type(filetype) From 587fbebf479a331ca3103733d876dfebad7bf4bf Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 12:24:18 +0200 Subject: [PATCH 2/6] fix: call root_dir instead, since it's now a function --- lua/copilot/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index eb49e9ce..9e009c2b 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -27,7 +27,7 @@ end local lsp_start = vim.lsp.start if not lsp_start then local function reuse_client(client, conf) - return client.config.root_dir == conf.root_dir and client.name == conf.name + return client.config.root_dir() == conf.root_dir() and client.name == conf.name end -- shim for neovim < 0.8.2 From 86ac1118422d7efedb37d60a4e0d21c009b6a041 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 12:36:54 +0200 Subject: [PATCH 3/6] Revert "fix: call root_dir instead, since it's now a function" This reverts commit 587fbebf479a331ca3103733d876dfebad7bf4bf. --- lua/copilot/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index 9e009c2b..eb49e9ce 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -27,7 +27,7 @@ end local lsp_start = vim.lsp.start if not lsp_start then local function reuse_client(client, conf) - return client.config.root_dir() == conf.root_dir() and client.name == conf.name + return client.config.root_dir == conf.root_dir and client.name == conf.name end -- shim for neovim < 0.8.2 From 26f9080b54013328fa603c21e3b49ccfd50b57a3 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 12:37:50 +0200 Subject: [PATCH 4/6] fix: only use client.name in reuse client logic --- lua/copilot/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index eb49e9ce..5cabb00e 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -27,7 +27,7 @@ end local lsp_start = vim.lsp.start if not lsp_start then local function reuse_client(client, conf) - return client.config.root_dir == conf.root_dir and client.name == conf.name + return client.name == conf.name end -- shim for neovim < 0.8.2 From 7a39d670cdd0704e85074d608c68274da1f66221 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 12:49:27 +0200 Subject: [PATCH 5/6] fix: add get_rootdir and modify root_dir instead --- lua/copilot/client.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index 5cabb00e..1f93ec07 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -27,7 +27,7 @@ end local lsp_start = vim.lsp.start if not lsp_start then local function reuse_client(client, conf) - return client.name == conf.name + return client.conf.root_dir == conf.root_dir and client.name == conf.name end -- shim for neovim < 0.8.2 @@ -98,6 +98,11 @@ function M.buf_attach(force) return end + local bufnr = vim.api.nvim_get_current_buf() + local bufname = vim.api.nvim_buf_get_name(bufnr) + + M.config.root_dir = M.config.get_root_dir(require("lspconfig.util").path.sanitize(bufname), bufnr) + local client_id = lsp_start(M.config) store_client_id(client_id) end @@ -180,7 +185,8 @@ local function prepare_client_config(overrides) node, agent_path, }, - root_dir = require("lspconfig.util").find_git_ancestor, + root_dir = vim.loop.cwd(), + get_root_dir = require("lspconfig.util").find_git_ancestor, name = "copilot", get_language_id = function(_, filetype) return util.language_for_file_type(filetype) From 6d8168a0dd71625ff25eb09c4cd953a277862151 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Wed, 20 Sep 2023 13:38:15 +0200 Subject: [PATCH 6/6] fix: conf -> config --- lua/copilot/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index 1f93ec07..6ff0a2cf 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -27,7 +27,7 @@ end local lsp_start = vim.lsp.start if not lsp_start then local function reuse_client(client, conf) - return client.conf.root_dir == conf.root_dir and client.name == conf.name + return client.config.root_dir == conf.root_dir and client.name == conf.name end -- shim for neovim < 0.8.2