[Lldb-commits] [lldb] e896612 - [lldb/Commands] Fix disk completion from root directory
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 6 10:58:55 PDT 2023
Author: Med Ismail Bennani
Date: 2023-06-06T10:58:34-07:00
New Revision: e8966125e2812f08bf0f548bf576981025d44cbd
URL: https://github.com/llvm/llvm-project/commit/e8966125e2812f08bf0f548bf576981025d44cbd
DIFF: https://github.com/llvm/llvm-project/commit/e8966125e2812f08bf0f548bf576981025d44cbd.diff
LOG: [lldb/Commands] Fix disk completion from root directory
This patch should fix path completion starting from the root directory.
To do so, this patch adds a special case when setting the search
directory when the completion buffer points to the root directory.
Differential Revision: https://reviews.llvm.org/D152013
Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
Added:
Modified:
lldb/source/Commands/CommandCompletions.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index 1fe25d9655dc9..35237d419d469 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -381,6 +381,8 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
Storage.append(RemainderDir);
}
SearchDir = Storage;
+ } else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
+ SearchDir = CompletionBuffer;
} else {
SearchDir = path::parent_path(CompletionBuffer);
}
@@ -390,9 +392,11 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
PartialItem = path::filename(CompletionBuffer);
// path::filename() will return "." when the passed path ends with a
- // directory separator. We have to filter those out, but only when the
- // "." doesn't come from the completion request itself.
- if (PartialItem == "." && path::is_separator(CompletionBuffer.back()))
+ // directory separator or the separator when passed the disk root directory.
+ // We have to filter those out, but only when the "." doesn't come from the
+ // completion request itself.
+ if ((PartialItem == "." || PartialItem == path::get_separator()) &&
+ path::is_separator(CompletionBuffer.back()))
PartialItem = llvm::StringRef();
if (SearchDir.empty()) {
diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index f25e1b408bbce..0cfd213177d6a 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -477,6 +477,19 @@ def test_custom_command_completion(self):
self.complete_from_to("my_test_cmd main.cp", ["main.cpp"])
self.expect("my_test_cmd main.cpp", substrs=["main.cpp"])
+ def test_completion_target_create_from_root_dir(self):
+ """Tests source file completion by completing ."""
+ root_dir = os.path.abspath(os.sep)
+ self.completions_contain(
+ "target create " + root_dir,
+ list(
+ filter(
+ lambda x: os.path.exists(x),
+ map(lambda x: root_dir + x + os.sep, os.listdir(root_dir)),
+ )
+ ),
+ )
+
def test_target_modules_load_aout(self):
"""Tests modules completion by completing the target modules load argument."""
self.build()
More information about the lldb-commits
mailing list