Repository: neovim/neovim
File: runtime/lua/vim/version.lua (Lua)

Code before:
    ---@diagnostic disable-next-line: cast-local-type
    version = M.parse(version)
  elseif getmetatable(version) ~= Version then
    -- Need metatable to compare versions.
    version = setmetatable(vim.deepcopy(version, true), Version)
  end
  if version then
    if self.from == self.to then
      return version == self.from
    end
    return version >= self.from and (self.to == nil or version < self.to)
  end
end

--- Parses a semver |version-range| "spec" and returns a range object:
---
--- ```
--- {
---   from: Version
---   to: Version
---   has(v: string|Version)
--- }
--- ```
---
--- `:has()` checks if a version is in the range (inclusive `from`, exclusive
--- `to`. If `from` and `to` are the same, then 'to' will be inclusive).
---
--- Example:
---
--- ```lua
--- local r = vim.version.range('1.0.0 - 2.0.0')
--- print(r:has('1.9.9'))       -- true
--- print(r:has('2.0.0'))       -- false
--- print(r:has(vim.version())) -- check against current Nvim version
--- ```
---
--- Or use cmp(), le(), lt(), ge(), gt(), and/or eq() to compare a version
--- against `.to` and `.from` directly:
---
--- ```lua
--- local r = vim.version.range('1.0.0 - 2.0.0') -- >=1.0, <2.0
--- print(vim.version.ge({1,0,3}, r.from) and vim.version.lt({1,0,3}, r.to))
--- ```
---
--- @see # https://github.com/npm/node-semver#ranges
--- @since 11
---
--- @param spec string Version range "spec"
--- @return vim.VersionRange?
function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim
  if spec == '*' or spec == '' then

Review comment (suggestion):
```suggestion
--- `:has()` checks if a version is in the range (inclusive `from`, exclusive `to`).
```

Code after:
    ---@diagnostic disable-next-line: cast-local-type
    version = M.parse(version)
  elseif getmetatable(version) ~= Version then
    -- Need metatable to compare versions.
    version = setmetatable(vim.deepcopy(version, true), Version)
  end
  if version then
    if self.from == self.to then
      return version == self.from
    end
    return version >= self.from and (self.to == nil or version < self.to)
  end
end

--- Parses a semver |version-range| "spec" and returns a range object:
---
--- ```
--- {
---   from: Version
---   to: Version
---   has(v: string|Version)
--- }
--- ```
---
--- `:has()` checks if a version is in the range (inclusive `from`, exclusive `to`).
---
--- Example:
---
--- ```lua
--- local r = vim.version.range('1.0.0 - 2.0.0')
--- print(r:has('1.9.9'))       -- true
--- print(r:has('2.0.0'))       -- false
--- print(r:has(vim.version())) -- check against current Nvim version
--- ```
---
--- Or use cmp(), le(), lt(), ge(), gt(), and/or eq() to compare a version
--- against `.to` and `.from` directly:
---
--- ```lua
--- local r = vim.version.range('1.0.0 - 2.0.0') -- >=1.0, <2.0
--- print(vim.version.ge({1,0,3}, r.from) and vim.version.lt({1,0,3}, r.to))
--- ```
---
--- @see # https://github.com/npm/node-semver#ranges
--- @since 11
---
--- @param spec string Version range "spec"
--- @return vim.VersionRange?
function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim
  if spec == '*' or spec == '' then
    return setmetatable({ from = M.parse('0.0.0') }, { __index = VersionRange })