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

Highlight fixes #241

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

Conversation

Emilios1995
Copy link
Contributor

@Emilios1995 Emilios1995 commented Mar 21, 2024

This PR contains some updates to existing highlights to conform to neovim's latest documentation, and also introduces a few missing ones.

The new features are:

  • Highlights function calls
  • Highlights module and record pattern members
  • Highlights units as built-in constants
  • Highlights labeled parameters

Comment on lines 21 to +28
[
(variant_identifier)
(polyvar_identifier)
] @constant
] @constructor
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not everyone might agree on this one, since variants, specially polyvars without parameters, are used as "constants". This thinking is common when making JS bindings, since polyvars compile to strings.

However, from a language perspective, I find it more correct to think of them as constructors. This is also how the ocaml parser highlights them.


; single parameter with no parens
(function parameter: (value_identifier) @parameter)
(function parameter: (value_identifier) @variable.parameter)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and other similar changes conform to to Neovim's new tags with fallbacks. Meaning, if a certain theme specifies a color for @variable.parameter, it will be used, but otherwise it will fall back to the color for @variable.

@Emilios1995 Emilios1995 marked this pull request as ready for review March 21, 2024 18:22
@Emilios1995 Emilios1995 marked this pull request as draft March 21, 2024 18:24
@Emilios1995 Emilios1995 force-pushed the highlight-fixes branch 2 times, most recently from ccdbd1b to b5bbe2f Compare March 25, 2024 01:52
(module_identifier) @namespace
(module_identifier) @module

(member_expression (property_identifier) @variable.member)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was @property and was changed to @variable.member. I looked at other languages and this is how it's usually handled: @property is for places such as record definition when both the property and value are explicitly written, and member is for extracting a value out of that property. (which is why it belongs to the variable group.)

@Emilios1995 Emilios1995 marked this pull request as ready for review March 25, 2024 02:12
@aspeddro
Copy link
Collaborator

Great job, leaving some comments and questions I had when testing highlighting in the rescript-lang repo..

The parameter start and end_ is highlighted as @property.rescript. Wouldn't @variable.parameter be better?

Js.Array2.slice(~start=0, ~end_=Js.Array2.length(moduleRoute) - 1)

Code


"value" is highlighted as @variable.member. It should be @string?

let version = (evt->ReactEvent.Form.target)["value"]

Code


slug is a value, I think it should just be @variable

let rehypePlugins =
      [Rehype.WithOptions([Plugin(Rehype.slug), SlugOption({prefix: slugPrefix ++ "-"})])]->Some
                                       // ^ slug is highlighted as variable.member

Code


moduleName inside template string is highlighted as @string

let pathModule = Path.join([dir, version, `${moduleName}.json`])

Code


row, column and shrotMsg is highlighted as @variable.member but not row in Api.LocMsg.row. Should it be highlighted? I really don't know

let {Api.LocMsg.row: row, column, shortMsg} = locMsg
              // ^ not highligted     

Code

@Emilios1995
Copy link
Contributor Author

The parameter start and end_ is highlighted as @property.rescript. Wouldn't @variable.parameter be better?

Js.Array2.slice(~start=0, ~end_=Js.Array2.length(moduleRoute) - 1)

parameter is usually used for the parameter themselves when declaring the arguments of a function. Here, the labels are the names of the parameters. In other words, in your example, 0 is more of a variable.parameter than ~start.

My reasoning on using property is that in the Neovim docs is defined as "The key in a key/value pair", which made sense here.

However, I can see how it's not an exact fit.

In OCaml they use @label. It is not a good fit based solely on the Neovim docs description, which is:
"GOTO and other labels (e.g. label: in C), including heredoc labels"
However, label is a whole different concept in OCaml and these are indeed labeled arguments, so it can work too.

What do you think? It's hard to debate what label fits better objectively, and it's hard to analyze which one looks better across themes. Honestly I think either parameter, property, or label are fine.

Code

"value" is highlighted as @variable.member. It should be @string?

let version = (evt->ReactEvent.Form.target)["value"]

Yeah, that should be @string.

slug is a value, I think it should just be @variable

let rehypePlugins =
      [Rehype.WithOptions([Plugin(Rehype.slug), SlugOption({prefix: slugPrefix ++ "-"})])]->Some
                                       // ^ slug is highlighted as variable.member

My thinking is that it's the member of a module... but perhaps it's best to use member only for record fields.
Indeed, in OCaml they use @variable. I'll change it.

moduleName inside template string is highlighted as @string

let pathModule = Path.join([dir, version, `${moduleName}.json`])

Yeah that's wrong.

row, column and shrotMsg is highlighted as @variable.member but not row in Api.LocMsg.row. Should it be highlighted? I really don't know

let {Api.LocMsg.row: row, column, shortMsg} = locMsg
              // ^ not highligted     

I like how OCaml handles it. Applied to this example, it would be:

let {Api.LocMsg.row: row, column, shortMsg} = locMsg
//                         ^@variable.member
//                                  ^@variable
//                                          ^ @variable.member
//                                                         ^ @variable.member

So regarding the row part, I definitely think it's the right highlight. For column and shortMsg I also like it, but we could also make them variable . (That's what the javascript highlights do.) But again, I like OCaml's approach.

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.

None yet

2 participants