[Lldb-commits] [lldb] 45e3f66 - Auto-completion bug fix for dot operator
Walter Erquinigo via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 30 16:09:21 PST 2020
Author: Hector Diaz
Date: 2020-01-30T16:02:58-08:00
New Revision: 45e3f6660cf4503a8f63ce0a22e574f6d0997914
URL: https://github.com/llvm/llvm-project/commit/45e3f6660cf4503a8f63ce0a22e574f6d0997914
DIFF: https://github.com/llvm/llvm-project/commit/45e3f6660cf4503a8f63ce0a22e574f6d0997914.diff
LOG: Auto-completion bug fix for dot operator
Summary:
There was a bug on LLDB VSCode where there was the following behavior:
//Code
```
struct foo {
int bar:
};
...
foo my_foo = {10};
```
Trying to auto-complete my_foo.b with my_foo.bar resulted instead with my_foo.my_foo.bar
This diff fixes this bug and adds some tests to check correct behavior.
It also fixes the same bug using the arrow operator (->) when user manually requests completions.
TODO: Fix bug where no recommended completions are automatically shown with arrow operator
{F11249959}
{F11249958}
Reviewers: wallace
Reviewed By: wallace
Subscribers: teemperor, labath, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73506
Added:
Modified:
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/TestVSCode_completions.py
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/main.cpp
lldb/tools/lldb-vscode/lldb-vscode.cpp
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/TestVSCode_completions.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/TestVSCode_completions.py
index d1d92346e436..155d476bb58a 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/TestVSCode_completions.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/TestVSCode_completions.py
@@ -113,3 +113,76 @@ def test_completions(self):
}
],
)
+
+ self.verify_completions(
+ self.vscode.get_completions("foo1.v"),
+ [
+ {
+ "text": "var1",
+ "label": "foo1.var1 -- int"
+ }
+ ]
+ )
+
+ self.verify_completions(
+ self.vscode.get_completions("foo1.my_bar_object.v"),
+ [
+ {
+ "text": "var1",
+ "label": "foo1.my_bar_object.var1 -- int"
+ }
+ ]
+ )
+
+ self.verify_completions(
+ self.vscode.get_completions("foo1.var1 + foo1.v"),
+ [
+ {
+ "text": "var1",
+ "label": "foo1.var1 -- int"
+ }
+ ]
+ )
+
+ self.verify_completions(
+ self.vscode.get_completions("foo1.var1 + v"),
+ [
+ {
+ "text": "var1",
+ "label": "var1 -- int &"
+ }
+ ]
+ )
+
+ #should correctly handle spaces between objects and member operators
+ self.verify_completions(
+ self.vscode.get_completions("foo1 .v"),
+ [
+ {
+ "text": "var1",
+ "label": ".var1 -- int"
+ }
+ ],
+ [
+ {
+ "text": "var2",
+ "label": ".var2 -- int"
+ }
+ ]
+ )
+
+ self.verify_completions(
+ self.vscode.get_completions("foo1 . v"),
+ [
+ {
+ "text": "var1",
+ "label": "var1 -- int"
+ }
+ ],
+ [
+ {
+ "text": "var2",
+ "label": "var2 -- int"
+ }
+ ]
+ )
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/main.cpp b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/main.cpp
index 14a8815a5244..f77dba592f55 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/main.cpp
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/completions/main.cpp
@@ -1,6 +1,17 @@
#include <string>
#include <vector>
+struct bar {
+ int var1;
+};
+
+struct foo {
+ int var1;
+ bar* my_bar_pointer;
+ bar my_bar_object;
+ foo* next_foo;
+};
+
int fun(std::vector<std::string> var) {
return var.size(); // breakpoint 1
}
@@ -12,5 +23,8 @@ int main(int argc, char const *argv[]) {
std::string str2 = "b";
std::vector<std::string> vec;
fun(vec);
+ bar bar1 = {2};
+ bar* bar2 = &bar1;
+ foo foo1 = {3,&bar1, bar1, NULL};
return 0; // breakpoint 2
}
diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 8fad2a501773..83ea23653ff0 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -951,9 +951,17 @@ void request_completions(const llvm::json::Object &request) {
for (size_t i = 0; i < count; i++) {
std::string match = matches.GetStringAtIndex(i);
std::string description = descriptions.GetStringAtIndex(i);
-
+
llvm::json::Object item;
- EmplaceSafeString(item, "text", match);
+
+ llvm::StringRef match_ref = match;
+ for(llvm::StringRef commit_point: {".", "->"}) {
+ if (match_ref.contains(commit_point)){
+ match_ref = match_ref.rsplit(commit_point).second;
+ }
+ }
+ EmplaceSafeString(item, "text", match_ref);
+
if (description.empty())
EmplaceSafeString(item, "label", match);
else
More information about the lldb-commits
mailing list