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

Differentiate syntax between function definitions and function calls #40

Merged
merged 1 commit into from
Feb 19, 2020
Merged

Differentiate syntax between function definitions and function calls #40

merged 1 commit into from
Feb 19, 2020

Conversation

axelson
Copy link
Member

@axelson axelson commented Feb 18, 2020

Goals:

  • By default in most themes, function calls should not be highlighted the same
    as function calls
    • Most syntaxes only define function definitions, so most themes highlight
      those definitions with a rather bold color, applying the same coloring to
      all functions calls results in visual noise
  • It should still be possible to define custom highlighting for function calls

State of syntax highlighting:

  • Textmate syntax highlighting standard (as defined by [1]) defines function
    definitions (entity.name.function) but says nothing about function calls
  • Most themes do not support special coloring for function calls
  • We can't expect most themes to add special Elixir support

This PR combines portions of #30 and #38 that have similar goals.

PR #30 by itself did not fully accomplish my goals because function calls are
still annotated with entity.name.function.elixir which is highlighted as a
function definition

PR #38 changed the function call names, but it changed it to a non-standard scope.

So in this PR we change the entity.name.function.elixir to
entity.name.function-call.elixir which allows customization, but is a scope
that that does not have default coloring in most themes (while still being
semantically similar).

Also Ruby's syntax uses the similar entity.name.function-call.ruby:
https://github.com/rubyide/vscode-ruby/blob/b232cfd0c96f41ceab72655dcfa17dab40c05562/packages/vscode-ruby/syntaxes/ruby.cson.json#L2243

Related comment: elixir-editors/elixir-tmbundle#179 (comment)

cc: @thiagomajesk, @CaiqueMitsuoka, @chrismccord

[1] https://macromates.com/manual/en/language_grammars

Goals:
* By default in most themes, function calls should not be highlighted the same
  as function calls
  * Most syntaxes only define function definitions, so most themes highlight
    those definitions with a rather bold color, applying the same coloring to
    all functions calls results in visual noise
* It should still be possible to define custom highlighting for function calls

State of syntax highlighting:
* Textmate syntax highlighting standard (as defined by [1]) defines function
definitions (`entity.name.function`) but says nothing about function calls
* Most themes do not support special coloring for function calls
* We can't expect most themes to add special Elixir support

This PR combines portions of #30 and #38 that have similar goals.

PR #30 by itself did not fully accomplish my goals because function calls are
still annotated with `entity.name.function.elixir` which is highlighted as a
function definition

PR #38 changed the function call names, but it changed it to a non-standard scope.

So in this PR we change the `entity.name.function.elixir` to
`entity.name.function-call.elixir` which allows customization, but is a scope
that that does not have default coloring in most themes (while still being
semantically similar).

Also Ruby's syntax uses the similar `entity.name.function-call.ruby`:
https://github.com/rubyide/vscode-ruby/blob/b232cfd0c96f41ceab72655dcfa17dab40c05562/packages/vscode-ruby/syntaxes/ruby.cson.json#L2243

[1] https://macromates.com/manual/en/language_grammars
@chrismccord
Copy link

beautiful. Thank you!

@thiagomajesk
Copy link

Nice one @axelson!
Will this also cover the scenario highlighted here: #22 (comment)?

@axelson axelson changed the title Differentiate between function definitions and function calls Differentiate syntax between function definitions and function calls Feb 19, 2020
@axelson
Copy link
Member Author

axelson commented Feb 19, 2020

Nice one @axelson!
Will this also cover the scenario highlighted here: #22 (comment)?

Thanks! Since this doesn't add any new rules, code like say_hello "Caique" will still just be tagged with the scope source.elixir. Ideally we could detect that as a function call, but I'm not sure how difficult that would be (and if it would require any tradeoffs), in any case that would be handled in a separate PR.

@axelson axelson merged commit 3fb4dbf into elixir-lsp:master Feb 19, 2020
@axelson axelson deleted the elixir-syntax branch February 19, 2020 18:13
@thiagomajesk
Copy link

@axelson Indeed!
Do you also think it's necessary to split the original issue to keep up this conversation separately? There are at least a couple more cases in the mix.

@axelson
Copy link
Member Author

axelson commented Feb 20, 2020

Do you also think it's necessary to split the original issue to keep up this conversation separately? There are at least a couple more cases in the mix.

Yeah I think that #22 is too broad, so I'll close it, but please open up individual syntax/grammar improvement issues (or PR's).

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

3 participants