mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-08 01:04:54 +00:00
Add clang.excludeGlobs option
It allows to disable compilations options matching any of specified patterns. '*', '?', '[' and ']' metacharacters are supported.
This commit is contained in:
parent
d3a3bcef34
commit
2358c34852
@ -101,6 +101,10 @@ struct Config {
|
|||||||
// e.g. If your project is built by GCC and has an option thag clang does not understand.
|
// e.g. If your project is built by GCC and has an option thag clang does not understand.
|
||||||
std::vector<std::string> excludeArgs;
|
std::vector<std::string> excludeArgs;
|
||||||
|
|
||||||
|
// Arguments matching any of these glob patterns will be excluded.
|
||||||
|
// * ? and [] metacharacters are supported.
|
||||||
|
std::vector<std::string> excludeGlobs;
|
||||||
|
|
||||||
// Additional arguments to pass to clang.
|
// Additional arguments to pass to clang.
|
||||||
std::vector<std::string> extraArgs;
|
std::vector<std::string> extraArgs;
|
||||||
|
|
||||||
@ -323,8 +327,8 @@ REFLECT_STRUCT(Config::ServerCap::Workspace::WorkspaceFolders, supported,
|
|||||||
REFLECT_STRUCT(Config::ServerCap::Workspace, workspaceFolders);
|
REFLECT_STRUCT(Config::ServerCap::Workspace, workspaceFolders);
|
||||||
REFLECT_STRUCT(Config::ServerCap, documentOnTypeFormattingProvider,
|
REFLECT_STRUCT(Config::ServerCap, documentOnTypeFormattingProvider,
|
||||||
foldingRangeProvider, workspace);
|
foldingRangeProvider, workspace);
|
||||||
REFLECT_STRUCT(Config::Clang, excludeArgs, extraArgs, pathMappings,
|
REFLECT_STRUCT(Config::Clang, excludeArgs, excludeGlobs, extraArgs,
|
||||||
resourceDir);
|
pathMappings, resourceDir);
|
||||||
REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport,
|
REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport,
|
||||||
linkSupport, snippetSupport);
|
linkSupport, snippetSupport);
|
||||||
REFLECT_STRUCT(Config::CodeLens, localVariables);
|
REFLECT_STRUCT(Config::CodeLens, localVariables);
|
||||||
|
@ -30,6 +30,7 @@ limitations under the License.
|
|||||||
#include <clang/Tooling/CompilationDatabase.h>
|
#include <clang/Tooling/CompilationDatabase.h>
|
||||||
#include <llvm/ADT/STLExtras.h>
|
#include <llvm/ADT/STLExtras.h>
|
||||||
#include <llvm/ADT/StringSet.h>
|
#include <llvm/ADT/StringSet.h>
|
||||||
|
#include <llvm/Support/GlobPattern.h>
|
||||||
#include <llvm/Support/LineIterator.h>
|
#include <llvm/Support/LineIterator.h>
|
||||||
#include <llvm/Support/Program.h>
|
#include <llvm/Support/Program.h>
|
||||||
|
|
||||||
@ -82,9 +83,33 @@ struct ProjectProcessor {
|
|||||||
Project::Folder &folder;
|
Project::Folder &folder;
|
||||||
std::unordered_set<size_t> command_set;
|
std::unordered_set<size_t> command_set;
|
||||||
StringSet<> excludeArgs;
|
StringSet<> excludeArgs;
|
||||||
|
SmallVector<GlobPattern, 0> excludeGlobs;
|
||||||
|
|
||||||
ProjectProcessor(Project::Folder &folder) : folder(folder) {
|
ProjectProcessor(Project::Folder &folder) : folder(folder) {
|
||||||
for (auto &arg : g_config->clang.excludeArgs)
|
for (auto &arg : g_config->clang.excludeArgs)
|
||||||
excludeArgs.insert(arg);
|
excludeArgs.insert(arg);
|
||||||
|
|
||||||
|
for (const auto &globString : g_config->clang.excludeGlobs) {
|
||||||
|
auto globOrErr = GlobPattern::create(globString);
|
||||||
|
|
||||||
|
if (!globOrErr) {
|
||||||
|
LOG_S(WARNING) << "bad glob: " << globString;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
excludeGlobs.push_back(globOrErr.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ArgExcluded(StringRef arg) {
|
||||||
|
if (excludeArgs.count(arg))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (const auto &glob : excludeGlobs) {
|
||||||
|
if (glob.match(arg)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand %c %cpp ... in .ccls
|
// Expand %c %cpp ... in .ccls
|
||||||
@ -115,7 +140,7 @@ struct ProjectProcessor {
|
|||||||
}
|
}
|
||||||
if (ok)
|
if (ok)
|
||||||
args.push_back(A.data());
|
args.push_back(A.data());
|
||||||
} else if (!excludeArgs.count(A)) {
|
} else if (!ArgExcluded(A)) {
|
||||||
args.push_back(arg);
|
args.push_back(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,7 +421,7 @@ void Project::LoadDirectory(const std::string &root, Project::Folder &folder) {
|
|||||||
entry.args.reserve(args.size());
|
entry.args.reserve(args.size());
|
||||||
for (std::string &arg : args) {
|
for (std::string &arg : args) {
|
||||||
DoPathMapping(arg);
|
DoPathMapping(arg);
|
||||||
if (!proc.excludeArgs.count(arg))
|
if (!proc.ArgExcluded(arg))
|
||||||
entry.args.push_back(Intern(arg));
|
entry.args.push_back(Intern(arg));
|
||||||
}
|
}
|
||||||
entry.compdb_size = entry.args.size();
|
entry.compdb_size = entry.args.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user