Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: treesitter markdown highlight #378

Closed
3 tasks done
seblj opened this issue Mar 3, 2023 · 5 comments · Fixed by #379 or #639
Closed
3 tasks done

bug: treesitter markdown highlight #378

seblj opened this issue Mar 3, 2023 · 5 comments · Fixed by #379 or #639
Labels
bug Something isn't working

Comments

@seblj
Copy link

seblj commented Mar 3, 2023

Did you check docs and existing issues?

  • I have read all the noice.nvim docs
  • I have searched the existing issues of noice.nvim
  • I have searched the exsiting issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.0-dev-1023+g649742821

Operating system/version

MacOS Ventura 13.1

Describe the bug

Bug:

After the new PR by lewis with vim.treesitter.language.add() (Not sure if this was the case before that), this line here may break highlighting in the buffer:

if Treesitter.has_lang(self.extmark.lang) then

Screen.Recording.2023-03-03.at.17.45.40.mov

There are two reasons for this I believe. The first one is that it uses the filetype to check for a parser when the argument should really be the parsername. For example in this case, when I backspace and get a signature help it will call that function with typescriptreact, and that is not the parser name. I think it ideally should use vim.treesitter.language.get_lang which would give the correct parsername tsx.

The other reason is probably that I am not sure vim.treesitter.language.require_language is the correct way to check if a parser is available. I think it ideally should use something like has_parser either from upstream or nvim-treesitter (would then need to add it as a required dependency which is not the best even though there are probably a minority who are not using it).

Follow up question while I am here

While I am at it, I also noticed that the language server from rust for example returns a code block without specifying the language only when sending signature results. On hover it does it correctly. I am not sure if this applies to others as well. This will make the hover look like this:
Screenshot 2023-03-03 at 18 00 17

While signature looks like this:
Screenshot 2023-03-03 at 18 00 32

This is because of the fallback to text here:

local lang = line:match("```(%S+)") or "text"

Would it make sense to fallback to the filetype here instead maybe?

Steps To Reproduce

Sorry for not being able to have an easier replication of the bug.

  1. Clone this: https://github.com/seblj/noice-bug
  2. Run npm install
  3. Go into App.tsx and do as I did in the video

Expected Behavior

It would not remove treesitter highlighting from the buffer when doing :e

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{ "folke/tokyonight.nvim" },
	{
		"folke/noice.nvim",
		config = function()
			require("noice").setup({
				lsp = {
					-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
					override = {
						["vim.lsp.util.convert_input_to_markdown_lines"] = true,
						["vim.lsp.util.stylize_markdown"] = true,
						["cmp.entry.get_documentation"] = true,
					},
				},
				-- you can enable a preset for easier configuration
				presets = {
					bottom_search = true, -- use a classic bottom cmdline for search
					command_palette = true, -- position the cmdline and popupmenu together
					long_message_to_split = true, -- long messages will be sent to a split
					inc_rename = false, -- enables an input dialog for inc-rename.nvim
					lsp_doc_border = false, -- add a border to hover docs and signature help
				},
			})
		end,
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@seblj seblj added the bug Something isn't working label Mar 3, 2023
@max397574
Copy link
Contributor

also noticed the signature help thing before

@folke
Copy link
Owner

folke commented Mar 3, 2023

image

This is how it looks like for me with the latest nightly and updated nvim-treesitter.

What am I missing?

@folke
Copy link
Owner

folke commented Mar 3, 2023

image

Got it. It was using syntax hl. Fixing it

@seblj
Copy link
Author

seblj commented Mar 3, 2023

image

Got it. It was using syntax hl. Fixing it

Thanks! What do you think about my suggestion to fallback to the filetype if no language is provided for the codeblock?

@folke
Copy link
Owner

folke commented Mar 3, 2023

Yep, makes sense!

Coming up :)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants