Recognizing LSP's custom tokens in the LSP client

Hello,

I’ve created a new token type on my LSP backend:

 public static final List<String> TOKEN_TYPES = List.of(
        "keyword",      // MESSAGE, DEFINE
        "string",       // STRING_LITERAL
        "operator",     // AMP, DOT
        "delimiter",    // LCURLY, RCURLY, DQUOTE
        "variable",     // TEXT
        "include",      // my new token
        "comment"       // For future use
);

In VSCode, for example, this new token is recognized and can be customized (colored) via the settings.json. In IntelliJ, however, I can’t seem to find this token in the settings. Adding it in the Dark.icls file also doesn’t work. This is my code for the client:

import com.intellij.platform.lsp.api.*;

public class MyCustomLspServerSupportProvider
implements LspServerSupportProvider {

   public String SERVER_JAR = "...";
   @Override
   public void fileOpened(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull LspServerSupportProvider.LspServerStarter lspServerStarter)
   {
      var command = new GeneralCommandLine(Arrays.asList(
              "java",
              "-jar",
              SERVER_JAR
      ));
      LspServerDescriptor descriptor = new LspServerDescriptor(project, "LSP") {
         @Override
         public boolean isSupportedFile(@NotNull VirtualFile virtualFile)
         {
            return virtualFile.getFileType() instanceof MyCustomFileType;
         }
         @Override
         public GeneralCommandLine createCommandLine() {
            return command;
         }
      };
      lspServerStarter.ensureServerStarted(descriptor);
   }
}

Any thoughts?

Best,

Florin

In your plugin project, you should be able to see the LSP API source code and documentation. Take a look at the following:

  • com.intellij.platform.lsp.api.LspServerDescriptor#getLspCustomization
  • com.intellij.platform.lsp.api.customization.LspCustomization#getSemanticTokensCustomizer
  • com.intellij.platform.lsp.api.customization.LspSemanticTokensSupport#getTokenTypes