[PATCH] D41537: Optionally add code completion results for arrow instead of dot

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 22 02:58:24 PDT 2018


ilya-biryukov added inline comments.


================
Comment at: lib/Sema/SemaCodeComplete.cpp:4109
+  if (CodeCompleter->includeFixIts()) {
+    const SourceRange OpRange(OpLoc, OpLoc.getLocWithOffset(IsArrow ? 2 : 1));
+    CompletionSucceded =
----------------
yvvan wrote:
> ilya-biryukov wrote:
> > I'd use token ranges here to avoid assumptions about sizes of tokens, e.g. `CreateReplacemen(CharSourceRange::getTokenRange(OpLoc, OpLoc), IsArrow ? '.' : '->')`
> > There are complicated cases like `\` that end of the line and macros and it's definitely better to use an abstraction that hides those cases.
> the problem is that I need the range, not just a location.... and I don't know how to extract it here. is there a way to get next token location here?
IIUC, using `CharSourceRange::getTokenRange(OpLoc, OpLoc)` will do what you want.
When `CharSourceRange` is a token range, the client code should measurements the token length and the producing code would use the starting location of the last token.
Here are the relevant bits from the comment of the `CharSourceRange`:
```
/// In the token range case, the
/// size of the last token must be measured to determine the actual end of the
/// range.
 ```


https://reviews.llvm.org/D41537





More information about the cfe-commits mailing list