-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat(cli-utils): add experimental support for .svelte
files
#241
Conversation
🦋 Changeset detectedLatest commit: a128090 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const virtualFileId = file.fileId + VIRTUAL_EXT; | ||
const virtualSourceFile = project.createSourceFile( | ||
virtualFileId, | ||
virtualSnapshot.getText(0, virtualSnapshot.getLength()), | ||
{ overwrite: true, scriptKind: ts.ScriptKind.TSX } | ||
); | ||
|
||
if (virtualSourceFile._markAsInProject) virtualSourceFile._markAsInProject(); | ||
|
||
projectToVirtual.set(file.fileId, virtualSourceFile.compilerNode); | ||
virtualToProject.set(virtualFileId, projectSourceFile); | ||
sourceMaps.set(file.fileId, sourceMap); | ||
sourceMaps.set(virtualFileId, sourceMap); | ||
} | ||
|
||
return ((fileId, position) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still unable to override the original filename with the output here, which would allow us to clean that up. Since TypeScript does support arbitrary file extensions, I'm not quite sure where that issue may be coming from, but for now, this workaround is still needed
const VueVirtualCode = | ||
vue.VueGeneratedCode || ((vue as any).VirtualCode as typeof vue.VueGeneratedCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export was renamed on the main
branch of @vuejs/language-tools
, so both names will have to be checked here to anticipate their next release: vuejs/language-tools@f46634c
.svelte
files
Related: #232
Related: #236
Summary
This abstracts our usage of
volar
’s utilities down toVirtualCode
wrappers and abstracts it to have parity with the Svelte file support.The Svelte2TSX compiler has been added to compile Svelte files to TSX as well.
Notably, this changes the approach slightly. To risk confusing external files with virtual files, we now create a
SourceFile
of the project file (svelte/vue file) outside of our TypeScript program and don't add it to the project.Redirections to the virtual file and such still function as before. But the biggest change is that all commands will now iterate over the virtual files (e.g.
.vue.ts
and.vue.svelte
) instead of the non-TS project files (.vue
and.svelte
), since those aren't loaded into TypeScript anymore. The output of the logger is hence mapped andgetFilePosition
now uses the position mapper as needed.Set of changes
VirtualCode
project -> virtual
orvirtual -> project
file, so it can be used for both, the GraphQLSP plugin info methods, and the logger outputs