microsoft / vscode-html-languageservice

Language services for HTML
MIT License
220 stars 109 forks source link

Proper way to inject customTags through the service #188

Open ejfasting opened 4 months ago

ejfasting commented 4 months ago

Hello,

I'm working on an LSP server and I'm testing if i can leverage the parseHtmlDocument from this service. To do that i need to add some customData/customTags that are recognized by the service, but I'm having some issues figuring out how to inject it properly.

I've tried initializing the languageService witha IHTMLDataProvider object:

// Define custom tags
const customTags = [
    { name: '<%', kind: 'startTag' },
    { name: '%>', kind: 'endTag' }
];

// Custom data provider function
const customDataProvider: html.IHTMLDataProvider = {
    getId: () => 'customDataProvider',
    isApplicable: () => true,
    provideTags: () => {
        return customTags.map(tag => ({
            name: tag.name,
            kind: tag.kind,
            selfClosing: false,
            attributes: [] // empty array for attributes
        }));
    },
    provideAttributes: () => [], // empty array for attributes
    provideValues: () => [] // empty array for values
};

// Initialize language service options with custom data provider
const languageServiceOptions: html.LanguageServiceOptions = {
    customDataProviders: [customDataProvider]
};

// Initialize language service
const htmlLs = html.getLanguageService(languageServiceOptions);

What's the proper way of doing it?

//Eivind