Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clangd] Desugar template parameter aliases in type hints
This patch alleviates clangd/clangd#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: dde8a0f Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D151785
- Loading branch information
Showing
2 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters