florianhumblot created this revision. florianhumblot added a project: clang-tools-extra. Herald added subscribers: kadircet, arphaman. Herald added a project: All. florianhumblot requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
When using clangd as a language server in an editor such as vscode, it is currently hard to use the `List Document Symbols` feature with files where a function is overloaded many times. Other language servers (such as the one provided by Microsoft) return more than just the symbol's name for the view, namely it also returns the parameters of the (member) functions in the file. i.e. clang's current view: F28575822: image.png <https://reviews.llvm.org/F28575822> versus Microsoft's current view: F28575823: image.png <https://reviews.llvm.org/F28575823> This patch adds the parameter information to symbol listings of free functions and member functions, resulting in the following symbol navigation view: F28575826: image.png <https://reviews.llvm.org/F28575826> This patch has been tested with vscode V1.80.2 and the vscode clangd extension version v0.1.24 No additional changes were necessary to either clang(d) or the vscode extension for the fix to work (other than specifying the custom clangd executable) Resolves https://github.com/clangd/clangd/issues/1344 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157080 Files: clang-tools-extra/clangd/Protocol.cpp Index: clang-tools-extra/clangd/Protocol.cpp =================================================================== --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -895,8 +895,16 @@ {"range", S.range}, {"selectionRange", S.selectionRange}}; - if (!S.detail.empty()) + if (!S.detail.empty()) { + if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) { + llvm::StringRef Detail{S.detail}; + const auto Start = Detail.find_first_of('('); + const auto End = Detail.find_last_of(')'); + const auto Distance = End - Start; + Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')'; + } Result["detail"] = S.detail; + } if (!S.children.empty()) Result["children"] = S.children; if (S.deprecated)
Index: clang-tools-extra/clangd/Protocol.cpp =================================================================== --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -895,8 +895,16 @@ {"range", S.range}, {"selectionRange", S.selectionRange}}; - if (!S.detail.empty()) + if (!S.detail.empty()) { + if (S.kind == SymbolKind::Method || S.kind == SymbolKind::Function) { + llvm::StringRef Detail{S.detail}; + const auto Start = Detail.find_first_of('('); + const auto End = Detail.find_last_of(')'); + const auto Distance = End - Start; + Result["name"] = S.name + Detail.substr(Start, Distance).str() + ')'; + } Result["detail"] = S.detail; + } if (!S.children.empty()) Result["children"] = S.children; if (S.deprecated)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits