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 Q# language support #4901

Merged
merged 14 commits into from
Jul 22, 2020
Merged

Add Q# language support #4901

merged 14 commits into from
Jul 22, 2020

Conversation

JakuJ
Copy link
Contributor

@JakuJ JakuJ commented Jun 26, 2020

Description

This PR intends to add support for Microsoft's Q# quantum programming language. The source files associated with this language come with the ".qs" extension.

Adding the language to Linguist by itself, however, would mean misclassifying a lot of Qt Script files as Q#, as it uses the same extension and is also not yet supported by Linguist. Therefore, this PR also attempts to add support for Qt Script.

Colors

I am in no way associated with Microsoft, and the #2a59ff #2a59ff color I've chosen for the language (lacking an official logo that I know of) is pretty much arbitrary, albeit close to the color of the logo of the official VSCode extension. It's also different enough from green and purple associated with C# and F# – languages commonly used alongside Q# in the same repository.

Update: The colour associated with Q# is now "fridge gold" #fed659 #fed659 .

The color for Qt Script is #00b841 #00b841 – the closest one I've found to the color of Qt's logo that's still available.

Q# syntax

The official grammar (template) resides deep inside the qsharp-compiler repository. The script/add-grammar utility is not able to find the grammar file in this repo, probably because of the extension. The grammar itself works when pasted into Lightshow.

The grammar I found for the language might seem a bit old (the repository is 2 years old and archived), however, the Lightshow website shows the same highlighting for both grammars (tested on the sample sources), so I think it's okay.

Update: the owner of the repository containing syntax for Q# took it down, which means no syntax highlighting for the language, at least until microsoft/qsharp-compiler#504 gets resolved.

Update 2: The issue got resolved, official syntax for Q# has been added.

Checklist for Q#:

Checklist for Qt Script:

  • I am adding a new language.
    • The extension of the new language is used in hundreds of repositories on GitHub.com.
      • Search results for each extension:
        • qs (this matches 438 repositories at the time of submitting the PR)
    • I have included a real-world usage sample for all extensions added in this PR:
    • I have included a syntax highlighting grammar Qt Script uses JavaScript's syntax highlighting
    • I have updated the heuristics to distinguish my language from others using the same extension

@pchaigno
Copy link
Contributor

pchaigno commented Jul 5, 2020

The script/add-grammar utility is not able to find the grammar file in this repo, probably because of the extension.

Yep, that's likely the cause. Any idea why they're not using the standard file extensions?

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 the contribution!

lib/linguist/languages.yml Show resolved Hide resolved
@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 5, 2020

The script/add-grammar utility is not able to find the grammar file in this repo, probably because of the extension.

Yep, that's likely the cause. Any idea why they're not using the standard file extensions?

The extension they use is "tmLanguage.json.v.template". The file itself is part of the VSCode extension for the language, so I guess they are generating the actual syntax file locally, after it's installed. After closer inspection, it seems that there was at least one change to the file after the other repository was archived - the "internal" keyword is now legal. This confirms my doubts – the repository is, after all, outdated. I will I reach out to the maintainers of the official repository and see what can be done.

@pchaigno
Copy link
Contributor

pchaigno commented Jul 5, 2020

After closer inspection, it seems that there was at least one change to the file after the other repository was archived - the "internal" keyword is now legal. This confirms my doubts – the repository is, after all, outdated. I will I reach out to the maintainers of the official repository and see what can be done.

Please note a grammar isn't required for initial support in Linguist. We can add it as a follow up. The language will still show up in search queries and statistics in the meantime.

@tcNickolas
Copy link

tcNickolas commented Jul 8, 2020

@JakuJ I'm so excited to see this PR! I am part of the Microsoft Quantum team, and we've been thinking that we need to look into adding Q# to Linguist for a while - now we don't! :-)

If I may offer a suggestion for the color, our latest official color palette includes ivory (#f2eadb), dark orange (#6b2929), dark teal (#274b47), dark blue (#243a5e) and yellow (#ffb900).

The "most frequently used with" languages are probably C#, Python and Jupyter notebooks, with some *shell, so it makes sense to pick the color from our palette that would work nicely with all of these. (Here is a languages bar of the Quantum Katas repo which is fairly representative of the languages typically used with Q#.)

image

Looking at this, I would lean towards the lighter colors, ivory (#f2eadb)
image
or yellow (#ffb900)
image

Thank you again for working on this!

@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 9, 2020

@tcNickolas Always a pleasure to help out 😄 Speaking of colours, unfortunately the ones you've proposed are not available, according to the Free Colour Picker. Some of the closest free colours include:

#ffddb6 #ffddb6
#ffe88d #ffe88d
#fdd257 #fdd257
#ff9912 #ff9912

If you ask me, anything yellow/goldish wold be nice, reminds me of the gold-plated vertical rods in a quantum computer – the first image everyone sees after googling the phrase 😀 However, I think it'd be best for the people behind the project to choose the colour. Use the Picker and if you find a colour that's good enough, I'll update the PR.

Edit: The Picker doesn't really show you which colours are available unless you mouse over them, so I've painted over those to make it a bit easier for you. You should still use the Picker for the exact hex codes.

free_colours

@tcNickolas
Copy link

I like #fdd257 #fdd257 (the third one you suggested). I didn't even think of the fridge pictures, but you're right, there is a resemblance.

Thank you!

@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 9, 2020

Apparently the color proximity algorithm used by the Picker is not quite the same as the one used by Linguist. So #fdd257 #fdd257 doesn't actually pass the tests. However, #fed659 #fed659 does and personally I see no difference, so I'll just go with this one.

@pchaigno
Copy link
Contributor

Apparently the color proximity algorithm used by the Picker is not quite the same as the one used by Linguist. So #fdd257 #fdd257 doesn't actually pass the tests. However, #fed659 #fed659 does and personally I see no difference, so I'll just go with this one.

@lildude Any idea what's happening here? Are we not using the same versions of dependencies?

@pchaigno pchaigno requested a review from lildude July 11, 2020 09:47
@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 11, 2020

Alright, microsoft/qsharp-compiler#504 got resolved and we've now got access to the official syntax for Q#, so I've just added it here. This makes support for the language complete from day one.

@pchaigno
Copy link
Contributor

Alright, microsoft/qsharp-compiler#504 got resolved and we've now got access to the official syntax for Q#, so I've just added it here. This makes support for the language complete from day one.

Awesome! Could you update the original post's template with a highlighting example?

@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 11, 2020

@pchaigno Sure thing, done.

@JakuJ
Copy link
Contributor Author

JakuJ commented Jul 18, 2020

Revisiting this PR as it's been a whole week now since the last activity. The changes have been approved and all the checks have passed. Is there anything else that should be done? @pchaigno @lildude

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

This won't go live on GitHub.com until I make a release, which I'm aiming to do before 3 Aug, though can't promise anything.

@lildude lildude merged commit ba9c24c into github-linguist:master Jul 22, 2020
@Alhadis
Copy link
Collaborator

Alhadis commented Jul 22, 2020

@tcNickolas Just a random tip when writing hexadecimal colour-codes on GitHub: enclosing the code in backticks will display the colour when rendered. E.g., instead of writing #000000, write `#000000` (which produces #000000).

Alhadis added a commit to file-icons/atom that referenced this pull request Jul 24, 2020
sambacha pushed a commit to freight-trust/linguist that referenced this pull request Sep 4, 2020
* Add Q# language support

* Add a color for Q#

* Make Q# colour closer to the VSCode extension logo

* Add support for Qt Script

* Remove Q# syntax repo

* Properly remove the submodule

* Add heuristics for Q# and Qt Script

* Fine-tune the '.qs' heuristics

* Change Q# colour to "fridge gold"

* Add the official grammar for Q#
Copy link

@zxc41bm6 zxc41bm6 left a comment

Choose a reason for hiding this comment

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

.

@github-linguist github-linguist deleted a comment from zxc41bm6 Mar 28, 2022
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants