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

Special characters not highlighted in strings #1928

Open
Av1d1ty opened this issue Jun 20, 2024 · 11 comments
Open

Special characters not highlighted in strings #1928

Av1d1ty opened this issue Jun 20, 2024 · 11 comments
Labels
bug Something isn't working editor:vim

Comments

@Av1d1ty
Copy link

Av1d1ty commented Jun 20, 2024

Zig Version

0.12.1

Zig Language Server Version

0.13.0, 0.12.0

Client / Code Editor / Extensions

nvim 0.10, lspconfig

Steps to Reproduce and Observed Behavior

Open file with a special character like \n or \t in a string literal. See that all characters have the same color.
image

Expected Behavior

Special characters highlighted differently
image

Image above shows what it looks like when ZLS is turned off.

Relevant log output

No response

@Av1d1ty Av1d1ty added the bug Something isn't working label Jun 20, 2024
@Techatrix Techatrix added enhancement New feature or request and removed bug Something isn't working labels Jun 20, 2024
@Techatrix
Copy link
Member

Above Terminal is NeoVim 0.10.0, Bottom Terminal is Neovim 0.9.5

With ZLS

with-zls

Without ZLS

without-zls

In case this is hard to see, the escape characters are highlighted except with ZLS on NeoVim 0.10.0. Everything else was as expected.
I tried out a few of the default colorschemes in NeoVim 0.10.0 but that didn't help.
I did not observe any changes when enabling the zig.vim extension.

So it seems like something is going on with NeoVim 0.10.0... 🤔

The `init.lua` being used
local vim = vim
local Plug = vim.fn['plug#']

vim.call('plug#begin')
Plug('neovim/nvim-lspconfig') -- https://github.com/neovim/nvim-lspconfig
-- Plug('ziglang/zig.vim') -- https://github.com/ziglang/zig.vim
vim.call('plug#end')

-- I disabled ZLS by removing everything below here

local lspconfig = require('lspconfig')
lspconfig.zls.setup {
  cmd = { '/home/techatrix/repos/zls/zig-out/bin/zls' },
  settings = {
    zls = {
      zig_exe_path = '/nix/store/s3nq31mhm8gxkq691p5w6q61ficw1hvr-zig-0.13.0/bin/zig',
    }
  }
}

@Techatrix Techatrix added bug Something isn't working editor:vim and removed enhancement New feature or request labels Jun 20, 2024
@Av1d1ty
Copy link
Author

Av1d1ty commented Jun 21, 2024

Also special characters are displayed correctly in Lua files with lua-ls active.

@WillLillis
Copy link
Sponsor Contributor

WillLillis commented Jun 21, 2024

It seems like neovim's semantic token highlighting are overriding tree-sitter's highlight's for the escaped characters. Adding the following to my config disabled semantic highlighting for zig string tokens, and appears to fix the issue:

vim.api.nvim_set_hl(0, '@lsp.type.string.zig', {})

I'm not sure what a more permanent/ "out of the box" fix would be, as it seems that semantic token highlights have a higher priority than tree-sitter's by default.

@Vexu
Copy link
Contributor

Vexu commented Jun 21, 2024

The same thing happens in vscode when semantic_tokens is set to full instead of partial, maybe other editors with grammar based highlighting should also use partial?

@Techatrix
Copy link
Member

Perhaps it is more reasonable to assume that the editor already provides syntax based highlighting for Zig code? Then we could make partial the default which also fixes this issue.

@Av1d1ty
Copy link
Author

Av1d1ty commented Jun 22, 2024

Can confirm that setting semantic tokens to "partial" does fix the issue, but at the same time highlighting changes in places where I prefer it would not

Semantic tokens set to "full"
image

Semantic tokens set to "partial"
image

As you can see, function parameters are no longer highlighted distinctly in function body.

@Av1d1ty
Copy link
Author

Av1d1ty commented Jun 22, 2024

Also, on a side note, Mason tells me that default value for semantic tokens in "partial", while in fact it is set to "full"

image

@Av1d1ty
Copy link
Author

Av1d1ty commented Jun 22, 2024

Side note 2: Mason shows config names in camelCase, while in fact they need to be set in snake_case in my config files. Not sure if it is an actual issue. Maybe I lack understanding about how Mason and configs work for language servers.

@Techatrix
Copy link
Member

Mason's package.yaml for ZLS uses vscode-zig's package.json to provide information about config options. This should not be done because vscode-zig options don't exactly match what ZLS uses. I will look into resolving that.

@Techatrix
Copy link
Member

Can confirm that setting semantic tokens to "partial" does fix the issue, but at the same time highlighting changes in places where I prefer it would not

This should be fixed by 2e5a2a5.

I used folke/tokyonight.nvim and set semantic_tokens to partial. Here is how it changed:

Before

Screenshot from 2024-06-22 12-31-42

After

Screenshot from 2024-06-22 12-31-09

@Av1d1ty
Copy link
Author

Av1d1ty commented Jun 22, 2024

Awesome, thanks!

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

No branches or pull requests

4 participants