Skip to content

Add possibility to define language defaults #189

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

Closed
dummdidumm opened this issue Jun 25, 2020 · 10 comments
Closed

Add possibility to define language defaults #189

dummdidumm opened this issue Jun 25, 2020 · 10 comments
Assignees
Labels
enhancement New feature or request next-major will be fixed in the next major

Comments

@dummdidumm
Copy link
Member

dummdidumm commented Jun 25, 2020

Is your feature request related to a problem? Please describe.
If a project settles on a specific language for scripts/styles/markup, it usually wants to use that in ALL scripts/styles/markup. Yet we have to define the language explicitely each time.

Describe the solution you'd like
A new settings through which you can set defaults for script/styles/markup, something like this:

preprocessorDefaults: {
   script: 'typescript',
   styles: 'less'
   // no markup default
}

This means every tag would be preprocessed with said language, even if I don't specify lang="typescript" for example. If I specifiy either type or lang on the tag, that one is used instead.

Describe alternatives you've considered
None.

How important is this feature to you?
Would help saving typing that 20 characters each file, but not a deal breaker.

Additional context
If this gets implemented, the language-tools-repo needs to update its doc accordingly.

@kaisermann kaisermann added the enhancement New feature or request label Jun 25, 2020
@kaisermann
Copy link
Member

Hey @dummdidumm 👋 I'm not completely against being able to define default processors, but as stated in #184 it's something that can negatively affect the DX of svelte projects. How do you see the language-tools handling this situation?

@dummdidumm
Copy link
Member Author

Oh, I did not see that issue, sorry about that 🤦

It either would need its own settings in svelte.config.js or somehow interact with the preprocessor (getting its settings).
So it would be a tradeoff -> more initial setup necessary, less typing afterwards.

@kaisermann
Copy link
Member

No worries 😀 This is an even stronger signal that this feature is wanted / useful. We have to find the most frictionless way of doing this with the language-tools team.

My brainstorming thoughts:

  • Adding these options to svelte-preprocess would make the language-tools need to treat this preprocessor differently. I'm not sure if this is the best way forward, even if it's now considered a official package.

  • Adding them directly to the root of svelte.config.js would force us to look for this file to get these configs. One could create an object with the default languages config and pass it to both svelte-preprocess and, being creative here, export it to the language-tools, like:

const defaults = {
   script: 'typescript',
   styles: 'less'
}

module.exports = {
  preprocess: preprocess({ defaults })
}

exports.defaults = defaults

Would this only work in auto preprocessing? Or standalone processors should also respect these default configs? I'm not sure what would be the benefit of using each processor separately and wanting to set default languages (apart from not having to type the language attribute).

@kaisermann kaisermann self-assigned this Jun 25, 2020
@dummdidumm
Copy link
Member Author

dummdidumm commented Jun 25, 2020

Good thought about the interoperability with other preprocessors. I think the best way would be to just duplicate it then like you proposed, so there is a separate setting for the language server and the preprocessor, so they don't have to know of each other. In the docs on both sides it then needs to be made clear that this can only be used when both the preprocessor and the IDE Svelte extension support this setting, which would be the case for svelte-preprocess and svelte-language-server.

@benmccann
Copy link
Member

I like this idea. It'd be good to have something like lang="text/javascript" work as an override to opt-out if I set typescript as the default

@dummdidumm
Copy link
Member Author

I agree. If either lang or type is set, this would be used as before, else the default one.

kaisermann added a commit that referenced this issue Jul 1, 2020
@kaisermann
Copy link
Member

Had sometime today to tackle this one and I think I've managed to do it in a good way. Default languages will be css, javascript and html (technically incorrect, I know 👀), but by passing defaults: { markup, style, script } you'll be able to override them. Implemented this in the v4 branch (commit)

kaisermann added a commit that referenced this issue Jul 1, 2020
kaisermann added a commit that referenced this issue Jul 1, 2020
kaisermann added a commit that referenced this issue Jul 1, 2020
@gavinmcfarland
Copy link

Hi, I have a use case to add to this. Although I think it might have some slightly new contexts.

I'm using pHTML in my projects which allows me to preprocess HTML. It's a bit similar to PostCSS in the respect that it's not a replacement for things like SASS. It works in tandem. So in this case pHTML really ought to work 1. After all other preprocessors and 2. Work without a template tag. This way anything which is processed by say something like Pug can be passed next to the pHTML preprocessor.

@kaisermann kaisermann reopened this Jul 4, 2020
@kaisermann
Copy link
Member

@limitlessloop Hey 👋

I don't think this is related to being able to define default languages. Could you create a specific issue for pHTML support? It could be implemented in a similar way to the postcss and babel transformers.

@gavinmcfarland
Copy link

@kaisermann ah I see, ok. Thanks I'll raise an issue to see if you can advice how to set it up. Thank you.

kaisermann added a commit that referenced this issue Jul 5, 2020
@kaisermann kaisermann added the next-major will be fixed in the next major label Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next-major will be fixed in the next major
Projects
None yet
Development

No branches or pull requests

4 participants