[PATCH] D147395: [Clangd] Make the type hint length limit configurable
Yi Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 08:29:00 PDT 2023
zhangyi1357 updated this revision to Diff 510508.
zhangyi1357 added a comment.
Add uint32Value() for uint32_t type parsing in config file.
For TypeNameLimit config, support no limit with value 0.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147395/new/
https://reviews.llvm.org/D147395
Files:
clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/InlayHints.cpp
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
return;
std::string TypeName = T.getAsString(Policy);
- if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
+ if (Cfg.InlayHints.TypeNameLimit == 0 ||
+ TypeName.length() < Cfg.InlayHints.TypeNameLimit)
addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
}
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -255,7 +255,7 @@
F.Designators = *Value;
});
Dict.handle("TypeNameLimit", [&](Node &N) {
- if (auto Value = scalarValue(N, "TypeNameLimit"))
+ if (auto Value = uint32Value(N, "TypeNameLimit"))
F.TypeNameLimit = *Value;
});
Dict.parse(N);
@@ -379,6 +379,17 @@
return std::nullopt;
}
+ std::optional<Located<uint32_t>> uint32Value(Node &N, llvm::StringRef Desc) {
+ if (auto Scalar = scalarValue(N, Desc)) {
+ unsigned long long Num;
+ if (!llvm::getAsUnsignedInteger(**Scalar, 0, Num)) {
+ return Located<uint32_t>(Num, Scalar->Range);
+ }
+ }
+ warning(Desc + " invalid number", N);
+ return std::nullopt;
+ }
+
// Try to parse a list of single scalar values, or just a single value.
std::optional<std::vector<Located<std::string>>> scalarValues(Node &N) {
std::vector<Located<std::string>> Result;
Index: clang-tools-extra/clangd/ConfigFragment.h
===================================================================
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,8 +322,8 @@
std::optional<Located<bool>> DeducedTypes;
/// Show designators in aggregate initialization.
std::optional<Located<bool>> Designators;
- /// Limit the length of type name hints.
- std::optional<Located<std::string>> TypeNameLimit;
+ /// Limit the length of type name hints. (0 means no limit)
+ std::optional<Located<uint32_t>> TypeNameLimit;
};
InlayHintsBlock InlayHints;
};
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -614,7 +614,7 @@
if (F.TypeNameLimit)
Out.Apply.push_back(
[Value(**F.TypeNameLimit)](const Params &, Config &C) {
- C.InlayHints.TypeNameLimit = stoul(Value);
+ C.InlayHints.TypeNameLimit = Value;
});
}
Index: clang-tools-extra/clangd/Config.h
===================================================================
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,8 +147,8 @@
bool Parameters = true;
bool DeducedTypes = true;
bool Designators = true;
- // Limit the length of type names in inlay hints.
- size_t TypeNameLimit = 32;
+ // Limit the length of type names in inlay hints. (0 means no limit)
+ uint32_t TypeNameLimit = 32;
} InlayHints;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147395.510508.patch
Type: text/x-patch
Size: 3318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230403/10737d4f/attachment-0001.bin>
More information about the cfe-commits
mailing list