forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
56 lines (46 loc) · 1.43 KB
/
utils.lua
File metadata and controls
56 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local logger = require("copilot.logger")
local api = require("copilot.api")
local config = require("copilot.config")
local c = require("copilot.client")
local M = {}
function M.add_workspace_folder(folder_path)
if type(folder_path) ~= "string" then
logger.error("workspace folder path must be a string")
return false
end
if vim.fn.isdirectory(folder_path) ~= 1 then
logger.error("invalid workspace folder: " .. folder_path)
return false
end
folder_path = vim.fn.fnamemodify(folder_path, ":p")
--- @type workspace_folder
local workspace_folder = {
uri = vim.uri_from_fname(folder_path),
name = folder_path,
}
local workspace_folders = config.workspace_folders
if not workspace_folders then
workspace_folders = {}
end
for _, existing_folder in ipairs(workspace_folders) do
if existing_folder == folder_path then
return
end
end
table.insert(workspace_folders, { folder_path })
config.workspace_folders = workspace_folders
local client = c.get()
if client and client.initialized then
api.notify(client, "workspace/didChangeWorkspaceFolders", {
event = {
added = { workspace_folder },
removed = {},
},
})
logger.notify("added workspace folder: " .. folder_path)
else
logger.notify("workspace folder will be added on next session: " .. folder_path)
end
return true
end
return M