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
83 lines (71 loc) · 2.29 KB
/
utils.lua
File metadata and controls
83 lines (71 loc) · 2.29 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
local config = require("copilot.config")
local logger = require("copilot.logger")
local client_ft = require("copilot.client.filetypes")
local M = {}
---@param config_root_dir RootDirFuncOrString
function M.get_root_dir(config_root_dir)
local root_dir --[[@as string]]
if type(config_root_dir) == "function" then
root_dir = config_root_dir()
else
root_dir = config_root_dir
end
if not root_dir or root_dir == "" then
root_dir = "."
end
root_dir = vim.fn.fnamemodify(root_dir, ":p:h")
return root_dir
end
---@return copilot_workspace_configurations
function M.get_workspace_configurations()
local filetypes = vim.deepcopy(config.filetypes) --[[@as table<string, boolean>]]
if filetypes["*"] == nil then
filetypes = vim.tbl_deep_extend("keep", filetypes, client_ft.internal_filetypes)
end
local copilot_model = config and config.copilot_model ~= "" and config.copilot_model or ""
---@type string[]
local disabled_filetypes = vim.tbl_filter(function(ft)
return filetypes[ft] == false
end, vim.tbl_keys(filetypes))
table.sort(disabled_filetypes)
return {
settings = {
github = {
copilot = {
selectedCompletionModel = copilot_model,
},
},
enableAutoCompletions = not not (config.panel.enabled or config.suggestion.enabled),
disabledLanguages = vim.tbl_map(function(ft)
return { languageId = ft }
end, disabled_filetypes),
},
}
end
---@return copilot_window_show_document_result
---@param result copilot_window_show_document
function M.show_document(_, result)
logger.trace("window/showDocument:", result)
local success, _ = pcall(vim.ui.open, result.uri)
if not success then
if vim.ui.open ~= nil then
vim.api.nvim_echo({
{ "window/showDocument" },
{ vim.inspect({ _, result }) },
{ "\n", "NONE" },
}, true, {})
error("Unsupported OS: vim.ui.open exists but failed to execute.")
else
vim.api.nvim_echo({
{ "window/showDocument" },
{ vim.inspect({ _, result }) },
{ "\n", "NONE" },
}, true, {})
error("Unsupported Version: vim.ui.open requires Neovim >= 0.10")
end
end
return {
success = success,
}
end
return M