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

Highlight deprecated symbols #1765

Closed
weskoerber opened this issue Feb 12, 2024 · 6 comments
Closed

Highlight deprecated symbols #1765

weskoerber opened this issue Feb 12, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@weskoerber
Copy link

weskoerber commented Feb 12, 2024

I recently saw #1764 which highlights deprecated symbols in the completion list and I think this is an awesome feature.

Is it possible to extend that feature and highlight the deprecated symbols via diagnostics? For example, like rust_analyzer's deprecation highlights (note how foo() is hightlighted - er, struck-through - on line 6):

image

@weskoerber weskoerber added the enhancement New feature or request label Feb 12, 2024
@Techatrix
Copy link
Member

Showing an error when using a symbol that is a @compileError would require reliable semantic analysis (#552) to avoid emitting incorrect diagnostics. Using the build on save feature of ZLS or vscode-zig can provide these diagnostics.

#1764 does emit tokens with a "deprecated" modifier but it depends on the editor/client on whether they do anything with this information like highlighting the token as strike-through. I've checked VS Code, Sublime Text 4 and Helix but none of them highlighted a symbol as strike-through.

I was able to get symbols highlighted as strike-through in VS Code with the following setting:

"editor.semanticTokenColorCustomizations": {
  "rules": {
    "*.deprecated": {
      "strikethrough": true
    }
  }
},

Not really sure which editor you were using but I am curious to see if your editor is special in that regard or rust_analyzer uses a different approach to get foo as strike-through in rust.

@llogick
Copy link
Contributor

llogick commented Feb 12, 2024

@weskoerber
Copy link
Author

weskoerber commented Feb 13, 2024

Not really sure which editor you were using but I am curious to see if your editor is special in that regard or rust_analyzer uses a different approach to get foo as strike-through in rust.

I'm using neovim (master branch). Neovim's documentation on its diagnostic framework suggests it supports the Deprecated diagnostic tag:

                                                *hl-DiagnosticDeprecated*
DiagnosticDeprecated
    Used for deprecated or obsolete code.

Using the build on save feature of ZLS or vscode-zig can provide these diagnostics.

I was able to get symbols highlighted as strike-through in VS Code with the following setting:

Interesting, I'll test with enable_build_on_save turned on and report back.

Probably making use of tags?: DiagnosticTag[];, https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic

That does appear to be the case (using the lsp-types crate). However, I'm not familiar with rust_analyzer from a developer's perspective. I'm just a user. That could be a red herring.

@weskoerber
Copy link
Author

Unfortunately, setting enable_build_on_save didn't get deprecation warning diagnostics comparable to rust-analyzer.

If you were able to get it working in VS Code, perhaps this is editor specific?

@weskoerber
Copy link
Author

Swinging back around on this... I was able to reproduce your results on Windows using VS Code. This is an editor specific issue. I'm gonna close this, but if I find a way to get it working in Neovim I'll update this issue.

image

@weskoerber
Copy link
Author

So I eventually figured this out, and it was a pretty dumb reason: I wasn't passing the client capabilities to the LSP server. After passing the capabilities to the setup call in my neovim lua, it worked:

require('lspconfig').zls.setup({
  capabilities = client_capabilities,
})

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

No branches or pull requests

3 participants