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 custom exe path, icons, and improve syntax highlighting #30

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

myleslinder
Copy link

@myleslinder myleslinder commented Sep 25, 2022

Love your work on the language so far. I had some syntax highlighting issues with my theme so took a stab at making some updates and tried to address some open issues in the process. Let me know if there's any issues or you need any updates.

Custom Path
Should close #26
Added a setting to change the path to the Gleam executable. By default, it looks for it in the PATH, but if the setting has a value it will use the path specified instead.
I've set the scope to machine as it seems to be what is recommended in the configuration schema docs

For example, an installation path which shouldn't be shared across machines

If an executable can't be found at the path an error dialog is shown to the user.

Default Formatter
I've set the default formatter in the configuration so users won't have to set that themselves.

Language Icons
I added these icons before I noticed that PR #29 already exists so apologies for the duplication. The icons are svgs and using the black for light themes and pink for dark themes.

Syntax Highlighting
This may close #24 as if the variable name starts with an _ I've set it to be source.ignore which is a scope themes often target and even if they don't it will be stylized differently than regular variables. As far as I could see there's no way to accomplish the reduced opacity in the grammar and other languages I checked out (Go and TS) both don't have reduced opacity when the unused variable is ignored with the _ prefix.

I set up a number of new matches for different parts of the grammar and split out most of the keywords into their own patterns to the most accurate scope that themes are likely to target. I ran into some issues with proper scope assignment on the outer function names in the case of multiple nested function calls that are the formatter doesn't split across multiple lines and that don't use the pipe operator (e.g. f(f(x))).

High level overview of the changes:

  • todo is identified as a system provided function
  • The prelude types listed in the language tour are also indicated as system provided, however the prelude values are handled differently
  • ., and , are indicated as punctuation scopes
  • previously defined keywords are assigned to unique scopes
  • additional keywords have been added such as as, #, :
  • Nil is scoped as a null
  • import statements are split into scopes for the import keyword, a name if applicable (e.g. in gleam/io, gleam is scoped as the import name), and variables for the usable values. The entire import statement is scoped as well.
  • variables are more broadly scoped to include usage in case, function calls, etc
  • functions without parentheses in a pipeline are scoped as function names
  • type constructor functions are scoped as functions when they're called

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Wow! This is brilliant, thank you. And thanks for waiting while I have been on holiday.

Ive left one question in line

syntaxes/gleam.tmLanguage.json Outdated Show resolved Hide resolved
@lpil
Copy link
Member

lpil commented Dec 1, 2022

Hi @myleslinder , shall I pick this PR up from you?

@myleslinder
Copy link
Author

@lpil sorry for the radio silence, I can get this over the finish line this week. Are there any other changes you need aside from not styling the prelude types differently?

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Hey @myleslinder ! Slow for the slow reply, I quit my job and then immediately fell unwell 😷

That sounds great to me!

@myleslinder
Copy link
Author

myleslinder commented Feb 6, 2023

@lpil made the changes you requested and added the use keyword. Again, apologies for the terribly long delay. Let me know if you need anything else!

}
},
{
"match": "(?:{| |, |\\/|\\.|\\[|\\()(\\.\\.)*(?!\\bas\\b|\\blet\\b|\\bfn\\b|\\buse\\b|\\bconst\\b|\\bcase\\b|\\btry\\b|\\bassert\\b|\\bif\\b|\\bopaque\\b|\\bexternal\\b|\\btype\\b|\\b_+\\w*\\b|\\blet _+\\w*\\b)(\\w+\\()*([a-z_]+)(?!\\/|\\(|:)\\b",
Copy link
Member

Choose a reason for hiding this comment

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

Since try is no longer a keyword:

Suggested change
"match": "(?:{| |, |\\/|\\.|\\[|\\()(\\.\\.)*(?!\\bas\\b|\\blet\\b|\\bfn\\b|\\buse\\b|\\bconst\\b|\\bcase\\b|\\btry\\b|\\bassert\\b|\\bif\\b|\\bopaque\\b|\\bexternal\\b|\\btype\\b|\\b_+\\w*\\b|\\blet _+\\w*\\b)(\\w+\\()*([a-z_]+)(?!\\/|\\(|:)\\b",
"match": "(?:{| |, |\\/|\\.|\\[|\\()(\\.\\.)*(?!\\bas\\b|\\blet\\b|\\bfn\\b|\\buse\\b|\\bconst\\b|\\bcase\\b|\\bassert\\b|\\bif\\b|\\bopaque\\b|\\bexternal\\b|\\btype\\b|\\b_+\\w*\\b|\\blet _+\\w*\\b)(\\w+\\()*([a-z_]+)(?!\\/|\\(|:)\\b",

},
{
"name": "keyword.control.trycatch.gleam",
"match": "\\b(try|assert)\\b"
Copy link
Member

Choose a reason for hiding this comment

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

Since try is no longer a language keyword:

Suggested change
"match": "\\b(try|assert)\\b"
"match": "\\b(assert)\\b"

Copy link
Member

Choose a reason for hiding this comment

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

Can we call it assertion or something rather than trycatch?

}
},
{
"match": "(\"\\w+(?:\\/*\\w+\\.{1}(?:js|mjs|cjs)+)*\") (\"\\w+\")",
Copy link
Member

Choose a reason for hiding this comment

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

What does this do?

},
{
"name": "keyword.control.trycatch.gleam",
"match": "\\b(try|assert)\\b"
Copy link
Member

Choose a reason for hiding this comment

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

Can we call it assertion or something rather than trycatch?

@lpil
Copy link
Member

lpil commented May 30, 2023

I've been testing this out and for some reason none of the grammar changes seems to be changing my syntax highlighting. I'm running npm run compile-watch and press f5 to open a new vscode window. Is there something else I need to do?

image

@PgBiel
Copy link

PgBiel commented Apr 15, 2024

Could the custom PATH changes be perhaps pulled into a separate PR to make it easier to review? I'm particularly interested in this feature.

Let me know if I could pick that up, if that'd be interesting.

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.

Make the gleam executable file/path configurable. discarded args not greyed out
4 participants