Files
neovim/runtime/lua/vim/_meta/regex.lua
Justin M. Keyes 4b424a06c5 backport fix(lsp): send didClose, didOpen when languageId changes (#39519)
fix(lsp): send didClose, didOpen when languageId changes

Problem:
If a buffer's filetype changes after the LSP client has already
attached (e.g. from json to jsonc via a modeline), but the client
supports both filetypes, it stays attached. It does not notify the
server of the new languageId, causing the server to incorrectly process
the file using the old languageId.

Solution:
Save the languageId used during textDocument/didOpen, and send
textDocument/didClose + textDocument/didOpen when buffer's languageId
changed.

Lsp spec:
0003fb53f1/_specifications/lsp/3.18/textDocument/didOpen.md (L5)
> If the language id of a document changes, the client
> needs to send a textDocument/didClose to the server followed by a
> textDocument/didOpen with the new language id if the server handles
> the new language id as well.

AI-assisted: Gemini 3.1 Pro

Co-authored-by: phanium <91544758+phanen@users.noreply.github.com>
2026-04-30 13:09:55 +00:00

40 lines
1.7 KiB
Lua

--- @meta
-- This file is NOT generated, edit it directly.
error('Cannot require a meta file')
-- luacheck: no unused args
--- @brief Vim regexes can be used directly from Lua. Currently they only allow
--- matching within a single line.
--- Parses the Vim regex `re` and returns a regex object. Regexes are "magic" and case-sensitive by
--- default, regardless of 'magic' and 'ignorecase'. They can be controlled with flags, see |/magic|
--- and |/ignorecase|.
--- @param re string
--- @return vim.regex
function vim.regex(re) end
--- @nodoc
--- @class vim.regex
local regex = {} -- luacheck: no unused
--- Matches string `str` against this regex. To match the string precisely, surround the regex with
--- "^" and "$". Returns the byte indices for the start and end of the match, or `nil` if there is
--- no match. Because any integer is "truthy", `regex:match_str()` can be directly used as
--- a condition in an if-statement.
--- @param str string
--- @return integer? # match start (byte index), or `nil` if no match
--- @return integer? # match end (byte index), or `nil` if no match
function regex:match_str(str) end
--- Matches line at `line_idx` (zero-based) in buffer `buf`. Match is restricted to byte index
--- range `start` and `end_` if given, otherwise see |regex:match_str()|. Returned byte indices are
--- relative to `start` if given.
--- @param buf integer
--- @param line_idx integer
--- @param start? integer
--- @param end_? integer
--- @return integer? # match start (byte index) relative to `start`, or `nil` if no match
--- @return integer? # match end (byte index) relative to `start`, or `nil` if no match
function regex:match_line(buf, line_idx, start, end_) end