Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa.
Details
- Reviewers
ilya-biryukov - Commits
- rG2f84d911317b: Added functionality to suggest FixIts for conversion of '->' to '.' and vice…
rL339224: Added functionality to suggest FixIts for conversion of '->' to '.' and vice…
rCTE339224: Added functionality to suggest FixIts for conversion of '->' to '.' and vice…
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
Thanks for the change! Overall LG, mostly NITs about the tests.
clangd/CodeComplete.cpp | ||
---|---|---|
957 | NIT: this change is unrelated, maybe remove from the diff? We can submit it separately without review, since it's a noop formatting cleanup | |
1099–1100 | Same here: maybe remove from this change and submit separately? | |
1289 | IIUC, it does not play nicely with the insertText in VSCode, right? (I.e. completing this.^ will produce this-push_back) | |
unittests/clangd/CodeCompleteTests.cpp | ||
497 | NIT: also submit as a separate change? | |
1374 | Maybe remove the body of opeartor->() and the private field? | |
1378 | Maybe remove namespace and put everything into global ns? | |
1381 | Maybe tests without the prefix, so that both AuxFunction and MemberFunction are available and assert that AuxFunction does not have a fix-it? | |
1389 | This can be made more readable with helpers from unittests/clangd/Annotations.h. Annotations Source(R"cpp( /// .... void f() { ClassWithPtr x; x[[->]]MemberFunction^ })cpp"); Source.point(); // <-- completion point Source.range(); // <-- range for the fix-it Our completions helper already has parsing of annotations internally, though. But we can write a new overload for the helper that accepts completion point and the parsed text directly. |
clangd/CodeComplete.cpp | ||
---|---|---|
286 | IIRC LangOptions are actually important when running lexer (that is used internally to measure the length of the tokens). | |
clangd/SourceCode.cpp | ||
11 | NIT: no need for this include in .cpp file, since the header already has that. | |
clangd/SourceCode.h | ||
16 | NIT: #include "clang/Basic/Diagnostic.h" should be enough here | |
unittests/clangd/CodeCompleteTests.cpp | ||
99 | Maybe accept a stringref to source code and completion point directly? |
Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa.
- Fixes for comments.
- Take unnecessary patches back
- Second pass for comments.
- Add downranking for scores of fixit elements.
Thanks! The only major comment I have is about the FixItsScore, others are mostly NITs.
clangd/Quality.cpp | ||
---|---|---|
298 | NIT: remove braces around single-statement loop body | |
clangd/Quality.h | ||
80 | The comment is a bit misleading, since it's actually the length of the inserted code. int FixItScore; // Measure of the total amount of edit needed by the fix-its. Higher is worse, i.e. more code needs to change And overall, it looks like the penalty might be too harsh for some potential fix-its. E.g. imagine a fix-it that adds a using ns::some_class directive somewhere to the file. The size of the inserted text will be proprotional to the size of the fully-qualfiied-name of the class, but it does not seem like the fix-its for items with larger names should be downranked more than others, after all it's the same type of fix-it. // Hypothetical example, we don't have fix-its like that yet. namespace ns { class SomeVeryLongName {}; class ShortName {}; } ^ // <-- complete here, imagine the completion items for both classes are available and // add `using ns::<ClassName>;` to the global namespace. In that case, we will penalize SomeVeryLongName more than ShortName, because it has a longer fix-it, but it does not look like a useful distinction. | |
unittests/clangd/CodeCompleteTests.cpp | ||
130 | NIT: use const Annotations&? | |
137 | The number of completions overloads seems to be getting out of hand. Generally, I think we want the most general version: CodeCompleteResult completionsImpl(ClangdServer&, Text, Point, Index, Opts) And two conveniece wrappers that create ClangdServer for us: // Parses Annotations(Text) and creates a ClangdServer instance. CodeCompleteResult completions(Text, Index = ..., Opts = ...); // Only creates a ClangdServer instance. CodeCompleteResult completions(Text, Point, Index=..., Opts =...); Can we make the rest of the code to use this API? (e.g. if function accepts a ClangdServer, the callers have to do quite a bit of setup anyway and I don't think adding the annotations parsing to get the completion point will hurt the readability there). | |
1390 | NIT: remove braces around single-statement ifs, LLVM code generally tends to avoid adding braces around single-statement bodies of loops, conditionals, etc | |
1432 | We tend to unit-test the scores separately from general completion tests. |
LGTM, with a few NITs.
Thanks for the change!
clangd/Quality.h | ||
---|---|---|
81 | NIT: put the comment at the previous line to keep false at the same line. | |
unittests/clangd/CodeCompleteTests.cpp | ||
99 | It seems this comment got moved accidentally, move it back? | |
unittests/clangd/QualityTests.cpp | ||
360 | NIT: took me some time to figure out the difference between this and the next one. |
IIRC LangOptions are actually important when running lexer (that is used internally to measure the length of the tokens).
Use ASTCtx.getLangOptions()?