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

feat(language-server): generate template virtual code #69

Merged
merged 22 commits into from Mar 27, 2024

Conversation

johnsoncodehk
Copy link
Contributor

@johnsoncodehk johnsoncodehk commented Mar 13, 2024

This is a new draft implementation of Vue Vine language services by Volar 2.

  • Support variable reference and click jumping into definition.

  • Migrate to TS plugin to resolve component types to support props intellisense and be compatible with SFC components.

Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for vue-vine ready!

Name Link
🔨 Latest commit 506a4ab
🔍 Latest deploy log https://app.netlify.com/sites/vue-vine/deploys/6603975af0338c0008e36d51
😎 Deploy Preview https://deploy-preview-69--vue-vine.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 14, 2024

@johnsoncodehk

Awesome work !! Thanks for joining us 🎉🥳🎉🥳🎉🥳🎉🥳

and make this epic PR, here's my feedback after trying this PR's effect.

image

There are 3 issues in demo that need to be addressed.

  1. The first question is: _unref requires external import, I see you left a comment of Todo in the code, do you need the compiler of Vue Vine or other parts to do any additional support?

    The generated _unref comes from nowhere, why and how does it be generated?

    Also, the mapping from _unref(loading) to original loading is broken and dislocated

  2. The second question is: The @click="...some bare expression" seems not detected by template generation process, and there's not any segement about it in the final virtual code as well.

    Is this a compiler-dom bug or something we need to modify?

  3. The third question may be related to Issue 1, those variables need to be wrapped with _unref to get actual type from Ref<ThatType> to ThatType.

@johnsoncodehk
Copy link
Contributor Author

  1. This was due to the mode: 'module' option being passed in, I disabled it in johnsoncodehk@84133d1 which seemed to fix the mapping issue.
  2. This is also fixed by remove mode: 'module' option.
  3. It's implement by johnsoncodehk@421ec36.

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 16, 2024

  1. This was due to the mode: 'module' option being passed in, I disabled it in johnsoncodehk@84133d1 which seemed to fix the mapping issue.
  2. This is also fixed by remove mode: 'module' option.
  3. It's implement by johnsoncodehk@421ec36.

@johnsoncodehk Thanks for such detailed explanation 🙏!!

After trying the new commits, I‘ve got some new questions:

Some functions are still not referenced

  1. It's interesting that variables id and isDark which are been referenced didn't show any warning of ts(6133) declared but not used, but why do those functions toggleDark and randomString get warnings?
image

Those imported variables get "unused" warnings too.

image





TS diagnostics are reported twice

  1. It seems the functions TS language service provided always run twice, like the examples below:
image

the intellisense options are duplicated.

image

The diagnostics are reported twice.




More extensive support

  1. The last question is what am I supposed to do (maybe add more API from compiler) to support component props typing when user're writing components in template.

I've talked about this with @so1ve in #53 , I think I can provide a feature-specific API for this

All I wanna achieve is to fix #52 #53 , and I think the basic features of Vue Vine language service are done.

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 16, 2024

@johnsoncodehk Also mentioned in #53,

as long as we need type definitions fromuser source code, we can easily read them on VineCompFnCtx,

every component context stores a Record of prop name and it's typing source code babel node,

so that we can use it's location and copy it into final virtual code for Volar

@johnsoncodehk
Copy link
Contributor Author

From https://github.com/volarjs/insiders/issues/3

I gave it a try in e126df4

But it seems that nothing has changed after I write contributes.typescriptServerPlugin this into @vue-vine/vscode-ext package.json

There is a fews problems.

  1. The ts plugin should be export with export = instead of export default
  2. tsup config incorrect
  3. The way Volar patches languageServiceHost for .vine.ts is incorrect

For 3. I will update a version for Volar first.

By the way, I found in vue/language-tools that many intellisense feature in Vue SFC template is done by creating Volar Service Plugin, I'm wondering if we can adopt it into Vue Vine ?

Yes it is possible, let's see after completing the TS plugin.

johnsoncodehk added a commit to volarjs/volar.js that referenced this pull request Mar 26, 2024
…le extensions

fixes cannot generate virtual code in ts plugin for vue-vine
refs: vue-vine/vue-vine#69
@ShenQingchuan
Copy link
Member

@johnsoncodehk I got many Errors in every .vine.ts after the latest commit, is that because those globalTypes and TS service are not completely loaded?

@johnsoncodehk
Copy link
Contributor Author

@johnsoncodehk I got many Errors in every .vine.ts after the latest commit, is that because those globalTypes and TS service are not completely loaded?

Can you reproduce the problem in the playground directory?

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 27, 2024

@johnsoncodehk I got many Errors in every .vine.ts after the latest commit, is that because those globalTypes and TS service are not completely loaded?

Can you reproduce the problem in the playground directory?

@johnsoncodehk Yes, for now if I want to verify our results for language service support, I'll do:

  1. run build script in the root directory to ensure we have the latest dists
  2. click VSCode's Debug panel -> "Run Vine extension”
  3. The extension debug host window automatically opens packages/playground, and I'll open src/vine/app.vine.ts to see the syntax highlight & TS semantics diagnoses

Could you reproduce the same as what I saw here after following these steps above in your environment?

image

@johnsoncodehk
Copy link
Contributor Author

johnsoncodehk commented Mar 27, 2024

This seems to be vuejs/language-tools#3942, which may be related to the extensions you installed.

This issue cannot be avoided from us and I will discuss this with the TS team.

@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 27, 2024

This seems to be vuejs/language-tools#3942, which may be related to the extensions you installed.

This issue cannot be avoided from us and I will discuss this with the TS team.

@johnsoncodehk Thanks a lot !!!!

After switching from my Linux PC to my Mac, there's indeed not these diagnoses occurred.

Everything looks pretty fine now.

So I'll merge this PR, and we can open new PRs for further extension features later.
The next big thing may be Intellisense for component name after typing '<'

@ShenQingchuan ShenQingchuan marked this pull request as ready for review March 27, 2024 03:48
@ShenQingchuan ShenQingchuan merged commit 622f87f into vue-vine:main Mar 27, 2024
8 checks passed
@ShenQingchuan
Copy link
Member

ShenQingchuan commented Mar 27, 2024

Oh I figured out ~

@johnsoncodehk It seems like that I meet some problems with VSCode extension bundling that after packing out a .vsix file, installing locally and opening a .vine.ts, I found there's not a Vine Language Server in "Output" panel.

Can easily reproduce in main branch now with the same operations.


With some exploring by myself, I can make "Vine Language Server" show but still nothing output correctly.

After installing packed VSIX file and I saw Vine language server is working fine with Volar Labs, it shows virtual files and service plugins.
But the output panel shows like this:

image

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

Successfully merging this pull request may close these issues.

None yet

2 participants