2 LSP Extensions
rhcher edited this page 2021-12-18 19:03:57 +08:00

Cross reference extensions

Aside from definitions/references/workspace symbol, ccls provides some LSP extensions that find base/derived classes/methods, vars of a type, callers of a function.

$ccls/vars

It can be seen as a specialized textDocument/references. It finds all variables when the cursor is at a type of a variable (the type of the variable will be used). Whether local variables/parameters/struct members are returned can be specified with kind.

  • params: TextDocumentPositionParams extended with kind
  • return: Location[]

$ccls/call

Find callers (callee: false, default) or callees (callee: true) when the cursor is at a function.

The method returns either a flattened Location[], or a hierarchical type.

hierarchy: false (default)

  • params: TextDocumentPositionParams extended with callee, callType
  • return: Location[]

hierarchy: true

  • initial params: TextDocumentPositionParams extended with callee, callType. The result includes id and kind which are used to expand a node.
  • params: id, kind, callee, callType

Optional levels and qualified can be used to customize the hierarchy.

$ccls/inheritance

Find base classes (derived: false, default) or derived classes (derived: true).

It can also used to jump between the primary template and partial specializations.

hierarchy: false (default)

  • params: TextDocumentPositionParams extended with derived
  • return: Location[]

hierarchy: true

  • initial params: TextDocumentPositionParams extended with derived. The result includes id and kind which are used to expand a node.
  • params: id, kind, derived

Optional levels and qualified can be used to customize the hierarchy.

ccls/member

Find member variables/functions/types when the cursor is at a class/struct/union or a variable (the type of which will be used). Find local variables when the cursor is at a function.

  • kind: 4 (default), member variables are returned.
  • kind: 3, member functions are returned.
  • kind: 2, member types are returned.

hierarchy: false (default)

  • params: TextDocumentPositionParams extended with derived
  • return: Location[]

hierarchy: true

  • initial params: TextDocumentPositionParams extended with derived. The result includes id and kind which are used to expand a node.
  • params: id, kind, derived

Returned nodes can be furthe expanded if kind: 4.

Optional levels and qualified can be used to customize the hierarchy.

$ccls/navigate

Semantic movement among declarations.

  • params: TextDocumentPositionParams extended with direction. The allowed values of direction:
    • "U": parent
    • "D": first child
    • "L": left sibling
    • "R": right sibling
  • return: Location[]