Skip to content

Conversation

@devmattrick
Copy link
Contributor

This PR fixes #1262 by adding a new configuration option: svelte.plugin.svelte.defaultScriptLanguage. This option can either be none or ts, which will configure Svelte VSCode to use <script> or <script lang="ts"> respectively when generating new script tags on auto import.

Let me know if you'd like any changes. Thanks!

Copy link
Member

@jasonlyu123 jasonlyu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

Can you also document the config to the README?

"title": "Svelte: Rename",
"description": "Enable rename/move Svelte files functionality"
},
"svelte.plugin.svelte.defaultScriptLanguage": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this inside completions? Like "svelte.plugin.svelte.completions.defaultScriptLanguage"? @jasonlyu123 what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It is also being used in the code action. if we want to further organize it. Maybe the name needs to be more generic. Maybe something like suggest or preferences?

Copy link
Member

@dummdidumm dummdidumm Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, it's also part of the code action. In that case, never mind 😄 My fear is that people would mistake this as something like "if I set this I don't need to write <script lang="ts"> at all" (like the deprecated and discouraged default language of svelte preprocess).

@RemyRylan
Copy link

Thanks @devmattrick for getting this together. I just wanted to ask before a maintainer here merges: is this something that should instead go in svelte.config.js?

I see this issue #422, would it be more straightforward to use that method instead?

// svelte.config.js
export default {
  preprocess: [
    autoPreprocess({
      defaults: { script: 'typescript' },
    }),
  ],
};

Does the VS Code extension pickup your svelte.config.js file?

@dummdidumm
Copy link
Member

dummdidumm commented Dec 9, 2021

The config you mention is deprecated and discouraged. Problem is that not all tooling can reliably read the config, and there's also syntax highlighting limitations - as a result you get all kinds if weird behavior. This PR should only be about adding lang="ts" during a auto import or code action which creates a script tag, which is an editor-only feature so it shouldn't be part of svelte.config.js

@RemyRylan
Copy link

@dummdidumm got it, thank you!

@dummdidumm dummdidumm merged commit a572c7c into sveltejs:master Dec 10, 2021
@qwabra
Copy link

qwabra commented Oct 19, 2022

.vscode/settings.json

{
	"svelte.plugin.svelte.defaultScriptLanguage": "ts"
}

does not work?!

expexted <script lang="ts"></script>
instead <script></script>
it is right?

@jasonlyu123
Copy link
Member

nope. This PR is for the script tag created when there's an auto-import.

<C

to

<script lang="ts">
  import Component from 'path/to/Component.svelte'
</script>

<Component

@qwabra
Copy link

qwabra commented Oct 21, 2022

"an auto-import" hmm.

what about snippets, is that possible by Svelte config?

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.

Allow configuration of default script language

5 participants