language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Completion for custom element tag name

Open break-stuff opened this issue 1 year ago • 11 comments

Description

There doesn't seem to way to extend the language tool for custom elements.

Proposed solution

Vue and JSX templates have an interface that can be extended to include custom elements/web components. This would be a nice way for library authors to provide better type integration and descriptions within svelte templates.

Alternatives

No response

Additional Information, eg. Screenshots

No response

break-stuff avatar Jan 04 '24 23:01 break-stuff

There are ways to enhance the typing.

https://svelte.dev/docs/typescript#enhancing-built-in-dom-types

jasonlyu123 avatar Jan 05 '24 00:01 jasonlyu123

Oh, this is fantastic! Thank you!

break-stuff avatar Jan 05 '24 01:01 break-stuff

@jasonlyu123 do you have a working example of this? It doesn't seem to work in my sample app.

break-stuff avatar Jan 07 '24 01:01 break-stuff

Can you provide a link to that example app?

dummdidumm avatar Jan 07 '24 07:01 dummdidumm

Yeah, here's a simple repo.

https://github.com/break-stuff/svelte-custom-elements-demo

break-stuff avatar Jan 07 '24 18:01 break-stuff

I have added a additional-svelte-typings.d.ts to the /src directory and updated the tsconfig.json to "include": ["src/**/*"] (basically just followed the steps in the docs).

break-stuff avatar Jan 07 '24 18:01 break-stuff

It does work in your repo. Are you expecting to have completion for it as well?

jasonlyu123 avatar Jan 08 '24 01:01 jasonlyu123

Yes, I don't see any difference in having it vs not having it in my repo.

break-stuff avatar Jan 08 '24 01:01 break-stuff

The difference is it will be type-check for the element.

jasonlyu123 avatar Jan 08 '24 01:01 jasonlyu123

There is another way to add custom tag name completion. It's only a local config, so it's not something library authors can leverage, but it's still a good workaround until we can figure out a way to provide the completion.

https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md

jasonlyu123 avatar Jan 08 '24 02:01 jasonlyu123

Yeah, I created a package to generate that, but it would be nice if devs would only have to set one thing for types and autocomplete.

https://www.npmjs.com/package/custom-element-vs-code-integration

break-stuff avatar Jan 08 '24 02:01 break-stuff