-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clangd] Support symbolTags for document symbol #113669
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
65ad54d
to
02124e4
Compare
You can test this locally with the following command:git-clang-format --diff 2e43a304f10fd801f068d0f9831f01f2c5b0b2e2 2d8224260143899f9af9a99465318da05d04722f --extensions cpp,h -- clang-tools-extra/clangd/AST.cpp clang-tools-extra/clangd/AST.h clang-tools-extra/clangd/FindSymbols.cpp clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h clang-tools-extra/clangd/SemanticHighlighting.cpp View the diff from clang-format here.diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index fb43439695..7bbae42b2a 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -1090,13 +1090,13 @@ struct CodeAction {
};
llvm::json::Value toJSON(const CodeAction &);
-enum class SymbolTag {
+enum class SymbolTag {
Deprecated = 1,
Private = 2,
Package = 3,
Protected = 4,
Public = 5,
- Internal= 6,
+ Internal = 6,
File = 7,
Static = 8,
Abstract = 9,
@@ -1584,7 +1584,6 @@ struct ResolveTypeHierarchyItemParams {
bool fromJSON(const llvm::json::Value &, ResolveTypeHierarchyItemParams &,
llvm::json::Path);
-
/// The parameter of a `textDocument/prepareCallHierarchy` request.
struct CallHierarchyPrepareParams : public TextDocumentPositionParams {};
|
Hi @chouzz, Thank you very much for your PR draft. I checked your changes and have a few questions. Does the method Having tags Constant and Read-only might be confusing. Maybe we should consider removing the Constant tag from LSP and only use Read-only. What do you think? Especially for C++ code, it would be great if the tags declaration and definition would also be set. I'm sure, clangd has these details already, since it uses these modifiers e.g. for syntax highlighting. Do you think, you could also set the declaration and definition tags? |
It's extracted from
I agree. Also, I checked
OK, I will check how to add this. |
I thought about the Constant tag. In Java for example, there is no Do you agree? Then I'd adapt my PR on the LSP project accordingly. |
I have no objections to this. |
Thank you @chouzz for adding Declaration and Definition tags. I'm sorry for answering late. I was quite busy last days. Could we please also replace the Const tag with the Read-only tag? (I'm planning to remove the Const tag from my PR on the LSP spec). What about an Abstract tag? Is there some clangd code that could be re-used for that? Oh, sorry, it's already covered here. |
@travkin79 I replaced |
Thank you @chouzz, |
Hi @chouzz, It seems, there is one failing test in the CI pipeline. Could you try fixing it?
|
Hi, @travkin79 that sounds great. I tried to build clangd from my github action, but I failed, maybe @HighCommander4 could help point out how to build clangd via github actions with specify branch?
I will check. |
What is it that you're trying to do? The purpose of clangd's Are you trying to publish something to https://github.com/chouzz/clangd/releases? Or just avoid building clangd / running tests locally? |
@HighCommander4 Just try to avoid building clangd locally. |
Hi @chouzz,
I built your branch of llvm / clangd locally. I did the following on a linux machine
I must admit, it takes some time to clone and especially to build the project. |
@travkin79 |
Hi @chouzz, At the moment, what I get for your example is the following response ( {
"id": "103",
"jsonrpc": "2.0",
"result": [
{
"detail": "const int",
"kind": 13,
"name": "g_var",
"range": {
"end": {
"character": 19,
"line": 0
},
"start": {
"character": 0,
"line": 0
}
},
"selectionRange": {
"end": {
"character": 15,
"line": 0
},
"start": {
"character": 10,
"line": 0
}
}
},
{
"children": [
{
"detail": "void ()",
"kind": 6,
"name": "pub",
"range": {
"end": {
"character": 14,
"line": 3
},
"start": {
"character": 4,
"line": 3
}
},
"selectionRange": {
"end": {
"character": 12,
"line": 3
},
"start": {
"character": 9,
"line": 3
}
}
},
{
"detail": "void ()",
"kind": 6,
"name": "pri",
"range": {
"end": {
"character": 14,
"line": 5
},
"start": {
"character": 4,
"line": 5
}
},
"selectionRange": {
"end": {
"character": 12,
"line": 5
},
"start": {
"character": 9,
"line": 5
}
}
},
{
"detail": "void ()",
"kind": 6,
"name": "pro",
"range": {
"end": {
"character": 14,
"line": 7
},
"start": {
"character": 4,
"line": 7
}
},
"selectionRange": {
"end": {
"character": 12,
"line": 7
},
"start": {
"character": 9,
"line": 7
}
}
}
],
"detail": "class",
"kind": 5,
"name": "P",
"range": {
"end": {
"character": 1,
"line": 8
},
"start": {
"character": 0,
"line": 1
}
},
"selectionRange": {
"end": {
"character": 7,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
]
} |
Hi @chouzz, Methods
Types @HighCommander4, |
@travkin79
And I am going to update the branch to remove
Currently, the implementation should only work in DocumentSymbol(outline). BTW, I tested in vscode, I am not sure why it also in |
Hi @chouzz, Your newest commit 0f6d25b only removes the Constant tag. Thus, It would only change the numbers returned as tags. I'll check if I can provide a verbose LS log output. Concerning |
Hi @chouzz, I checked my config. It turns out there was some config file replacing the default clangd path with another one. Fixing that results in the expected behavior. Now, I can create an outline view like the following for your code snippet. |
Hi @chouzz,
Example: demo.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
{
}
}; LS output: {
"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
]
}
]
} |
Hi @chouzz, |
This patch:
isConst, isStatic, isAbstract, isVirtual
fromSemanticHighlighting.cpp
toAST.h/cpp
to reuse it inFindSymbols.cpp
Fixes: clangd/clangd#2123