Author: ibiryukov Date: Wed Apr 25 08:13:34 2018 New Revision: 330833 URL: http://llvm.org/viewvc/llvm-project?rev=330833&view=rev Log: [CodeComplete] Fix completion in the middle of ident in ctor lists.
Summary: The example that was broken before (^ designates completion points): class Foo { Foo() : fie^ld^() {} // no completions were provided here. int field; }; To fix it we don't cut off lexing after an identifier followed by code completion token is lexed. Instead we skip the rest of identifier and continue lexing. This is consistent with behavior of completion when completion token is right before the identifier. Reviewers: sammccall, aaron.ballman, bkramer, sepavloff, arphaman, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D44932 Added: cfe/trunk/test/CodeCompletion/end-of-file.cpp Modified: cfe/trunk/lib/Lex/Lexer.cpp cfe/trunk/test/CodeCompletion/ctor-initializer.cpp Modified: cfe/trunk/lib/Lex/Lexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=330833&r1=330832&r2=330833&view=diff ============================================================================== --- cfe/trunk/lib/Lex/Lexer.cpp (original) +++ cfe/trunk/lib/Lex/Lexer.cpp Wed Apr 25 08:13:34 2018 @@ -1654,7 +1654,21 @@ FinishIdentifier: if (isCodeCompletionPoint(CurPtr)) { // Return the code-completion token. Result.setKind(tok::code_completion); - cutOffLexing(); + // Skip the code-completion char and all immediate identifier characters. + // This ensures we get consistent behavior when completing at any point in + // an identifier (i.e. at the start, in the middle, at the end). Note that + // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code + // simpler. + assert(*CurPtr == 0 && "Completion character must be 0"); + ++CurPtr; + // Note that code completion token is not added as a separate character + // when the completion point is at the end of the buffer. Therefore, we need + // to check if the buffer has ended. + if (CurPtr < BufferEnd) { + while (isIdentifierBody(*CurPtr)) + ++CurPtr; + } + BufferPtr = CurPtr; return true; } Modified: cfe/trunk/test/CodeCompletion/ctor-initializer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ctor-initializer.cpp?rev=330833&r1=330832&r2=330833&view=diff ============================================================================== --- cfe/trunk/test/CodeCompletion/ctor-initializer.cpp (original) +++ cfe/trunk/test/CodeCompletion/ctor-initializer.cpp Wed Apr 25 08:13:34 2018 @@ -58,5 +58,9 @@ struct B { // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: COMPLETION: Pattern : member1(<#args#> + // Check in the middle and at the end of identifier too. + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s + // CHECK-CC8: COMPLETION: Pattern : member2(<#args#> int member1, member2; }; Added: cfe/trunk/test/CodeCompletion/end-of-file.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/end-of-file.cpp?rev=330833&view=auto ============================================================================== --- cfe/trunk/test/CodeCompletion/end-of-file.cpp (added) +++ cfe/trunk/test/CodeCompletion/end-of-file.cpp Wed Apr 25 08:13:34 2018 @@ -0,0 +1,7 @@ +// Check that clang does not crash when completing at the last char in the +// buffer. +// NOTE: This file must *NOT* have newline at the end. +// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s +// CHECK: COMPLETION: foo +using foo = int***; +f \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits