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
Add support for custom file extensions #2035
Add support for custom file extensions #2035
Conversation
# Conflicts: # extensions/vscode-vue-language-features/package.json # extensions/vscode-vue-language-features/src/common.ts
Thanks for your exploration! I will try to take over your work. |
Due to you don't have do anything with {
"vueCompilerOptions": {
"extensions": [".vue", ".myvue", ".vcc", ".comp", ".comp2"]
}
} What do you think? |
Interesting. I was completely unaware that we could put custom data is tsconfig without it throwing errors. I suppose I am too used to webpack and rollup being far more strict about their config files. Yes. I think that is a much cleaner way to do it. Would this also mean the language service does not need to be restarted for the changes to take affect? |
Yes we don't have limitation to
Yes, language server watching tsconfig change to auto reload project. But after more dug up I think we still need |
I did a little testing with the branch after your updates against our main repo this evening. Everything seems to work. At least all the features I normally use seem to work:
There are probably lots of other use-cases that I haven't test (and probably many more features I don't even know exist), but so far everything seems to work. |
We should also add file watch support for additional extensions: https://github.com/johnsoncodehk/volar/blob/ac996cd92592a774a768719f9e810b5694d633cb/extensions/vscode-vue-language-features/src/nodeClientMain.ts#L70 But I will resolve it myself after merged this PR, because it's related to #2037. (But if you want to implement in this PR you can go) |
I guess |
Yes. I will hopefully work on the readme and the other items tomorrow. |
All changes should be in.
|
We should standardize the format of |
I can't found a similar setting, but I prefer extensions no dot for consistent with |
Yes, I will update that. Along that same thought, the new tsconfig.json vueCompilerOptions setting is "extensions" and currently you must specify the custom extension AND the |
|
We don't need to make |
I have updated the README to remove mention of |
Everything looks good, thank you! Since you successfully changed language client and vue language core, can you share how complex the code structure is and what is the main difficulty you encountered to you? If you have any ideas for improvement please let me know. |
* Add support for custom file extensions to be treated as Vue files. * refactor: add `VueLanguagePlugin.extensions` instead of pluginOptions * Changed vueserver.additionalExtensions setting to be a string array. * Add setup instructions on custom file extensions to vscode-vue-language-features README. * Added additional extensions to file system wacher. * chore: double quotes -> single quotes * Updated additionalExtensions to be extension without period. Updated README to match. * chore: remove empty extraPlugins param * feat: add `extensions` option to vue-tsconfig.schema.json * feat: show reload VSCode when changed additional extensions Co-authored-by: johnsoncodehk <johnsoncodehk@gmail.com>
@johnsoncodehk Thanks for your help with this. Your feedback made this change much better than if I had stuck with my original idea. To answer your question, I think the main difficulty was figuring out the process of debugging in VS Code. Specifically, understanding how the language server worked and that I had to run the main extension first and then attach to the language server. It took me a while to figure how to do this. Once I did it a couple times and figured out the magic it was pretty easy. The second most difficult thing was figuring out how all the packages talk to each other and in what order (so to speak) they talk to each other. Because of the IPC stuff just looking at the call stack didn't always give me the answer of "how I got to this breakpoint". I think this is mostly covered by the "High Level System Overview" image in the main README.md file. But that image didn't really make sense until after I started tinkering and understanding the whole multi-process aspect a bit. Both of those might very well be documented. I admit I didn't look too deeply beyond just the README file. I assumed just setting some breakpoints and looking at the call stack would answer most of my questions. Bad assumption. The code structure was pretty easy for me to understand. Maybe some more comments on functions describing what they do and why they do it, but I know that is often difficult when time is limited. And thank you so much for this extension. You have built an amazing thing that is making a huge impact on the Vue community! |
This would implement custom file extensions for Vue files as mentioned in #1931.
Changes
additionalExtensions
was added to thevueserver
namespace. This is a comma, semicolon or space separated list of filename extensions. An optional period before the extension is allowed. Example setting value:.myvue, vcc; comp .comp2
would allowmyvue
,vcc
,comp
andcomp2
as extensions in addition to the standardvue
extension.VueServerInitializationOptions
was added calledadditionalExtensions
. This is an array of filename extensions and is used to pass the custom extensions to the language server..vue
. This allows extensions other than 3 characters to be used.pluginOptions
to theVueLanguagePlugin
type. This is basically an object whose top-level key is the plugin name and whose value is an unknown - specifically it should match whatever custom options the plugin expects.I do not like the way I had to implement number 4 above. It doesn't feel clean but I haven't been able to come up with better options. I considered making changes inside file-vue.ts to allow for calling a second function that sets the extensions and then returns the original exported function. But that would, I believe, be a breaking change.
@johnsoncodehk If you have ideas on number 4 and how better to achieve this - or if you are fine with the way it was implemented - please let me know.
Notes
As mentioned in the configuration option description, if you change the new configuration value the Volar service must be restarted for it to take affect.
This PR only touches the VSCode related bits. It does not touch any of the other plugins or entry points.
Work In Progress
I am marking this WIP for two reasons:
plugins/file-vue.ts
.