'Syntax highlighting in Vscode for type hints
I am using the Dark++ theme but personalising a lot of colours. Everything works fine but one small thing: only the basic types are properly highlighted. For example this
"editor.tokenColorCustomizations": {
"comments": "#707070",
"keywords": "#adc5ee",
"types": "#bbbbbb",
"strings": "#bdceb7"
}
gives me the following picture:
I would like the type hints in the function declaration to be grey+italic, as it happens correctly for the type "str". I understand it is not straightforward for npt.NDArray as that comes from the typing module, but why is this not working even for "list" and "dict"? And do you know of a workaround I could use? There are not special tokens for these types as far as I know, so no way to access them other than just customising the general token "types". I tried using regex expressions with the "Highlight" extension but that is not optimal, because I also want to keep the functionality that if I comment out part of that text, it should be greyed-out (using "Highlight" it doesn't).
Solution 1:[1]
To close this topic and for future reference, this is how I solved my issue: I ended up using semantic highlighting for type hints as rioV8 suggested.
This is done by adding the following to my Vscode settings JSON file:
"editor.semanticTokenColorCustomizations": {
"rules": {
"*.typeHint": {
"foreground": "#bbbbbb",
"fontStyle": "italic"
},
"class.typeHint.builtin": {
"foreground": "#bbbbbb",
"fontStyle": "italic"
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | etien |