-
Notifications
You must be signed in to change notification settings - Fork 13.5k
allow implicit completion inside empty template argument list #138846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-tools-extra Author: Tom Praschan (tom-anders) ChangesI noticed that when triggering completion inside something like Full diff: https://github.com/llvm/llvm-project/pull/138846.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 0eb196fbad46a..cc35e03959332 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -2455,6 +2455,11 @@ bool isIncludeFile(llvm::StringRef Line) {
}
bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
+ // Check if we're inside an empty template argument list
+ if (Content.size() > 2 && Content[Offset - 1] == '<' &&
+ Content[Offset] == '>')
+ return true;
+
// Look at last line before completion point only.
Content = Content.take_front(Offset);
auto Pos = Content.rfind('\n');
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 718bee2e40b11..62e0f8627b7c7 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3978,6 +3978,7 @@ TEST(AllowImplicitCompletion, All) {
"foo.^bar",
"foo->^bar",
"foo::^bar",
+ "std::vector<std::vector<^>>",
" # include <^foo.h>",
"#import <foo/^bar.h>",
"#include_next \"^",
@@ -3990,6 +3991,7 @@ TEST(AllowImplicitCompletion, All) {
"#include \"foo.h\"^",
"#error <^",
"#<^",
+ "a <^b",
};
for (const char *Test : Yes) {
llvm::Annotations A(Test);
|
@llvm/pr-subscribers-clangd Author: Tom Praschan (tom-anders) ChangesI noticed that when triggering completion inside something like Full diff: https://github.com/llvm/llvm-project/pull/138846.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 0eb196fbad46a..cc35e03959332 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -2455,6 +2455,11 @@ bool isIncludeFile(llvm::StringRef Line) {
}
bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
+ // Check if we're inside an empty template argument list
+ if (Content.size() > 2 && Content[Offset - 1] == '<' &&
+ Content[Offset] == '>')
+ return true;
+
// Look at last line before completion point only.
Content = Content.take_front(Offset);
auto Pos = Content.rfind('\n');
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 718bee2e40b11..62e0f8627b7c7 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3978,6 +3978,7 @@ TEST(AllowImplicitCompletion, All) {
"foo.^bar",
"foo->^bar",
"foo::^bar",
+ "std::vector<std::vector<^>>",
" # include <^foo.h>",
"#import <foo/^bar.h>",
"#include_next \"^",
@@ -3990,6 +3991,7 @@ TEST(AllowImplicitCompletion, All) {
"#include \"foo.h\"^",
"#error <^",
"#<^",
+ "a <^b",
};
for (const char *Test : Yes) {
llvm::Annotations A(Test);
|
|
// Check if we're inside an empty template argument list | ||
if (Content.size() > 2 && Content[Offset - 1] == '<' && | ||
Content[Offset] == '>') | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also pop up a completion within a template parameter list?
template <^> class foo {};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, but the buildkite run is showing AllowImplicitCompletions.All
is currently failing
@@ -2455,6 +2455,11 @@ bool isIncludeFile(llvm::StringRef Line) { | |||
} | |||
|
|||
bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) { | |||
// Check if we're inside an empty template argument list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for consistency with the other checks in this function, could you:
- move this after the "Look at last line before completion only" check; and
- formulate the check using
ends_with
?
I noticed that when triggering completion inside something like
std::vector<^>
via the '<' trigger character, no results are returned. This PR adds a small heuristic to detect this case and offer completions