mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Add support for project filtering
This commit is contained in:
parent
9d8c027cfb
commit
8e18e7a8ad
9
src/.vscode/settings.json
vendored
Normal file
9
src/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Place your settings in this file to overwrite default and user settings.
|
||||||
|
{
|
||||||
|
"cquery.blacklist": [
|
||||||
|
// ".*libclangmm/.*"
|
||||||
|
],
|
||||||
|
"cquery.whitelist": [
|
||||||
|
// ".*platform.*.cc"
|
||||||
|
]
|
||||||
|
}
|
@ -34,7 +34,7 @@ namespace {
|
|||||||
|
|
||||||
const int kNumIndexers = 8 - 1;
|
const int kNumIndexers = 8 - 1;
|
||||||
const int kMaxWorkspaceSearchResults = 1000;
|
const int kMaxWorkspaceSearchResults = 1000;
|
||||||
const bool kUseMultipleProcesses = false;
|
const bool kUseMultipleProcesses = false; // TODO: initialization options not passed properly when set to true.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1046,6 +1046,21 @@ void QueryDbMainLoop(
|
|||||||
Ipc_OpenProject* msg = static_cast<Ipc_OpenProject*>(message.get());
|
Ipc_OpenProject* msg = static_cast<Ipc_OpenProject*>(message.get());
|
||||||
std::string path = msg->project_path;
|
std::string path = msg->project_path;
|
||||||
|
|
||||||
|
std::vector<Matcher> whitelist;
|
||||||
|
std::cerr << "Using whitelist" << std::endl;
|
||||||
|
for (const std::string& entry : msg->whitelist) {
|
||||||
|
std::cerr << " - " << entry << std::endl;
|
||||||
|
whitelist.push_back(Matcher(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Matcher> blacklist;
|
||||||
|
std::cerr << "Using blacklist" << std::endl;
|
||||||
|
for (const std::string& entry : msg->blacklist) {
|
||||||
|
std::cerr << " - " << entry << std::endl;
|
||||||
|
blacklist.push_back(Matcher(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
project->Load(path);
|
project->Load(path);
|
||||||
std::cerr << "Loaded compilation entries (" << project->entries.size() << " files)" << std::endl;
|
std::cerr << "Loaded compilation entries (" << project->entries.size() << " files)" << std::endl;
|
||||||
//for (int i = 0; i < 10; ++i)
|
//for (int i = 0; i < 10; ++i)
|
||||||
@ -1054,6 +1069,31 @@ void QueryDbMainLoop(
|
|||||||
const CompilationEntry& entry = project->entries[i];
|
const CompilationEntry& entry = project->entries[i];
|
||||||
std::string filepath = entry.filename;
|
std::string filepath = entry.filename;
|
||||||
|
|
||||||
|
|
||||||
|
const Matcher* is_bad = nullptr;
|
||||||
|
for (const Matcher& m : whitelist) {
|
||||||
|
if (!m.IsMatch(filepath)) {
|
||||||
|
is_bad = &m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_bad) {
|
||||||
|
std::cerr << "[" << i << "/" << (project->entries.size() - 1) << "] Failed whitelist check \"" << is_bad->regex_string << "\"; skipping " << filepath << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const Matcher& m : blacklist) {
|
||||||
|
if (m.IsMatch(filepath)) {
|
||||||
|
is_bad = &m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_bad) {
|
||||||
|
std::cerr << "[" << i << "/" << (project->entries.size() - 1) << "] Failed blacklist check \"" << is_bad->regex_string << "\"; skipping " << filepath << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cerr << "[" << i << "/" << (project->entries.size() - 1)
|
std::cerr << "[" << i << "/" << (project->entries.size() - 1)
|
||||||
<< "] Dispatching index request for file " << filepath
|
<< "] Dispatching index request for file " << filepath
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -1619,7 +1659,7 @@ void LanguageServerStdinLoop() {
|
|||||||
if (!message)
|
if (!message)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::cerr << "[stdin]: Got message \"" << IpcIdToString(message->method_id) << '"' << std::endl;
|
std::cerr << "[stdin] Got message \"" << IpcIdToString(message->method_id) << '"' << std::endl;
|
||||||
switch (message->method_id) {
|
switch (message->method_id) {
|
||||||
// TODO: For simplicitly lets just proxy the initialize request like
|
// TODO: For simplicitly lets just proxy the initialize request like
|
||||||
// all other requests so that stdin loop thread becomes super simple.
|
// all other requests so that stdin loop thread becomes super simple.
|
||||||
@ -1627,11 +1667,15 @@ void LanguageServerStdinLoop() {
|
|||||||
auto request = static_cast<Ipc_InitializeRequest*>(message.get());
|
auto request = static_cast<Ipc_InitializeRequest*>(message.get());
|
||||||
if (request->params.rootUri) {
|
if (request->params.rootUri) {
|
||||||
std::string project_path = request->params.rootUri->GetPath();
|
std::string project_path = request->params.rootUri->GetPath();
|
||||||
std::cerr << "Initialize in directory " << project_path
|
std::cerr << "[stdin] Initialize in directory " << project_path
|
||||||
<< " with uri " << request->params.rootUri->raw_uri
|
<< " with uri " << request->params.rootUri->raw_uri
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
auto open_project = MakeUnique<Ipc_OpenProject>();
|
auto open_project = MakeUnique<Ipc_OpenProject>();
|
||||||
open_project->project_path = project_path;
|
open_project->project_path = project_path;
|
||||||
|
if (request->params.initializationOptions) {
|
||||||
|
open_project->whitelist = request->params.initializationOptions->whitelist;
|
||||||
|
open_project->blacklist = request->params.initializationOptions->blacklist;
|
||||||
|
}
|
||||||
ipc->SendMessage(IpcManager::Destination::Server, std::move(open_project));
|
ipc->SendMessage(IpcManager::Destination::Server, std::move(open_project));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
Matcher::Matcher(const std::string& search) {
|
Matcher::Matcher(const std::string& search) {
|
||||||
|
/*
|
||||||
std::string real_search;
|
std::string real_search;
|
||||||
real_search.reserve(search.size() * 3 + 2);
|
real_search.reserve(search.size() * 3 + 2);
|
||||||
for (auto c : search) {
|
for (auto c : search) {
|
||||||
@ -10,8 +11,10 @@ Matcher::Matcher(const std::string& search) {
|
|||||||
real_search += c;
|
real_search += c;
|
||||||
}
|
}
|
||||||
real_search += ".*";
|
real_search += ".*";
|
||||||
|
*/
|
||||||
|
|
||||||
regex = std::regex(real_search,
|
regex_string = search;
|
||||||
|
regex = std::regex(regex_string,
|
||||||
std::regex_constants::ECMAScript |
|
std::regex_constants::ECMAScript |
|
||||||
std::regex_constants::icase |
|
std::regex_constants::icase |
|
||||||
std::regex_constants::optimize
|
std::regex_constants::optimize
|
||||||
@ -19,7 +22,7 @@ Matcher::Matcher(const std::string& search) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matcher::IsMatch(const std::string& value) {
|
bool Matcher::IsMatch(const std::string& value) const {
|
||||||
//std::smatch match;
|
//std::smatch match;
|
||||||
//return std::regex_match(value, match, regex);
|
//return std::regex_match(value, match, regex);
|
||||||
return std::regex_match(value, regex, std::regex_constants::match_any);
|
return std::regex_match(value, regex, std::regex_constants::match_any);
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
struct Matcher {
|
struct Matcher {
|
||||||
Matcher(const std::string& search);
|
Matcher(const std::string& search);
|
||||||
|
|
||||||
bool IsMatch(const std::string& value);
|
bool IsMatch(const std::string& value) const;
|
||||||
|
|
||||||
|
std::string regex_string;
|
||||||
std::regex regex;
|
std::regex regex;
|
||||||
};
|
};
|
||||||
|
@ -58,6 +58,8 @@ MAKE_REFLECT_EMPTY_STRUCT(Ipc_IsAlive);
|
|||||||
struct Ipc_OpenProject : public IpcMessage<Ipc_OpenProject> {
|
struct Ipc_OpenProject : public IpcMessage<Ipc_OpenProject> {
|
||||||
static constexpr IpcId kIpcId = IpcId::OpenProject;
|
static constexpr IpcId kIpcId = IpcId::OpenProject;
|
||||||
std::string project_path;
|
std::string project_path;
|
||||||
|
std::vector<std::string> whitelist;
|
||||||
|
std::vector<std::string> blacklist;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Ipc_OpenProject, project_path);
|
MAKE_REFLECT_STRUCT(Ipc_OpenProject, project_path);
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ std::unique_ptr<BaseIpcMessage> MessageRegistry::ReadMessageFromStdin() {
|
|||||||
content += c;
|
content += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//std::cerr << content.c_str() << std::endl;
|
||||||
|
|
||||||
rapidjson::Document document;
|
rapidjson::Document document;
|
||||||
document.Parse(content.c_str(), content_length);
|
document.Parse(content.c_str(), content_length);
|
||||||
assert(!document.HasParseError());
|
assert(!document.HasParseError());
|
||||||
|
@ -800,6 +800,11 @@ struct lsClientCapabilities {
|
|||||||
MAKE_REFLECT_STRUCT(lsClientCapabilities, workspace, textDocument);
|
MAKE_REFLECT_STRUCT(lsClientCapabilities, workspace, textDocument);
|
||||||
|
|
||||||
struct lsInitializeParams {
|
struct lsInitializeParams {
|
||||||
|
struct lsCustomInitializationOptions {
|
||||||
|
NonElidedVector<std::string> whitelist;
|
||||||
|
NonElidedVector<std::string> blacklist;
|
||||||
|
};
|
||||||
|
|
||||||
// The process Id of the parent process that started
|
// The process Id of the parent process that started
|
||||||
// the server. Is null if the process has not been started by another process.
|
// the server. Is null if the process has not been started by another process.
|
||||||
// If the parent process is not alive then the server should exit (see exit notification) its process.
|
// If the parent process is not alive then the server should exit (see exit notification) its process.
|
||||||
@ -817,7 +822,7 @@ struct lsInitializeParams {
|
|||||||
optional<lsDocumentUri> rootUri;
|
optional<lsDocumentUri> rootUri;
|
||||||
|
|
||||||
// User provided initialization options.
|
// User provided initialization options.
|
||||||
// initializationOptions?: any; // TODO
|
optional<lsCustomInitializationOptions> initializationOptions;
|
||||||
|
|
||||||
// The capabilities provided by the client (editor or tool)
|
// The capabilities provided by the client (editor or tool)
|
||||||
lsClientCapabilities capabilities;
|
lsClientCapabilities capabilities;
|
||||||
@ -834,7 +839,8 @@ struct lsInitializeParams {
|
|||||||
};
|
};
|
||||||
void Reflect(Reader& reader, lsInitializeParams::lsTrace& value);
|
void Reflect(Reader& reader, lsInitializeParams::lsTrace& value);
|
||||||
void Reflect(Writer& writer, lsInitializeParams::lsTrace& value);
|
void Reflect(Writer& writer, lsInitializeParams::lsTrace& value);
|
||||||
MAKE_REFLECT_STRUCT(lsInitializeParams, processId, rootPath, rootUri, capabilities, trace);
|
MAKE_REFLECT_STRUCT(lsInitializeParams::lsCustomInitializationOptions, whitelist, blacklist);
|
||||||
|
MAKE_REFLECT_STRUCT(lsInitializeParams, processId, rootPath, rootUri, initializationOptions, capabilities, trace);
|
||||||
|
|
||||||
|
|
||||||
struct lsInitializeError {
|
struct lsInitializeError {
|
||||||
|
Loading…
Reference in New Issue
Block a user