Disable competing language servers / code highlighters

Viewed 57

I want to add a language server to handle completion / highlighting / etc. for a file. As a basis for testing stuff I am using an example from Microsoft (https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample) and changed it to be active for any File. This language server highlights any word in all capital letters.

When opening a C++ File, I get the highlighting / completion of my language server and the default one for C++ (See image).

Image: competing highlighters: 1: my extension, 2: other extension

I would like to detect if some other extension / build in highlighter is active for a file and deactivate it for this workspace or the current file if it is impossible for the current workspace)

  1. Is there a way to do this in a generic way where I do not have to know which extensions are highlighting code?
  2. If no, is there a way to do this, if I know a set of extensions I want to deactivate?
1 Answers

I finally had enough time to try around a bit more and found that providing your own language for the same extension is enough.

In package.json I added an element in contributes.languages with extensions containing .cpp (since I am using cpp files for testing).

I also copied over some implementation code from an example.

This suppressed the default highlighter and code completion for cpp files. Since i am only implementing a semantic token provider, I can see the default highlighting before my provider takes over. (I think this could be solved by adding a syntax highlighter, but this is already sufficient fo my preliminary testing)

I am not sure, how stable all of this would be as a plugin (I only tested in Extension Development Host mode)

Here an image of the results: Image

Related