@@ -3,12 +3,6 @@ local logger = require("copilot.logger")
3
3
4
4
local M = {}
5
5
6
- local id = 0
7
- function M .get_next_id ()
8
- id = id + 1
9
- return id
10
- end
11
-
12
6
--- @return { editorInfo : copilot_editor_info , editorPluginInfo : copilot_editor_plugin_info }
13
7
function M .get_editor_info ()
14
8
local info = {
@@ -37,61 +31,11 @@ function M.get_copilot_lua_version()
37
31
return copilot_lua_version
38
32
end
39
33
40
- local internal_filetypes = {
41
- yaml = false ,
42
- markdown = false ,
43
- help = false ,
44
- gitcommit = false ,
45
- gitrebase = false ,
46
- hgcommit = false ,
47
- svn = false ,
48
- cvs = false ,
49
- [" ." ] = false ,
50
- }
51
-
52
- --- @param filetype_enabled boolean | fun (): boolean
53
- local function resolve_filetype_enabled (filetype_enabled )
54
- if type (filetype_enabled ) == " function" then
55
- return filetype_enabled ()
56
- end
57
- return filetype_enabled
58
- end
59
-
60
- --- @param ft string
61
- --- @param filetypes table<string , boolean>
62
- --- @return boolean ft_disabled
63
- --- @return string ? ft_disabled_reason
64
- local function is_ft_disabled (ft , filetypes )
65
- if filetypes [ft ] ~= nil then
66
- return not resolve_filetype_enabled (filetypes [ft ]),
67
- string.format (" 'filetype' %s rejected by config filetypes[%s]" , ft , ft )
68
- end
69
-
70
- local short_ft = string.gsub (ft , " %..*" , " " )
71
-
72
- if filetypes [short_ft ] ~= nil then
73
- return not resolve_filetype_enabled (filetypes [short_ft ]),
74
- string.format (" 'filetype' %s rejected by config filetypes[%s]" , ft , short_ft )
75
- end
76
-
77
- if filetypes [" *" ] ~= nil then
78
- return not resolve_filetype_enabled (filetypes [" *" ]),
79
- string.format (" 'filetype' %s rejected by config filetypes[%s]" , ft , " *" )
80
- end
81
-
82
- if internal_filetypes [short_ft ] ~= nil then
83
- return not internal_filetypes [short_ft ],
84
- string.format (" 'filetype' %s rejected by internal_filetypes[%s]" , ft , short_ft )
85
- end
86
-
87
- return false
88
- end
89
-
90
34
--- @return boolean should_attach
91
35
--- @return string ? no_attach_reason
92
36
function M .should_attach ()
93
37
local ft = config .filetypes
94
- local ft_disabled , ft_disabled_reason = is_ft_disabled (vim .bo .filetype , ft )
38
+ local ft_disabled , ft_disabled_reason = require ( " copilot.client.filetypes " ). is_ft_disabled (vim .bo .filetype , ft )
95
39
96
40
if ft_disabled then
97
41
return not ft_disabled , ft_disabled_reason
@@ -100,33 +44,6 @@ function M.should_attach()
100
44
return true
101
45
end
102
46
103
- local language_normalization_map = {
104
- bash = " shellscript" ,
105
- bst = " bibtex" ,
106
- cs = " csharp" ,
107
- cuda = " cuda-cpp" ,
108
- dosbatch = " bat" ,
109
- dosini = " ini" ,
110
- gitcommit = " git-commit" ,
111
- gitrebase = " git-rebase" ,
112
- make = " makefile" ,
113
- objc = " objective-c" ,
114
- objcpp = " objective-cpp" ,
115
- ps1 = " powershell" ,
116
- raku = " perl6" ,
117
- sh = " shellscript" ,
118
- text = " plaintext" ,
119
- }
120
-
121
- function M .language_for_file_type (filetype )
122
- -- trim filetypes after dot, e.g. `yaml.gotexttmpl` -> `yaml`
123
- local ft = string.gsub (filetype , " %..*" , " " )
124
- if not ft or ft == " " then
125
- ft = " text"
126
- end
127
- return language_normalization_map [ft ] or ft
128
- end
129
-
130
47
local function relative_path (absolute )
131
48
local relative = vim .fn .fnamemodify (absolute , " :." )
132
49
if string.sub (relative , 0 , 1 ) == " /" then
@@ -167,37 +84,6 @@ function M.get_doc_params(overrides)
167
84
return params
168
85
end
169
86
170
- --- @return copilot_workspace_configurations
171
- function M .get_workspace_configurations ()
172
- local filetypes = vim .deepcopy (config .filetypes ) --[[ @as table<string, boolean>]]
173
-
174
- if filetypes [" *" ] == nil then
175
- filetypes = vim .tbl_deep_extend (" keep" , filetypes , internal_filetypes )
176
- end
177
-
178
- local copilot_model = config and config .copilot_model ~= " " and config .copilot_model or " "
179
-
180
- --- @type string[]
181
- local disabled_filetypes = vim .tbl_filter (function (ft )
182
- return filetypes [ft ] == false
183
- end , vim .tbl_keys (filetypes ))
184
- table.sort (disabled_filetypes )
185
-
186
- return {
187
- settings = {
188
- github = {
189
- copilot = {
190
- selectedCompletionModel = copilot_model ,
191
- },
192
- },
193
- enableAutoCompletions = not not (config .panel .enabled or config .suggestion .enabled ),
194
- disabledLanguages = vim .tbl_map (function (ft )
195
- return { languageId = ft }
196
- end , disabled_filetypes ),
197
- },
198
- }
199
- end
200
-
201
87
M .get_plugin_path = function ()
202
88
local copilot_path = vim .api .nvim_get_runtime_file (" lua/copilot/init.lua" , false )[1 ]
203
89
if vim .fn .filereadable (copilot_path ) ~= 0 then
@@ -217,32 +103,4 @@ function M.strutf16len(str)
217
103
end
218
104
end
219
105
220
- --- @return copilot_window_show_document_result
221
- --- @param result copilot_window_show_document
222
- function M .show_document (_ , result )
223
- logger .trace (" window/showDocument:" , result )
224
- local success , _ = pcall (vim .ui .open , result .uri )
225
- if not success then
226
- if vim .ui .open ~= nil then
227
- vim .api .nvim_echo ({
228
- { " window/showDocument" },
229
- { vim .inspect ({ _ , result }) },
230
- { " \n " , " NONE" },
231
- }, true , {})
232
- error (" Unsupported OS: vim.ui.open exists but failed to execute." )
233
- else
234
- vim .api .nvim_echo ({
235
- { " window/showDocument" },
236
- { vim .inspect ({ _ , result }) },
237
- { " \n " , " NONE" },
238
- }, true , {})
239
- error (" Unsupported Version: vim.ui.open requires Neovim >= 0.10" )
240
- end
241
- end
242
-
243
- return {
244
- success = success ,
245
- }
246
- end
247
-
248
106
return M
0 commit comments