Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper way to inject customTags through the service #188

Open
ejfasting opened this issue Apr 26, 2024 · 0 comments
Open

Proper way to inject customTags through the service #188

ejfasting opened this issue Apr 26, 2024 · 0 comments

Comments

@ejfasting
Copy link

ejfasting commented Apr 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant