microsoft / RTVS

R Tools for Visual Studio.
MIT License
390 stars 118 forks source link

[Feature Request] Syntax highlighting for functions and operators #4271

Closed mhmdmodan closed 6 years ago

mhmdmodan commented 6 years ago

RStudio has an optional feature to enable highlighting for functons, which offers a great increase in readability. Additionally, separate highlighting for operators, including custom binary operators (like the pipe %>%) would be quite helpful as well!

Here's a bit of code in RStudio:

image

And the same with RTVS:

image

Hopefully this can be implemented in future updates. Thank you!

MikhailArkhipov commented 6 years ago

VS has operator colors :-) It is just default is black.

image

Function colors somewhat more difficult since it technically requires semantic analysis. However, simple approach would be to color anything that has following ( (except keywords) as functions.

mhmdmodan commented 6 years ago

Ah! Thank you, didn't see that in the settings. I'm new to VS :)

As for the function call highlighting, looks like that's what RStudio does too.

image

MikhailArkhipov commented 6 years ago

Not too complicated, but fairly extensive change. Classifier currently gets a single token while it needs to get token collection and the current token index so it can determine if this is a function. Unfortunately, connection operations currently return elements and not indices. Also, tokenizer needs to run past the changed range since it needs to pick up the brace while it might be off-screen. Example

func|( <<- edge of the screen

VS request for colors in the range would not include '(` since it is off screen. Tokenizer needs to picks few items beyond .the visual range then

MikhailArkhipov commented 6 years ago

@mhmdmodan - which RStudio scheme it is? In the schemes I have I don't see option for function colors.

image

mhmdmodan commented 6 years ago

@MikhailArkhipov - Hi, it must be enabled in the Code menu under the Display tab first.

image

MikhailArkhipov commented 6 years ago

https://github.com/Microsoft/RTVS/commit/e83ab28203c1380dae8dbb739174cbc7efa70882

The color name is R Function. Default is black.