tree-sitter / tree-sitter-scala

Scala grammar for tree-sitter
MIT License
158 stars 55 forks source link

Enumeration color problem #391

Closed tsouchon-ledger closed 7 months ago

tsouchon-ledger commented 7 months ago

Commit of tree-sitter-scala you tested this on

installed directly from ts so last version I guess

A code sample showing the error

enum Foo: case Bar extends Oof ...

Show the error node

No error

What do you expect the tree to look like

All this information is colored in purple on my vim editor

I think it takes Bar and Oof as keyword which is not the case

Do you think it cames from my config ?

Where are you experiencing this error?

NvChad - MacOs

ckipp01 commented 7 months ago

Hey @tsouchon-ledger, could you provide a bit more information about what you mean? Do you mean literally every single token is purple? Trying this I see:

Screenshot 2024-03-19 at 14 44 49

I'm assuming this differs from what you're seeing? You should also be able to use :Insepct and :InspectTree in nvim to get a better idea of what might be going on.

tsouchon-ledger commented 7 months ago

Sorry for that I had to show you more stuff than that

As you can see everything seems ok apart the enum part

CleanShot 2024-03-19 at 23 03 37@2x

Inspect

CleanShot 2024-03-19 at 23 05 18@2x

InspectTree

CleanShot 2024-03-19 at 23 06 20@2x

My config

General info

I use catpuccin theme (seems the same for every other theme) And I'm on NvChad

Tree-sitter config

{
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "vim",
        "lua",
        "vimdoc",
        "html",
        "css",
        "javascript",
        "scala"
      },
    },
  },
}

metals config

local map = vim.keymap.set

return {
  "scalameta/nvim-metals",
  dependencies = {
    "nvim-lua/plenary.nvim",
    {
      "j-hui/fidget.nvim",
      opts = {},
    },
    {
      "mfussenegger/nvim-dap",
      config = function(self, opts)
        -- Debug settings if you're using nvim-dap
        local dap = require "dap"

        dap.configurations.scala = {
          {
            type = "scala",
            request = "launch",
            name = "RunOrTest",
            metals = {
              runType = "runOrTestFile",
              --args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example
            },
          },
          {
            type = "scala",
            request = "launch",
            name = "Test Target",
            metals = {
              runType = "testTarget",
            },
          },
        }
      end,
    },
  },
  ft = { "scala", "sbt", "java" },
  opts = function()
    local metals_config = require("metals").bare_config()

    -- Example of settings
    metals_config.settings = {
      showImplicitArguments = true,
      ammoniteJvmProperties = {
        "-Xmx5G",
        "-Xms500M",
      },
      javaHome = "/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home",
      excludedPackages = { "akka.actor.typed.javadsl", "com.github.swagger.akka.javadsl" },
    }

    -- *READ THIS*
    -- I *highly* recommend setting statusBarProvider to either "off" or "on"
    --
    -- "off" will enable LSP progress notifications by Metals and you'll need
    -- to ensure you have a plugin like fidget.nvim installed to handle them.
    --
    -- "on" will enable the custom Metals status extension and you *have* to have
    -- a have settings to capture this in your statusline or else you'll not see
    -- any messages from metals. There is more info in the help docs about this
    metals_config.init_options.statusBarProvider = "off"

    -- Example if you are using cmp how to make sure the correct capabilities for snippets are set
    metals_config.capabilities = require("cmp_nvim_lsp").default_capabilities()

    metals_config.on_attach = function(client, bufnr)
      require("metals").setup_dap()

      -- LSP mappings
      map("n", "gd", vim.lsp.buf.definition, { desc = "Goto Definition" })
      map("n", "K", vim.lsp.buf.hover, { desc = "Show Hover" })
      map("n", "gi", vim.lsp.buf.implementation, { desc = "Goto Implementation" })
      map("n", "gr", vim.lsp.buf.references, { desc = "Goto References" })
      map("n", "gs", vim.lsp.buf.document_symbol, { desc = "Document Symbol" })
      map("n", "gws", vim.lsp.buf.workspace_symbol, { desc = "Workspace Symbol" })
      map("n", "<leader>cl", vim.lsp.codelens.run, { desc = "CodeLens" })
      map("n", "<leader>sh", vim.lsp.buf.signature_help, { desc = "Signature Help" })
      map("n", "<leader>rn", vim.lsp.buf.rename, { desc = "Rename" })
      map("n", "<leader>lf", vim.lsp.buf.format, { desc = "Format" })
      map("n", "<leader>ca", vim.lsp.buf.code_action, { desc = "Code Action" })

      map("n", "<leader>ws", function()
        require("metals").hover_worksheet()
      end, { desc = "Hover Worksheet" })

      -- all workspace diagnostics
      map("n", "<leader>aa", vim.diagnostic.setqflist, { desc = "All Diagnostics" })

      -- all workspace errors
      map("n", "<leader>ae", function()
        vim.diagnostic.setqflist { severity = "E" }
      end, { desc = "All Errors" })

      -- all workspace warnings
      map("n", "<leader>aw", function()
        vim.diagnostic.setqflist { severity = "W" }
      end, { desc = "All Warnings" })

      -- buffer diagnostics only
      map("n", "<leader>d", vim.diagnostic.setloclist, { desc = "Buffer Diagnostics" })

      map("n", "[c", function()
        vim.diagnostic.goto_prev { wrap = false }
      end, { desc = "Previous Diagnostic" })

      map("n", "]c", function()
        vim.diagnostic.goto_next { wrap = false }
      end, { desc = "Next Diagnostic" })

      -- Example mappings for usage with nvim-dap. If you don't use that, you can
      -- skip these
      map("n", "<leader>dc", function()
        require("dap").continue()
      end, { desc = "Continue" })

      map("n", "<leader>dr", function()
        require("dap").repl.toggle()
      end, { desc = "REPL toggle" })

      map("n", "<leader>dK", function()
        require("dap.ui.widgets").hover()
      end, { desc = "Hover" })

      map("n", "<leader>dt", function()
        require("dap").toggle_breakpoint()
      end, { desc = "Toggle Breakpoint" })

      map("n", "<leader>dso", function()
        require("dap").step_over()
      end, { desc = "Step Over" })

      map("n", "<leader>dsi", function()
        require("dap").step_into()
      end, { desc = "Step Into" })

      map("n", "<leader>dl", function()
        require("dap").run_last()
      end, { desc = "Run Last" })
    end

    return metals_config
  end,
  config = function(self, metals_config)
    local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
    vim.api.nvim_create_autocmd("FileType", {
      pattern = self.ft,
      callback = function()
        require("metals").initialize_or_attach(metals_config)
      end,
      group = nvim_metals_group,
    })
  end,
}

@ckipp01 Thanks for your help and your reactivity 🙏

eed3si9n commented 7 months ago

Would :TSEnable highlight make a difference?

tsouchon-ledger commented 7 months ago

Hello @eed3si9n, unfortunately nothing change.

But I'm a bit confuse when I start my vim before scala metals index the project I guess I have the right highlight. I think metals override tree-sitter

https://github.com/tree-sitter/tree-sitter-scala/assets/150120807/ffbd5098-5444-4d9f-bdef-3bdeb395ef65

ckipp01 commented 7 months ago

Hello @eed3si9n, unfortunately nothing change.

But I'm a bit confuse when I start my vim before scala metals index the project I guess I have the right highlight. I think metals override tree-sitter

CleanShot.2024-03-20.at.08.44.30.mp4

Ahhhh yea, this is semantic tokens coming from Metals, which indeed will override your treesitter highlights. You can disable this with setting metals_config.settings.enableSemanticHighlighting = false. Feel free to also report this on the Metals side if an issue doesn't already exist.

tsouchon-ledger commented 7 months ago

Thanks @ckipp01 @eed3si9n for your help 🙏