mirror of
https://github.com/neovim/neovim.git
synced 2026-04-30 19:24:09 +00:00
Merge pull request #38894 backports
This commit is contained in:
@@ -65,6 +65,7 @@ LSP
|
||||
LUA
|
||||
|
||||
• Renamed `vim.diff` to `vim.text.diff`.
|
||||
• Added `__eq` metamethod to |vim.VersionRange|.
|
||||
|
||||
OPTIONS
|
||||
|
||||
@@ -301,6 +302,9 @@ LUA
|
||||
• EXPERIMENTAL: |vim.pos|, |vim.range| provide Position/Range abstraction.
|
||||
• |vim.filetype.inspect()| returns a copy of the internal tables used for
|
||||
filetype detection.
|
||||
• Added `__eq` metamethod to |vim.VersionRange|. 2 distinct but representing
|
||||
the same range instances now compare equal.
|
||||
|
||||
|
||||
OPTIONS
|
||||
|
||||
|
||||
@@ -103,6 +103,41 @@ function M._nextnonblank(bufnr, start_lnum)
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
--- Gets a best-effort set of all "known" filetypes, discovered by:
|
||||
--- - `getcompletion()`
|
||||
--- - `vim.filetype` internal registry
|
||||
--- @return table<string,true>
|
||||
function M._get_known_filetypes()
|
||||
local known = {} --- @type table<string,true>
|
||||
for _, ft in ipairs(vim.fn.getcompletion('', 'filetype')) do
|
||||
known[ft] = true
|
||||
end
|
||||
local registry = vim.filetype.inspect()
|
||||
|
||||
local function add_filetype(value)
|
||||
local filetype = type(value) == 'table' and value[1] or value
|
||||
if type(filetype) == 'string' then
|
||||
known[filetype] = true
|
||||
end
|
||||
end
|
||||
|
||||
for _, value in pairs(registry.extension) do
|
||||
add_filetype(value)
|
||||
end
|
||||
|
||||
for _, value in pairs(registry.filename) do
|
||||
add_filetype(value)
|
||||
end
|
||||
|
||||
for _, mappings in pairs(registry.pattern) do
|
||||
for _, value in pairs(mappings) do
|
||||
add_filetype(value)
|
||||
end
|
||||
end
|
||||
|
||||
return known
|
||||
end
|
||||
|
||||
do
|
||||
--- @type table<string,vim.regex>
|
||||
local regex_cache = {}
|
||||
|
||||
@@ -212,38 +212,10 @@ local function check_position_encodings()
|
||||
end
|
||||
end
|
||||
|
||||
local function get_known_filetypes()
|
||||
local known = vim.fn.getcompletion('', 'filetype')
|
||||
local registry = vim.filetype.inspect()
|
||||
|
||||
local function add_filetype(value)
|
||||
local filetype = type(value) == 'table' and value[1] or value
|
||||
if type(filetype) == 'string' and not vim.list_contains(known, filetype) then
|
||||
known[#known + 1] = filetype
|
||||
end
|
||||
end
|
||||
|
||||
for _, value in pairs(registry.extension) do
|
||||
add_filetype(value)
|
||||
end
|
||||
|
||||
for _, value in pairs(registry.filename) do
|
||||
add_filetype(value)
|
||||
end
|
||||
|
||||
for _, mappings in pairs(registry.pattern) do
|
||||
for _, value in pairs(mappings) do
|
||||
add_filetype(value)
|
||||
end
|
||||
end
|
||||
|
||||
return known
|
||||
end
|
||||
|
||||
local function check_enabled_configs()
|
||||
vim.health.start('vim.lsp: Enabled Configurations')
|
||||
|
||||
local known_filetypes = get_known_filetypes()
|
||||
local known_filetypes = vim.filetype._get_known_filetypes()
|
||||
|
||||
for name in vim.spairs(vim.lsp._enabled_configs) do
|
||||
local config = vim.lsp.config[name]
|
||||
@@ -276,7 +248,7 @@ local function check_enabled_configs()
|
||||
for _, filetype in
|
||||
ipairs(v --[[@as string[] ]])
|
||||
do
|
||||
if not vim.list_contains(known_filetypes, filetype) then
|
||||
if not known_filetypes[filetype] then
|
||||
report_warn(
|
||||
("Unknown filetype '%s' (Hint: filename extension != filetype)."):format(filetype)
|
||||
)
|
||||
|
||||
@@ -273,6 +273,9 @@ end
|
||||
|
||||
local range_mt = {
|
||||
__index = VersionRange,
|
||||
__eq = function(self, other)
|
||||
return self.to == other.to and self.from == other.from
|
||||
end,
|
||||
__tostring = function(self)
|
||||
if not self.to then
|
||||
return '>=' .. tostring(self.from)
|
||||
|
||||
@@ -118,6 +118,18 @@ describe('version', function()
|
||||
end)
|
||||
end
|
||||
|
||||
it('__eq', function()
|
||||
local range1 = vim.version.range('1.2.3 - 2.3.4')
|
||||
local range2 = vim.version.range('1.2.3 - 2.3.4')
|
||||
local range3 = vim.version.range('<=1.2.3')
|
||||
local range4 = vim.version.range('1.2.3')
|
||||
assert(range1 == range1)
|
||||
assert(range1 == range2)
|
||||
assert(range1 ~= range3)
|
||||
assert(range1 ~= range4)
|
||||
assert(range3 ~= range4)
|
||||
end)
|
||||
|
||||
it('handles prerelease', function()
|
||||
assert(not vim.version.range('1.2.3'):has('1.2.3-alpha'))
|
||||
assert(vim.version.range('1.2.3-alpha'):has('1.2.3-alpha'))
|
||||
|
||||
Reference in New Issue
Block a user