How to activate ILanguageClient regardless of content type in Visual Studio Extension

27 Views Asked by At

I have a language server that works by the user specifying plugins in a configuration file while developing. These plugins control what file types they operate on. For example, there is a JSON plugin, JavaScript plugin, etc. The extension and language server have no knowledge of what file types they will support because of this.

The problem is I'm trying to create an extension for Visual Studio (NOT VISUAL STUDIO CODE) and it seems the way to activate an ILanguageClient is to first implement it, then define a ContentType that activates the extension:

public class BarContentDefinition
{
    [Export]
    [Name("bar")]
    [BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
    internal static ContentTypeDefinition BarContentTypeDefinition;

    [Export]
    [FileExtension(".bar")]
    [ContentType("bar")]
    internal static FileExtensionToContentTypeDefinition BarFileExtensionDefinition;
}

[ContentType("bar")]
[Export(typeof(ILanguageClient))]
public class BarLanguageClient : ILanguageClient
{
  // etc...
}

Read more: https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-an-lsp-extension?view=vs-2022#create-a-simple-language-client

This does not work for me because I need to decide what file types are supported within the language server itself based on the config. So, I'm wondering if there's some way I can always activate the extension and then decide from there whether to activate the language client (I can know whether to launch the language server based on the precense of the application's config file). Is there some lower level API that allows activating ILanguageClients instead of needing to define content type attributes for activation?

0

There are 0 best solutions below