[clang-tools-extra] [clangd] Support symbolTags for document symbol (PR #113669)

Dietrich Travkin via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 04:46:56 PST 2024


travkin79 wrote:

Hi @chouzz,
I extended my prototype to create overlay icons for all Symbol Tags. I'm using another C++ code example for testing clangd's tags and my visualization. The results are promising, but I have a few questions.

* Could you please check if you can also set `Final` tags? It seems, clangd doesn't set these yet (see example).
* Is it correct that `virtual ~AbstractClass() = default;` is tagged as definition and not as declaration?

**Example: demo.cpp**
```cpp
class AbstractClass // abstract
{
public:

  virtual ~AbstractClass() = default; // public, virtual, declaration

  virtual void f1() = 0; // public, (pure) virtual, declaration

  void f2() const; // public, const, declaration

protected:

  void f3() // protected, (declaration+)definition
  {
  }

private:

  static void f4() // private, static, (declaration+)definition
  {
  }
};

void AbstractClass::f2() const // public, const, definition
{
}

class ImplClass : public AbstractClass
{
public:

  void f1() final // public, override, final, (declaration+)definition
  {
  }
};
```

**Outline prototype:**
![image](https://github.com/user-attachments/assets/94a43fb8-ce52-40d1-b97f-cbb32d28a855)

**LS output:**
```json
{
  "id": "7",
  "jsonrpc": "2.0",
  "result": [
    {
      "children": [
        {
          "kind": 9,
          "name": "~AbstractClass",
          "range": {
            "end": {
              "character": 36,
              "line": 4
            },
            "start": {
              "character": 2,
              "line": 4
            }
          },
          "selectionRange": {
            "end": {
              "character": 11,
              "line": 4
            },
            "start": {
              "character": 10,
              "line": 4
            }
          },
          "tags": [
            15,
            19,
            5
          ]
        },
        {
          "detail": "void ()",
          "kind": 6,
          "name": "f1",
          "range": {
            "end": {
              "character": 23,
              "line": 6
            },
            "start": {
              "character": 2,
              "line": 6
            }
          },
          "selectionRange": {
            "end": {
              "character": 17,
              "line": 6
            },
            "start": {
              "character": 15,
              "line": 6
            }
          },
          "tags": [
            15,
            9,
            18,
            5
          ]
        },
        {
          "detail": "void () const",
          "kind": 6,
          "name": "f2",
          "range": {
            "end": {
              "character": 17,
              "line": 8
            },
            "start": {
              "character": 2,
              "line": 8
            }
          },
          "selectionRange": {
            "end": {
              "character": 9,
              "line": 8
            },
            "start": {
              "character": 7,
              "line": 8
            }
          },
          "tags": [
            20,
            18,
            5
          ]
        },
        {
          "detail": "void ()",
          "kind": 6,
          "name": "f3",
          "range": {
            "end": {
              "character": 3,
              "line": 14
            },
            "start": {
              "character": 2,
              "line": 12
            }
          },
          "selectionRange": {
            "end": {
              "character": 9,
              "line": 12
            },
            "start": {
              "character": 7,
              "line": 12
            }
          },
          "tags": [
            19,
            4
          ]
        },
        {
          "detail": "void ()",
          "kind": 6,
          "name": "f4",
          "range": {
            "end": {
              "character": 3,
              "line": 20
            },
            "start": {
              "character": 2,
              "line": 18
            }
          },
          "selectionRange": {
            "end": {
              "character": 16,
              "line": 18
            },
            "start": {
              "character": 14,
              "line": 18
            }
          },
          "tags": [
            8,
            19,
            2
          ]
        }
      ],
      "detail": "class",
      "kind": 5,
      "name": "AbstractClass",
      "range": {
        "end": {
          "character": 1,
          "line": 21
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "selectionRange": {
        "end": {
          "character": 19,
          "line": 0
        },
        "start": {
          "character": 6,
          "line": 0
        }
      },
      "tags": [
        9,
        19
      ]
    },
    {
      "detail": "void () const",
      "kind": 6,
      "name": "AbstractClass::f2",
      "range": {
        "end": {
          "character": 1,
          "line": 25
        },
        "start": {
          "character": 0,
          "line": 23
        }
      },
      "selectionRange": {
        "end": {
          "character": 22,
          "line": 23
        },
        "start": {
          "character": 20,
          "line": 23
        }
      },
      "tags": [
        20,
        19,
        5
      ]
    },
    {
      "children": [
        {
          "detail": "void ()",
          "kind": 6,
          "name": "f1",
          "range": {
            "end": {
              "character": 3,
              "line": 33
            },
            "start": {
              "character": 2,
              "line": 31
            }
          },
          "selectionRange": {
            "end": {
              "character": 9,
              "line": 31
            },
            "start": {
              "character": 7,
              "line": 31
            }
          },
          "tags": [
            15,
            19,
            5
          ]
        }
      ],
      "detail": "class",
      "kind": 5,
      "name": "ImplClass",
      "range": {
        "end": {
          "character": 1,
          "line": 34
        },
        "start": {
          "character": 0,
          "line": 27
        }
      },
      "selectionRange": {
        "end": {
          "character": 15,
          "line": 27
        },
        "start": {
          "character": 6,
          "line": 27
        }
      },
      "tags": [
        19
      ]
    }
  ]
}
```

https://github.com/llvm/llvm-project/pull/113669


More information about the cfe-commits mailing list