feat: Allow embedded languages to utilise Svelte Intellisense in VSCode #2611
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello! This PR modifies the behaviour of the Svelte VSCode extension so that it activates for URIs that don't use the
file://
scheme.During standard extension usage, this makes no difference, as all Svelte files on disk will use the
file://
scheme in their URI. However, enabling this support allows other extensions to use Svelte as an embedded language and still take full advantage of all of the Svelte extension's Intellisense.This is handled in VSCode by a mechanism called Request Forwarding. In summary, VSCode will preprocess the custom language and create a virtual document that contains just the "Svelte" portion of the document. It can then invoke the Svelte extension on that virtual document.
The problem is that these virtual documents must use a unique URI scheme. As Svelte currently only activates on
file://
scheme URIs, these requests will be dropped.Example Use-Cases
Potential Problems
Various parts of the extension (document snapshots, Typescript plugin) track the
path
of the file, not the URI. The conversion from path to URI inlanguage-server/utils.ts
will assume thefile://
URI scheme when mapping between paths and URIs.I am not familiar enough with the Svelte Language Server inner workings to fully know what the impact of supporting all URI schemes is. I've tested these modifications locally and the extension seems to behave identically to the original extension, but I would appreciate some advice from the maintainers on the impact of this change!
I'm also not sure if there are any URI schemes that should be explicitly disallowed by the extension. For example,
http
/https
URIs ending in.svelte
should probably not be recorded in document snapshots, as these might appear in webviews?Next Steps
I'm hoping that this small change does not break any existing behaviour, as merging it will make any downstream embedded svelte extension's experience much better!