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

Add support for Svelte. #4323

Closed
wants to merge 2 commits into from
Closed

Conversation

umanghome
Copy link
Contributor

@umanghome umanghome commented Nov 12, 2018

Add support for Svelte.

Checklist:

@umanghome umanghome force-pushed the svelte branch 2 times, most recently from 912bb6c to 8ba151c Compare November 12, 2018 12:14
Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

Thanks for submitting the pull request!

Could you please update the template with the required information (the search query for in-the-wild usage, information on added samples, and the link to Lightshow showing the grammar in action)?

@umanghome
Copy link
Contributor Author

@pchaigno Done.

@Rich-Harris
Copy link

Svelte creator here, via Twitter. Amazing work Umang, thank you!

I noticed that the sample file is using the old Svelte 1 template syntax (e.g. double {{curlies}}) — is that intentional? Relatedly, we created a separate project to maintain the Svelte 2 syntax called HTMLx (the intention being that other frameworks are free to adopt it without having to invent their own syntax). Eventually our recommendation will be that people use the .htmlx file extension. Is it possible to support .htmlx here alongside .svelte?

@umanghome
Copy link
Contributor Author

@Rich-Harris Didn't notice the example was written in an older version. I picked up a file from an example on GitHub because the Svelte code that I write for work is confidential. I will pick up an updated sample and update the repository.

I can add .htmlx too, but the usage doesn't seem to be very much yet. I took a look at the README and it seems like it uses the same Grammar as Svelte does. In which case, it would make more sense to add support for HTMLx syntax rather than Svelte syntax as the base, and then let Svelte inherit this base.

@Rich-Harris
Copy link

Yeah, usage will be effectively zero for now since we haven't promoted the extension at all (because of the lack of linguist support, which this PR solves!) — we generally just go with good old .html, which gets you 90% of the way there. I spot-checked a few existing uses of .htmlx (without restricting it to files that also include export default) and it seems that in most cases it's temporary renaming of files (i.e. people adding an 'x' as an alternative to e.g. 'file.OLD.html')

@umanghome
Copy link
Contributor Author

@Rich-Harris Would you agree on keeping HTMLx as the base syntax and then inheriting Svelte syntax support from it for the sole purpose of syntax highlighting?

@Rich-Harris
Copy link

That makes sense to me, yes

@umanghome
Copy link
Contributor Author

I'm keeping .htmlx another extension for Svelte as of now. We can move it later to its own language once it gains enough traction.

@umanghome
Copy link
Contributor Author

@pchaigno Are there any guidelines on selecting a color for newly added languages?

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

I've left a few comments below that should help you address the Travis CI build failures.
Could you also check whether these files are Svelte files too? They looks like plain HTML files to me.

codemirror_mime_type: text/html
color: "#e34c26"
extensions:
- ".svelte"
Copy link
Contributor

Choose a reason for hiding this comment

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

I counted 117 repositories by 102 users from the search query you provided. That a bit low considering our usual requirement of hundreds of repositories, but it's unlikely we'll get any conflicts in the future given the extension. @lildude 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.

Unfortunately, that usage is not high enough for inclusion right now, it's barely over a hundred let alone hundreds.

@@ -4343,6 +4343,17 @@ STON:
tm_scope: source.smalltalk
ace_mode: text
language_id: 336
Svelte:
type: markup
tm_scope: text.html.svelte
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be source.svelte.

ace_mode: html
codemirror_mode: htmlmixed
codemirror_mime_type: text/html
color: "#e34c26"
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to set a color since it has a group; it will automatically take the parent's color.

@@ -4343,6 +4343,17 @@ STON:
tm_scope: source.smalltalk
ace_mode: text
language_id: 336
Svelte:
Copy link
Contributor

Choose a reason for hiding this comment

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

Items in languages.yml should be alphabetically sorted, with uppercase letters first.

@Rich-Harris
Copy link

They're not Svelte files — my hypothesis is:

in most cases it's temporary renaming of files (i.e. people adding an 'x' as an alternative to e.g. 'file.OLD.html'

Happily, HTML files highlighted as HTMLx will be identical except in some unusual edge cases, so the worst that will result from the false positive is that those files will now be highlighted as HTML instead of not at all.

At present, the vast majority of Svelte files are written with an .html extension. There are enough .svelte files to show up in search, but ideally we'd want to use the .htmlx extension instead — we've just held off doing that someone got around to sending a PR to linguist (and that someone turned out to be @umanghome!).

@pchaigno
Copy link
Contributor

They're not Svelte files — my hypothesis is:

in most cases it's temporary renaming of files (i.e. people adding an 'x' as an alternative to e.g. 'file.OLD.html'

Sorry, I missed that before.

Happily, HTML files highlighted as HTMLx will be identical except in some unusual edge cases, so the worst that will result from the false positive is that those files will now be highlighted as HTML instead of not at all.

Usage is way too low to add them now. Maybe we could add .htmlx as a HTML extension though (in a separate pull request)? I counted 351 repositories by 327 users so usage is fine.

If you think usage of .htmlx for Svelte files will grow rapidly, I can add the extension to #4219.

we've just held off doing that someone got around to sending a PR to linguist.

With this pull request, you'll be able to switch on syntax highlighting of .htmlx Svelte files on a per-repository basis, using Linguist overrides.

@Rich-Harris
Copy link

Ah, nice, I didn't know about overrides.

Maybe we could add .htmlx as a HTML extension though (in a separate pull request)?

That would make it practical to start using that extension, which could hopefully solve the chicken-and-egg problem we have at the moment, so yes — that sounds like an excellent starting point. Could you point us in the right direction please?

I expect usage will grow in time, yes — if you could add it to #4219 that'd be great. Thank you!

@umanghome
Copy link
Contributor Author

If we are going to add support for .htmlx, I would recommend making .svelte one of the file extensions for the HTMLx language. I would be happy to work on adding HTMLx in a different PR if we decide to close this one and go with HTMLx instead.

@pchaigno
Copy link
Contributor

Could you point us in the right direction please?

You can follow the contribution guidelines for that.

If we are going to add support for .htmlx, I would recommend making .svelte one of the file extensions for the HTMLx language. I would be happy to work on adding HTMLx in a different PR if we decide to close this one and go with HTMLx instead.

I wasn't suggesting to add HTMLx as a language, just .htmlx as a new HTML extension.

if you could add it to #4219 that'd be great.

Done.

@stale
Copy link

stale bot commented Dec 14, 2018

This pull request has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this pull request was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

@stale stale bot added the Stale label Dec 14, 2018
@stale
Copy link

stale bot commented Dec 29, 2018

This pull request has been automatically closed because it has not had activity in a long time. Please feel free to reopen it or create a new issue.

@stale stale bot closed this Dec 29, 2018
@umanghome umanghome mentioned this pull request Apr 23, 2019
18 tasks
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants