mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
fix(lsp): clear current_syntax before formatting fancy markdown region
This commit is contained in:
@@ -1160,34 +1160,29 @@ function M.fancy_floating_markdown(contents, opts)
|
|||||||
api.nvim_win_set_option(winnr, 'conceallevel', 2)
|
api.nvim_win_set_option(winnr, 'conceallevel', 2)
|
||||||
api.nvim_win_set_option(winnr, 'concealcursor', 'n')
|
api.nvim_win_set_option(winnr, 'concealcursor', 'n')
|
||||||
|
|
||||||
|
vim.cmd("ownsyntax lsp_markdown")
|
||||||
|
|
||||||
local idx = 1
|
local idx = 1
|
||||||
--@private
|
--@private
|
||||||
local function apply_syntax_to_region(ft, start, finish)
|
local function apply_syntax_to_region(ft, start, finish)
|
||||||
if ft == "" then
|
if ft == "" then
|
||||||
vim.cmd(string.format("syntax region markdownCodeBlock start=+\\%%%dl+ end=+\\%%%dl+ keepend extend", start, finish + 1))
|
vim.cmd(string.format("syntax region markdownCode start=+\\%%%dl+ end=+\\%%%dl+ keepend extend", start, finish + 1))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = ft..idx
|
local name = ft..idx
|
||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
local lang = "@"..ft:upper()
|
local lang = "@"..ft:upper()
|
||||||
|
-- HACK: reset current_syntax, since some syntax files like markdown won't load if it is already set
|
||||||
|
pcall(vim.api.nvim_buf_del_var, bufnr, "current_syntax")
|
||||||
-- TODO(ashkan): better validation before this.
|
-- TODO(ashkan): better validation before this.
|
||||||
if not pcall(vim.cmd, string.format("syntax include %s syntax/%s.vim", lang, ft)) then
|
if not pcall(vim.cmd, string.format("syntax include %s syntax/%s.vim", lang, ft)) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.cmd(string.format("syntax region %s start=+\\%%%dl+ end=+\\%%%dl+ contains=%s keepend", name, start, finish + 1, lang))
|
vim.cmd(string.format("syntax region %s start=+\\%%%dl+ end=+\\%%%dl+ contains=%s keepend", name, start, finish + 1, lang))
|
||||||
end
|
end
|
||||||
-- Previous highlight region.
|
|
||||||
local ph = 1
|
|
||||||
for _, h in ipairs(highlights) do
|
|
||||||
if ph <= h.start - 1 then
|
|
||||||
apply_syntax_to_region('lsp_markdown', ph, h.start - 1)
|
|
||||||
end
|
|
||||||
apply_syntax_to_region(h.ft, h.start, h.finish)
|
|
||||||
ph = h.finish + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if ph <= #stripped then
|
for _, h in ipairs(highlights) do
|
||||||
apply_syntax_to_region('lsp_markdown', ph, #stripped)
|
apply_syntax_to_region(h.ft, h.start, h.finish)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(cwin)
|
vim.api.nvim_set_current_win(cwin)
|
||||||
|
Reference in New Issue
Block a user