[clangd] Tweak --query-driver to ignore slash direction on windows

See https://github.com/clangd/clangd/issues/1022

Differential Revision: https://reviews.llvm.org/D120115
This commit is contained in:
Sam McCall 2022-02-18 13:28:16 +01:00
parent 12c4e65a76
commit 47b749e5be
1 changed files with 5 additions and 2 deletions

View File

@ -38,12 +38,10 @@
#include "clang/Basic/TargetOptions.h"
#include "clang/Driver/Types.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@ -276,6 +274,10 @@ std::string convertGlobToRegex(llvm::StringRef Glob) {
// Single star, accept any sequence without a slash.
RegStream << "[^/]*";
}
} else if (llvm::sys::path::is_separator(Glob[I]) &&
llvm::sys::path::is_separator('/') &&
llvm::sys::path::is_separator('\\')) {
RegStream << R"([/\\])"; // Accept either slash on windows.
} else {
RegStream << llvm::Regex::escape(Glob.substr(I, 1));
}
@ -293,6 +295,7 @@ llvm::Regex convertGlobsToRegex(llvm::ArrayRef<std::string> Globs) {
for (llvm::StringRef Glob : Globs)
RegTexts.push_back(convertGlobToRegex(Glob));
// Tempting to pass IgnoreCase, but we don't know the FS sensitivity.
llvm::Regex Reg(llvm::join(RegTexts, "|"));
assert(Reg.isValid(RegTexts.front()) &&
"Created an invalid regex from globs");