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

Auto-import of component adds a new <script> tag if <script> is below markup #547

Closed
ItalyPaleAle opened this issue Sep 18, 2020 · 1 comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@ItalyPaleAle
Copy link

Describe the bug
In my Svelte components, I put the <script> block after the markup. When I use the auto-import feature to import a new component, the language server adds a new <script> tag at the beginning of the file, which causes a compielr error.

To Reproduce

Start with this component:

<p>Hello World!</p>
<Foo />

<script>
import Foo from './Foo.svelte'
</script>

After <Foo /> type the name of another component not yet imported, such as <Bar then let auto-complete finish the import.

Expected behavior
This should appear:

<p>Hello World!</p>
<Foo />
<Bar />

<script>
import Foo from './Foo.svelte'
import Bar from './Bar.svelte'
</script>

Actual behavior

This appears instead (which causes a compiler error because you can't have more than 1 script tag):

<script>
import Bar from './Bar.svelte'
</script>

<p>Hello World!</p>
<Foo />
<Bar />

<script>
import Foo from './Foo.svelte'
</script>

System (please complete the following information):

  • OS: Linux
  • IDE: VS Code
  • Plugin/Package: svelte.svelte-vscode
@ItalyPaleAle ItalyPaleAle added the bug Something isn't working label Sep 18, 2020
@dummdidumm
Copy link
Member

The problem is that, while you're in the middle of typing, the code is an error-state (unclosed tag). Because of that, everything after the unclosed-tag is treated as the child of that tag - including the top level script tag. Therefore the intellisense thinks there's no top level script tag yet and creates one. We need to investage if we can check if that tag is not closed and try to mark the children as top level so the script is recognized correctly.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Sep 26, 2020
Tries to parse the HTML document and work around the limitations of the underlying parser which will trip up when there's a non-closed tag and treat everything afterwards as its child.
sveltejs#547
dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Oct 29, 2020
- Parser got better: Now sees `<` as start of other opening tag. sveltejs#547, closes sveltejs#578
- New option to not provide default data provider which removes duplicate suggestions
dummdidumm added a commit that referenced this issue Oct 29, 2020
- Parser got better: Now sees `<` as start of other opening tag. #547, closes #578
- New option to not provide default data provider which removes duplicate suggestions
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants