[all-commits] [llvm/llvm-project] 7d68f2: [clangd] Desugar template parameter aliases in typ...
zyn0217 via All-commits
all-commits at lists.llvm.org
Tue Jun 13 04:15:44 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7d68f2ef411ea2188666c2f67a8ee8b923adb12d
https://github.com/llvm/llvm-project/commit/7d68f2ef411ea2188666c2f67a8ee8b923adb12d
Author: Younan Zhang <zyn7109 at gmail.com>
Date: 2023-06-13 (Tue, 13 Jun 2023)
Changed paths:
M clang-tools-extra/clangd/InlayHints.cpp
M clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Log Message:
-----------
[clangd] Desugar template parameter aliases in type hints
This patch alleviates https://github.com/clangd/clangd/issues/1298.
Containers in C++ such as `std::vector` or `llvm::SmallVector`,
introduce a series of type aliases to adapt to generic algorithms.
Currently, If we write an declarator involving expressions with
these containers and `auto` placeholder, we probably obtain opaque
type alias like following:
```
std::vector<int> v = {1, 2, 3};
auto value = v[1]; // hint for `value`: value_type
auto *ptr = &v[0]; // hint for `ptr`: value_type *
```
These hints are useless for most of the time. It would be nice if we
desugar the type of `value_type` and print `int`, `int *` respectively
in this situation. But note we can't always prefer desugared type
since user might introduce type-aliases for brevity, where printing
sugared types makes more sense.
This patch introduces a heuristic method that displays the desugared
type that is an alias of template parameter. It merges
analogous method `shouldPrintCanonicalType` into `maybeDesugar` as well.
Previous commit for shouldPrintCanonicalType: dde8a0fe91cc
Reviewed By: nridge
Differential Revision: https://reviews.llvm.org/D151785
More information about the All-commits
mailing list