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

Nix injection incorrectly highlights elements as strings #49

Open
mydumpfire opened this issue Mar 2, 2024 · 3 comments
Open

Nix injection incorrectly highlights elements as strings #49

mydumpfire opened this issue Mar 2, 2024 · 3 comments

Comments

@mydumpfire
Copy link

mydumpfire commented Mar 2, 2024

This is how bash is normally highlighted (on helix, with the built-in tokyonight theme):

image

And this is how it looks like in an injected nix string block:

image

A lot of stuff that shouldn't be highlighted as a string, gets highlighted as one.

On the other hand, neovim doesn't seem to have this problem:

image

Anyone know what's causing this issue?

@asymmetric
Copy link

Are you sure you're using tree-sitter-nix in both editors? Generally, it would be good to post minimal configurations so that people can reproduce.

@mydumpfire
Copy link
Author

mydumpfire commented Mar 3, 2024

Yes, they're both using treesitter as the syntax highlighter. I can use :Inspect and :InspectTree on the neovim buffer and view the structure:

image

image

To reproduce:

For helix, you don't need a config. You should be able to reproduce it with the defaults: hx -c ''.

For neovim, you just need to have nvim-treesitter installed with the nix parser. You can put this into your ~/.config/nvim/init.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
    "--branch=stable",
    lazypath,
  }
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup {
  "folke/tokyonight.nvim",
  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
      local configs = require("nvim-treesitter.configs")

      configs.setup {
        ensure_installed = { "nix" },
        sync_install = false,
        highlight = { enable = true },
        indent = { enable = true },
      }
    end,
  },
}

vim.cmd.colorscheme("tokyonight")

For other installation methods: https://github.com/nvim-treesitter/nvim-treesitter/wiki/Installation

@the-mikedavis
Copy link
Contributor

This is because nvim-treesitter highlights (command argument: (word)): https://github.com/nvim-treesitter/nvim-treesitter/blob/8a9bef9327bc06c9c4158d4873d87bb1bf3ed112/queries/bash/highlights.scm#L172-L175

Helix doesn't highlight the (word) nodes so they keep the string highlight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants