Skip to content

Commit f9e2c6c

Browse files
committed
[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 <[email protected]>
1 parent 3cb3839 commit f9e2c6c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
384384
Storage.append(RemainderDir);
385385
}
386386
SearchDir = Storage;
387+
} else if (CompletionBuffer == path::root_directory(CompletionBuffer)) {
388+
SearchDir = CompletionBuffer;
387389
} else {
388390
SearchDir = path::parent_path(CompletionBuffer);
389391
}
@@ -393,9 +395,11 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name,
393395
PartialItem = path::filename(CompletionBuffer);
394396

395397
// path::filename() will return "." when the passed path ends with a
396-
// directory separator. We have to filter those out, but only when the
397-
// "." doesn't come from the completion request itself.
398-
if (PartialItem == "." && path::is_separator(CompletionBuffer.back()))
398+
// directory separator or the separator when passed the disk root directory.
399+
// We have to filter those out, but only when the "." doesn't come from the
400+
// completion request itself.
401+
if ((PartialItem == "." || PartialItem == path::get_separator()) &&
402+
path::is_separator(CompletionBuffer.back()))
399403
PartialItem = llvm::StringRef();
400404

401405
if (SearchDir.empty()) {

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,19 @@ def test_custom_command_completion(self):
477477
self.complete_from_to("my_test_cmd main.cp", ["main.cpp"])
478478
self.expect("my_test_cmd main.cpp", substrs=["main.cpp"])
479479

480+
def test_completion_target_create_from_root_dir(self):
481+
"""Tests source file completion by completing ."""
482+
root_dir = os.path.abspath(os.sep)
483+
self.completions_contain(
484+
"target create " + root_dir,
485+
list(
486+
filter(
487+
lambda x: os.path.exists(x),
488+
map(lambda x: root_dir + x + os.sep, os.listdir(root_dir)),
489+
)
490+
),
491+
)
492+
480493
def test_target_modules_load_aout(self):
481494
"""Tests modules completion by completing the target modules load argument."""
482495
self.build()

0 commit comments

Comments
 (0)