[PATCH] D53406: [clangd] Provide excuses for bad code completions, based on diagnostics. C++ API only.
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 19 14:42:02 PDT 2018
ilya-biryukov added a comment.
Since we're showing the diagnostics in the editors anyway, how crucial do we think it is to actually add that to the procotol?
Having more concrete reasons for misbehaving completions sounds more useful, though, e.g. "cannot complete members of the incomplete type", etc.
Totally fine to have this in the C++ API for experiments, of course.
> - LSP provides no protocol mechanims, and editors don't have UI for this
Have we tried returning an error in addition to the results? How do the clients behave in that case?
================
Comment at: clangd/CodeComplete.cpp:674
+// Tries to come up with a convincing excuse for our bad completion results,
+// based on the diagnostics near the completion point.
----------------
It took some time to figure out what "excuse" means here.
Maybe be more straightforward in naming/comments about what this class does? I.e. finds a last diagnostic on the same line.
It's private to this file, so it's easy to rename if we'll want to expand the heuristics.
================
Comment at: clangd/CodeComplete.cpp:686
+ for (StartOfLine = Offset;
+ StartOfLine > 0 && Code[StartOfLine - 1] != '\n'; --StartOfLine)
+ ;
----------------
Maybe use a getLineNumber helper from the SourceManager instead?
It needs a FileID, but it shouldn't be hard to get one.
================
Comment at: clangd/CodeComplete.cpp:1040
+ IncludeStructure *Includes = nullptr,
+ std::string *Excuse = nullptr) {
trace::Span Tracer("Sema completion");
----------------
Maybe replace an out parameter with returning a struct of two members?
Is there any use for calling code completion without providing an "excuse"?
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D53406
More information about the cfe-commits
mailing list