Visual-Studio-Code: describe new semantic highlight configurations

Fangrui Song 2019-10-15 00:16:40 -07:00
parent 5b301d0e9d
commit e7e01b0d97

@ -9,6 +9,9 @@ To load vscode-ccls without installing:
* `code vscode-ccls` * `code vscode-ccls`
* Press F5 * Press F5
* Open the project root with "Open Folder" (<kbd>C-k C-o</kbd>)
After changing some ccls configurations in `settings.json`, trigger the command `ccls: Restart language server` or reload the plugin to take effect.
## Setting up the extension ## Setting up the extension
@ -50,28 +53,57 @@ In case `compile_commands.json` is located not in default place ($root)
In this case it is located in `$root/build/compile_commands.json` In this case it is located in `$root/build/compile_commands.json`
### Semantic highlighting ### Semantic highlight
The Visual Studio Code ccls extension supports [semantic highlighting](https://medium.com/@evnbr/coding-in-color-3a6db2743a1e). To enable, put into settings.conf (or workspace configuration): <img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/vscode-ccls/highlight.webp" title="semantic highlight">
Add the following lines to `settings.json` to enable rainbow semantic highlight:
```json ```json
"ccls.highlighting.enabled.types": true, "ccls.highlight.function.face": ["enabled"],
"ccls.highlighting.enabled.freeStandingFunctions": true, "ccls.highlight.type.face": ["enabled"],
"ccls.highlighting.enabled.memberFunctions": true, "ccls.highlight.variable.face": ["enabled"],
"ccls.highlighting.enabled.freeStandingVariables": true,
"ccls.highlighting.enabled.memberVariables": true,
"ccls.highlighting.enabled.namespaces": true,
"ccls.highlighting.enabled.macros": true,
"ccls.highlighting.enabled.enums": true,
"ccls.highlighting.enabled.typeAliases": true,
"ccls.highlighting.enabled.enumConstants": true,
"ccls.highlighting.enabled.staticMemberFunctions": true,
"ccls.highlighting.enabled.parameters": true,
"ccls.highlighting.enabled.templateParameters": true,
"ccls.highlighting.enabled.staticMemberVariables": true,
"ccls.highlighting.enabled.globalVariables": true,
``` ```
<sub>Before vscode-ccls 0.1.28, settings like `"ccls.highlighting.enabled.types": true,` were used.</sub>
`ccls.highlight.{function,type,type}.face` define faces of basic symbol kinds
from which other symbol kinds (`{member,staticMember}{Function,Variable}`, etc)
can inherit. `package.json` defines some default faces:
```jsonc
// Predefined by package.json
"ccls.highlight.member": ["fontStyle: italic"],
"ccls.highlight.static": ["fontWeight: bold"],
"ccls.highlight.memberFunction.face": ["function", "member"]
"ccls.highlight.memberVariable.face": ["variable", "member"]
"ccls.highlight.staticMemberFunction.face": ["function", "static"]
"ccls.highlight.staticMemberVariable.face": ["variable", "static"]
```
For a symbol kind, its face property takes effect if `"enabled"` is specified either directly or indirectly. The face describes:
* Styles such as `"fontStyle: italic"`, `"fontWeight: bolder"`, and `"textDecoration: underline"`.
They are based on CSS properties with similar names. See MDN documents about [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight) and [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration).
* Colors. By default, `package.json` predefines some palettes. `ccls.highlight.memberFunction.colors` is not defined but it can inherit from `ccls.highlight.function.colors` because `ccls.highlight.memberFunction.face` inherits from `ccls.highlight.function.face`.
```jsonc
// Predefined by package.json
"ccls.highlight.function.colors": ["#e5b124", "#927754", "#eb992c", "#e2bf8f", "#d67c17", "#88651e", "#e4b953", "#a36526", "#b28927", "#d69855"],
"ccls.highlight.type.colors": ["#e1afc3", "#d533bb", "#9b677f", "#e350b6", "#a04360", "#dd82bc", "#de3864", "#ad3f87", "#dd7a90", "#e0438a"],
"ccls.highlight.variable.colors": ["#587d87", "#26cdca", "#397797", "#57c2cc", "#306b72", "#6cbcdf", "#368896", "#3ea0d2", "#48a5af", "#7ca6b7"],
"ccls.highlight.macro.colors": ["#e79528", "#c5373d", "#e8a272", "#d84f2b", "#a67245", "#e27a33", "#9b4a31", "#b66a1e", "#e27a71", "#cf6d49"],
"ccls.highlight.namespace.colors": ["#429921", "#58c1a4", "#5ec648", "#36815b", "#83c65d", "#417b2f", "#43cc71", "#7eb769", "#58bf89", "#3e9f4a"],
```
The colors will be randomly assigned to symbols. Change these properties to 1-element arrays to make colors fixed.
The list of available symbol kinds: `function, variable, type, enum, globalVariable, macro, memberFunction, memberVariable, namespace, parameter, staticMemberFunction, staticVariable, typeAlias`.
`globalVariable` works with latest ccls but not the 0.20190823.3 release.
### Cross references ### Cross references
You could set custom lookup using keybindings. Use command palette (`ctrl + shift + p` by default) -> `Open keyboard shortcuts file` You could set custom lookup using keybindings. Use command palette (`ctrl + shift + p` by default) -> `Open keyboard shortcuts file`
@ -93,7 +125,7 @@ You could set custom lookup using keybindings. Use command palette (`ctrl + shif
{"key":"<your-shortcuts>","command":"ccls.member","args":{"kind":3}} {"key":"<your-shortcuts>","command":"ccls.member","args":{"kind":3}}
``` ```
For VSCodeVim users, here's how to set arguments in User Settings (`settings.json`) For VSCodeVim users, heres how to set arguments in User Settings (`settings.json`)
```json ```json
"vim.normalModeKeyBindingsNonRecursive": [ "vim.normalModeKeyBindingsNonRecursive": [
{ {
@ -106,7 +138,7 @@ So you could hit `<space>-t` to see callees up to 3rd level if you set `<leader>
### Using vscode-ccls along side vscode-cpptools extension for debugger support ### Using vscode-ccls along side vscode-cpptools extension for debugger support
The `vscode-ccls` extension doesn't provide any debugger integration. One popular option is to use the [vscode-cpptools](https://github.com/Microsoft/vscode-cpptools) extension for this aspect. By default however, `vscode-cpptools` provides editor features that overlap with ccls, which yields duplicate results in things like autocomplete. The following settings may be applied to disable the editor support of `vscode-cpptools` to prevent this from happening, while still retaining the debugger features. The `vscode-ccls` extension doesnt provide any debugger integration. One popular option is to use the [vscode-cpptools](https://github.com/Microsoft/vscode-cpptools) extension for this aspect. By default however, `vscode-cpptools` provides editor features that overlap with ccls, which yields duplicate results in things like autocomplete. The following settings may be applied to disable the editor support of `vscode-cpptools` to prevent this from happening, while still retaining the debugger features.
```json ```json
"C_Cpp.autocomplete": "Disabled", "C_Cpp.autocomplete": "Disabled",