olimorris / onedarkpro.nvim

🎨 Atom's iconic One Dark theme. Cacheable, fully customisable, Tree-sitter and LSP semantic token support. Comes with variants
MIT License
773 stars 40 forks source link

[Bug]: Rust `#![attributes]` are not highlighted #219

Closed mrjones2014 closed 10 months ago

mrjones2014 commented 10 months ago

Your minimal.lua config

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",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "olimorris/onedarkpro.nvim",
    opts = {
      -- Your OneDarkPro config goes here
    },
    config = true
  },

  { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },

  -- Delete if you do not require LSP
  {
    "VonHeikemen/lsp-zero.nvim",
    branch = "v2.x",
    dependencies = {
      -- LSP Support
      {"neovim/nvim-lspconfig"},             -- Required
      {                                      -- Optional
        "williamboman/mason.nvim",
        build = function()
          pcall(vim.cmd, "MasonUpdate")
        end,
      },
      {"williamboman/mason-lspconfig.nvim"}, -- Optional

      -- Autocompletion
      {"hrsh7th/nvim-cmp"},     -- Required
      {"hrsh7th/cmp-nvim-lsp"}, -- Required
      {"L3MON4D3/LuaSnip"},     -- Required
    },
    config = function()
      local lsp = require("lsp-zero").preset({})

      lsp.on_attach(function(client, bufnr)
        lsp.default_keymaps({buffer = bufnr})
      end)

      lsp.ensure_installed({ "lua_ls" })

      -- (Optional) Configure lua language server for neovim
      require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls())

      lsp.setup()
    end
  }

  -- add any other plugins here
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
  treesitter.setup({
    ensure_installed = "all",
    ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
    highlight = { enable = true },
  })
end

vim.cmd("colorscheme onedark")

Error messages

No response

Describe the bug

For example, this is not highlighted, which I typically put at the top of any lib.rs file:

#![deny(clippy::all, clippy::pedantic, rust_2018_idioms, clippy::unwrap_used)]

But kind without the ! are highlighted correctly:

#[derive(Debug)]

Screenshot:

CleanShot 2023-11-15 at 13 40 23

Looks like it needs an additional LSP semantic token highlight.

Reproduce the bug

  1. cargo new example-crate
  2. Edit main.rs to have the following contents
#![deny(clippy::all, clippy::pedantic, rust_2018_idioms, clippy::unwrap_used)]

#[derive(Debug)]
enum Error {
  MyError,
}

fn main() {}

Final checks

olimorris commented 10 months ago

I notice this isn't coloured in the original VS Code theme either:

2023-11-15 19_31_18 - Code@2x

...which seems a bit of a miss.

How does this look?

2023-11-15 19_37_32 - WezTerm@2x

I used these highlights:

["@lsp.type.builtinAttribute.rust"] = { link = "Function" },
["@lsp.type.attributeBracket.rust"] = { link = "@punctuation.bracket.rust" },
["@lsp.type.generic.rust"] = { fg = theme.palette.red, style = config.styles.variables },
mrjones2014 commented 10 months ago

That looks great! Should I copy those to my config or will you be adding those to the default Rust highlights?

olimorris commented 10 months ago

I've merged into main! Thanks for raising...looks so much better.