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

Code completion for expressions in the markup doesn't work properly #1302

Closed
aradalvand opened this issue Dec 28, 2021 · 2 comments · Fixed by #2631
Closed

Code completion for expressions in the markup doesn't work properly #1302

aradalvand opened this issue Dec 28, 2021 · 2 comments · Fixed by #2631
Labels
bug Something isn't working limitation Constraints of the existing architecture make this hard to fix upstream

Comments

@aradalvand
Copy link

aradalvand commented Dec 28, 2021

Describe the bug
Code completion in JavaScript expressions in the markup doesn't work (as least as reliably) as it does in the script tag.

To Reproduce
I have a client object that contains various functions that send fetch requests, when I'm in the <script> and I type client and then hit ., this is the list of suggestions that appears, exactly what's expected:
image

But when I do the same thing in an {#await} block, for example, this is the list of suggestions:
image
As you can see, there is all sorts of unrelated stuff in there. I'm assuming this has something to do with this extension or the Svelte language server.
I've had this problem since the beginning, but I always thought "it's probably gonna be fixed soon", and I assumed there was an already-existing issue for it or something.

Expected behavior
I expect to see the members of the client objects properly as they are shown when I do client. in the script tag.

System (please complete the following information):

  • OS: Windows 10
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode
@aradalvand aradalvand added the bug Something isn't working label Dec 28, 2021
@aradalvand aradalvand changed the title Code completion for expression in the markup doesn't work properly Code completion for expressions in the markup doesn't work properly Dec 28, 2021
@jasonlyu123
Copy link
Member

This is a limitation we currently have. The syntax transformation under the hooks relies on the AST the svelte compiler returned. So it won't work if there's a syntax error in the markup. See sveltejs/svelte#4818. It should be working again once there's no syntax error. Like if you have at least an identifier after ..

This won't be completely fixed anytime soon. What we can do is find a workaround for each case to slightly improve it.

dummdidumm pushed a commit that referenced this issue Feb 16, 2022
Related to #538, #786 and #1302

This PR added a utility to check if there's trailing property access behind an expression. The Reason we needed this is that we blank the operators before parsing. So the operator won't exist in the AST. We need to check it so that the expression transformation also include it.

This should only be called with an expression that is a direct child of a template node. And since we only go backwards from the end of the moustache (}), it only makes sense to call this with the expression that might end directly before the end of the moustache.
@jasonlyu123 jasonlyu123 added limitation Constraints of the existing architecture make this hard to fix upstream labels Feb 6, 2023
@ptrxyz
Copy link

ptrxyz commented Jul 27, 2024

Funny enough autocompletion works if you try it with brackets. Type client[" and it'll show you the properties.

And even more funny: if you simply put client. (yes, simply this syntactically wrong line) as last line in your script tag, autocompletion in the template also works fine.

There is some black magic going on here. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working limitation Constraints of the existing architecture make this hard to fix upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants