DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
936 stars 17 forks source link

feat request: Disable Semantic Highlighting? #176

Closed akthe-at closed 5 months ago

akthe-at commented 5 months ago

Is there or could we get a way to disable semantic highlighting if we desire? I have other themes that support semantic tokens and there is no issue but there are others without...I was hoping perhaps I could have the ability to turn off semantic highlighting when I am using those themes?

Basedpyright Enabled: image

Basedpyright disabled, only tree sitter highlights and the theme without semantic token support. image

akthe-at commented 5 months ago

I figured out how to do it on the client side, I will close this and leave the autocommand here for any future people searching for this:

vim.api.nvim_create_autocmd("LspAttach", {
  callback = function(args)
    local client = vim.lsp.get_client_by_id(args.data.client_id)
    client.server_capabilities.semanticTokensProvider = nil
  end,
})
DetachHead commented 5 months ago

just to be clear, there was no issue with the semantic highlighting, you just wanted to disable it because it has no effect with the theme you use?

akthe-at commented 5 months ago

There is an issue but I don't think it is on your end. I'm doing more research to try and pin it down

karimlevallois commented 5 months ago

I'm seeing an issue on catppuccin, it's changing functions to blue, rather than the normal peach colour. Taken me hours to tie down what was causing it.

akthe-at commented 5 months ago

Do you have semantic_tokens = true ?

{ "catppuccin/nvim", lazy = true, name = "catppuccin", opts = { integrations = { aerial = true, alpha = true, cmp = true, dashboard = true, flash = true, gitsigns = true, headlines = true, illuminate = true, indent_blankline = { enabled = true }, leap = true, lsp_trouble = true, mason = true, markdown = true, mini = true, native_lsp = { enabled = true, underlines = { errors = { "undercurl" }, hints = { "undercurl" }, warnings = { "undercurl" }, information = { "undercurl" }, }, }, navic = { enabled = true, custom_bg = "lualine" }, neotest = true, neotree = true, noice = true, notify = true, semantic_tokens = true, telescope = true, treesitter = true, treesitter_context = true, which_key = true, }, }, }

karimlevallois commented 5 months ago

I do, but also tried disabling that option in my troubleshooting and it was still changing the colour, it's fine now after doing.

     setup = {
       basedpyright = function()
          LazyVim.lsp.on_attach(function(client, _)
            if client.name == "basedpyright" then
              -- Disable semantic tokens as breaking colorscheme function colours
              client.server_capabilities.semanticTokensProvider = nil
            end
          end)
        end,

Before with semantic tokens enabled in basedpyright. Notice the blue input() and print() functions: -

Screenshot 2024-03-23 at 21 28 06

How it usually looks with pyright and also pylance in VSCode: -

Screenshot 2024-03-23 at 21 27 11
akthe-at commented 5 months ago

instead of adding all that to setup, i found this an easier one liner to add to my options, vim.highlight.priorities.semantic_tokens = 95

karimlevallois commented 5 months ago

OK cool, what does the 95 relate to?

akthe-at commented 5 months ago

The priority level, I believe treesitter is 100, so it allows treesitter to take precedence.

akthe-at commented 5 months ago

makes me wonder if a lot of the vim/neovim themes need to be updated to work with basedpyright's semantic token highlights. Consider this, before basedpyright's release I believe the average way that python/neovim users were interacting with semantic_tokens was via semshi which did not work for a lot of people and was seldom used I believe.

Folke/Tokyonight was just adding a fix for this today.

karimlevallois commented 5 months ago

Funny enough, I was playing around with the semshi extra in LazyVim today and that’s when I noticed something was up. I thought the plug-in broke something and then I spent ages trying to find out what had changed. I even thought catppuccin had changed something, so was scouring through code to see if that was the case. It’s only when I opened the buffer and saw colours change when basedpyright popped in my Lualine that I figured out they must be related.

KotlinIsland commented 5 months ago

Please give it an upvote so we can prioritise the tickets 😊