summaryrefslogtreecommitdiff
path: root/source/Commands/CommandCompletions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Commands/CommandCompletions.cpp')
-rw-r--r--source/Commands/CommandCompletions.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/source/Commands/CommandCompletions.cpp b/source/Commands/CommandCompletions.cpp
index 7b351c50dc69..705e87651a8c 100644
--- a/source/Commands/CommandCompletions.cpp
+++ b/source/Commands/CommandCompletions.cpp
@@ -7,18 +7,14 @@
//
//===----------------------------------------------------------------------===//
-// C Includes
#include <sys/stat.h>
#if defined(__APPLE__) || defined(__linux__)
#include <pwd.h>
#endif
-// C++ Includes
-// Other libraries and framework includes
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSet.h"
-// Project includes
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
@@ -105,7 +101,6 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
if (CompletionBuffer.size() >= PATH_MAX)
return matches.GetSize();
- namespace fs = llvm::sys::fs;
namespace path = llvm::sys::path;
llvm::StringRef SearchDir;
@@ -121,7 +116,7 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
if (FirstSep != llvm::StringRef::npos)
Remainder = Buffer.drop_front(FirstSep + 1);
- llvm::SmallString<PATH_MAX> Resolved;
+ llvm::SmallString<256> Resolved;
if (!Resolver.ResolveExact(Username, Resolved)) {
// We couldn't resolve it as a full username. If there were no slashes
// then this might be a partial username. We try to resolve it as such
@@ -166,7 +161,11 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
size_t FullPrefixLen = CompletionBuffer.size();
PartialItem = path::filename(CompletionBuffer);
- if (PartialItem == ".")
+
+ // 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()))
PartialItem = llvm::StringRef();
if (SearchDir.empty()) {
@@ -178,11 +177,16 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
// SearchDir now contains the directory to search in, and Prefix contains the
// text we want to match against items in that directory.
+ FileSystem &fs = FileSystem::Instance();
std::error_code EC;
- fs::directory_iterator Iter(SearchDir, EC, false);
- fs::directory_iterator End;
+ llvm::vfs::directory_iterator Iter = fs.DirBegin(SearchDir, EC);
+ llvm::vfs::directory_iterator End;
for (; Iter != End && !EC; Iter.increment(EC)) {
auto &Entry = *Iter;
+ llvm::ErrorOr<llvm::vfs::Status> Status = fs.GetStatus(Entry.path());
+
+ if (!Status)
+ continue;
auto Name = path::filename(Entry.path());
@@ -190,20 +194,18 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name,
if (Name == "." || Name == ".." || !Name.startswith(PartialItem))
continue;
- // We have a match.
-
- llvm::ErrorOr<fs::basic_file_status> st = Entry.status();
- if (!st)
- continue;
+ bool is_dir = Status->isDirectory();
// If it's a symlink, then we treat it as a directory as long as the target
// is a directory.
- bool is_dir = fs::is_directory(*st);
- if (fs::is_symlink_file(*st)) {
- fs::file_status target_st;
- if (!fs::status(Entry.path(), target_st))
- is_dir = fs::is_directory(target_st);
+ if (Status->isSymlink()) {
+ FileSpec symlink_filespec(Entry.path());
+ FileSpec resolved_filespec;
+ auto error = fs.ResolveSymbolicLink(symlink_filespec, resolved_filespec);
+ if (error.Success())
+ is_dir = fs.IsDirectory(symlink_filespec);
}
+
if (only_directories && !is_dir)
continue;
@@ -357,13 +359,13 @@ CommandCompletions::SourceFileCompleter::SourceFileCompleter(
CompletionRequest &request)
: CommandCompletions::Completer(interpreter, request),
m_include_support_files(include_support_files), m_matching_files() {
- FileSpec partial_spec(m_request.GetCursorArgumentPrefix(), false);
+ FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
m_file_name = partial_spec.GetFilename().GetCString();
m_dir_name = partial_spec.GetDirectory().GetCString();
}
-Searcher::Depth CommandCompletions::SourceFileCompleter::GetDepth() {
- return eDepthCompUnit;
+lldb::SearchDepth CommandCompletions::SourceFileCompleter::GetDepth() {
+ return lldb::eSearchDepthCompUnit;
}
Searcher::CallbackReturn
@@ -454,8 +456,8 @@ CommandCompletions::SymbolCompleter::SymbolCompleter(
m_regex.Compile(regex_str);
}
-Searcher::Depth CommandCompletions::SymbolCompleter::GetDepth() {
- return eDepthModule;
+lldb::SearchDepth CommandCompletions::SymbolCompleter::GetDepth() {
+ return lldb::eSearchDepthModule;
}
Searcher::CallbackReturn CommandCompletions::SymbolCompleter::SearchCallback(
@@ -497,13 +499,13 @@ size_t CommandCompletions::SymbolCompleter::DoCompletion(SearchFilter *filter) {
CommandCompletions::ModuleCompleter::ModuleCompleter(
CommandInterpreter &interpreter, CompletionRequest &request)
: CommandCompletions::Completer(interpreter, request) {
- FileSpec partial_spec(m_request.GetCursorArgumentPrefix(), false);
+ FileSpec partial_spec(m_request.GetCursorArgumentPrefix());
m_file_name = partial_spec.GetFilename().GetCString();
m_dir_name = partial_spec.GetDirectory().GetCString();
}
-Searcher::Depth CommandCompletions::ModuleCompleter::GetDepth() {
- return eDepthModule;
+lldb::SearchDepth CommandCompletions::ModuleCompleter::GetDepth() {
+ return lldb::eSearchDepthModule;
}
Searcher::CallbackReturn CommandCompletions::ModuleCompleter::SearchCallback(