@@ -5,7 +5,7 @@ local nvim_eleven = vim.fn.has 'nvim-0.11' == 1
5
5
6
6
local iswin = vim .loop .os_uname ().version :match ' Windows'
7
7
8
- local M = {}
8
+ local M = { path = {} }
9
9
10
10
M .default_config = {
11
11
log_level = lsp .protocol .MessageType .Warning ,
@@ -95,57 +95,6 @@ function M.create_module_commands(module_name, commands)
95
95
end
96
96
end
97
97
98
- -- Some path utilities
99
- M .path = (function ()
100
- --- @param path string
101
- --- @return boolean
102
- local function is_fs_root (path )
103
- if iswin then
104
- return path :match ' ^%a:$'
105
- else
106
- return path == ' /'
107
- end
108
- end
109
-
110
- -- Traverse the path calling cb along the way.
111
- local function traverse_parents (path , cb )
112
- path = vim .loop .fs_realpath (path )
113
- local dir = path
114
- -- Just in case our algo is buggy, don't infinite loop.
115
- for _ = 1 , 100 do
116
- dir = vim .fs .dirname (dir )
117
- if not dir then
118
- return
119
- end
120
- -- If we can't ascend further, then stop looking.
121
- if cb (dir , path ) then
122
- return dir , path
123
- end
124
- if is_fs_root (dir ) then
125
- break
126
- end
127
- end
128
- end
129
-
130
- local function is_descendant (root , path )
131
- if not path then
132
- return false
133
- end
134
-
135
- local function cb (dir , _ )
136
- return dir == root
137
- end
138
-
139
- local dir , _ = traverse_parents (path , cb )
140
-
141
- return dir == root
142
- end
143
-
144
- return {
145
- is_descendant = is_descendant ,
146
- }
147
- end )()
148
-
149
98
function M .search_ancestors (startpath , func )
150
99
if nvim_eleven then
151
100
validate (' func' , func , ' function' )
@@ -294,7 +243,52 @@ function M.strip_archive_subpath(path)
294
243
return path
295
244
end
296
245
297
- --- Functions that can be removed once minimum required neovim version is high enough
246
+ --- Public functions that can be deprecated once minimum required neovim version is high enough
247
+
248
+ local function is_fs_root (path )
249
+ if iswin then
250
+ return path :match ' ^%a:$'
251
+ else
252
+ return path == ' /'
253
+ end
254
+ end
255
+
256
+ -- Traverse the path calling cb along the way.
257
+ local function traverse_parents (path , cb )
258
+ path = vim .loop .fs_realpath (path )
259
+ local dir = path
260
+ -- Just in case our algo is buggy, don't infinite loop.
261
+ for _ = 1 , 100 do
262
+ dir = vim .fs .dirname (dir )
263
+ if not dir then
264
+ return
265
+ end
266
+ -- If we can't ascend further, then stop looking.
267
+ if cb (dir , path ) then
268
+ return dir , path
269
+ end
270
+ if is_fs_root (dir ) then
271
+ break
272
+ end
273
+ end
274
+ end
275
+
276
+ --- This can be replaced with `vim.fs.relpath` once minimum neovim version is at least 0.11.
277
+ function M .path .is_descendant (root , path )
278
+ if not path then
279
+ return false
280
+ end
281
+
282
+ local function cb (dir , _ )
283
+ return dir == root
284
+ end
285
+
286
+ local dir , _ = traverse_parents (path , cb )
287
+
288
+ return dir == root
289
+ end
290
+
291
+ --- Helper functions that can be removed once minimum required neovim version is high enough
298
292
299
293
function M .tbl_flatten (t )
300
294
--- @diagnostic disable-next-line : deprecated
0 commit comments