Dynamically register a language

Viewed 13

I'm writing a vscode extension and I'd like to register languages dynamically, based on user configuration. The extension would then instantiate LSP clients to talk to servers derived from user configuration as well.

This would allow for people writing custom and toy languages to get an extension "for free" and experiment with editor features without necessarily having to implement and publish the vscode part of it.

I've dug a bit in the vscode sources, and found an interface that seem like it could help : "ILanguageService", but I'm unsure as to whether this is something that's accessible from the extension API.

Any idea how I could go at it ? Is it even possible ?

1 Answers

Alright, so my question stemmed from a misunderstanding of how LSP clients work. They don't necessarily need to be tied to a language, and can work on a glob-pattern basis, something like

            const filter: DocumentFilter = {
                scheme: 'file',
                pattern: `**/*.${myLanguage.extension}`
            };

            const clientOptions: LanguageClientOptions = {
                documentSelector: [filter]
            };

This seems to be sufficient for vscode to understand which LSP it should be calling

Related