vscode settings can now include an additional set of clang arguments to apply.

This commit is contained in:
Jacob Dufault 2017-04-17 21:06:01 -07:00
parent 2b6f4b7cdf
commit c615535d33
9 changed files with 25 additions and 14 deletions

View File

@ -324,7 +324,7 @@ void CompletionMain(CompletionManager* completion_manager) {
} // namespace } // namespace
CompletionSession::CompletionSession(const CompilationEntry& file, WorkingFiles* working_files) : file(file) { CompletionSession::CompletionSession(const CompilationEntry& file, IndexerConfig* config, WorkingFiles* working_files) : file(file) {
std::vector<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles(); std::vector<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles();
std::vector<std::string> args = file.args; std::vector<std::string> args = file.args;
@ -339,7 +339,7 @@ CompletionSession::CompletionSession(const CompilationEntry& file, WorkingFiles*
// TODO: I think we crash when there are syntax errors. // TODO: I think we crash when there are syntax errors.
active_index = MakeUnique<clang::Index>(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/); active_index = MakeUnique<clang::Index>(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/);
active = MakeUnique<clang::TranslationUnit>(*active_index, file.filename, args, unsaved, Flags()); active = MakeUnique<clang::TranslationUnit>(config, *active_index, file.filename, args, unsaved, Flags());
std::cerr << "Done creating active; did_fail=" << active->did_fail << std::endl; std::cerr << "Done creating active; did_fail=" << active->did_fail << std::endl;
//if (active->did_fail) { //if (active->did_fail) {
// std::cerr << "Failed to create translation unit; trying again..." << std::endl; // std::cerr << "Failed to create translation unit; trying again..." << std::endl;
@ -366,7 +366,8 @@ void CompletionSession::Refresh(std::vector<CXUnsavedFile>& unsaved) {
active->ReparseTranslationUnit(unsaved); active->ReparseTranslationUnit(unsaved);
} }
CompletionManager::CompletionManager(Project* project, WorkingFiles* working_files) : project(project), working_files(working_files) { CompletionManager::CompletionManager(IndexerConfig* config, Project* project, WorkingFiles* working_files)
: config(config), project(project), working_files(working_files) {
new std::thread([&]() { new std::thread([&]() {
CompletionMain(this); CompletionMain(this);
}); });
@ -397,6 +398,6 @@ CompletionSession* CompletionManager::GetOrOpenSession(const std::string& filena
else { else {
std::cerr << "Found compilation entry" << std::endl; std::cerr << "Found compilation entry" << std::endl;
} }
sessions.push_back(MakeUnique<CompletionSession>(*entry, working_files)); sessions.push_back(MakeUnique<CompletionSession>(*entry, config, working_files));
return sessions[sessions.size() - 1].get(); return sessions[sessions.size() - 1].get();
} }

View File

@ -24,7 +24,7 @@ struct CompletionSession {
//std::unique_ptr<clang::TranslationUnit> updated; //std::unique_ptr<clang::TranslationUnit> updated;
//std::unique_ptr<clang::Index> updated_index; //std::unique_ptr<clang::Index> updated_index;
CompletionSession(const CompilationEntry& file, WorkingFiles* working_files); CompletionSession(const CompilationEntry& file, IndexerConfig* config, WorkingFiles* working_files);
~CompletionSession(); ~CompletionSession();
// Refresh file index. // Refresh file index.
@ -33,6 +33,7 @@ struct CompletionSession {
struct CompletionManager { struct CompletionManager {
std::vector<std::unique_ptr<CompletionSession>> sessions; std::vector<std::unique_ptr<CompletionSession>> sessions;
IndexerConfig* config;
Project* project; Project* project;
WorkingFiles* working_files; WorkingFiles* working_files;
@ -43,7 +44,7 @@ struct CompletionManager {
}; };
AtomicObject<CompletionRequest> completion_request; AtomicObject<CompletionRequest> completion_request;
CompletionManager(Project* project, WorkingFiles* working_files); CompletionManager(IndexerConfig* config, Project* project, WorkingFiles* working_files);
// Start a code completion at the given location. |on_complete| will run when // Start a code completion at the given location. |on_complete| will run when
// completion results are available. |on_complete| may run on any thread. // completion results are available. |on_complete| may run on any thread.

View File

@ -902,7 +902,7 @@ bool IndexMain_DoIndex(IndexerConfig* config,
} }
// Parse request and send a response. // Parse request and send a response.
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(file_consumer_shared, index_request->path, index_request->args); std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(config, file_consumer_shared, index_request->path, index_request->args);
time.ResetAndPrint("Parsing/indexing " + index_request->path); time.ResetAndPrint("Parsing/indexing " + index_request->path);
for (auto& current_index : indexes) { for (auto& current_index : indexes) {
@ -1601,7 +1601,7 @@ void QueryDbMain(IndexerConfig* config) {
Project project; Project project;
WorkingFiles working_files; WorkingFiles working_files;
CompletionManager completion_manager(&project, &working_files); CompletionManager completion_manager(config, &project, &working_files);
FileConsumer::SharedState file_consumer_shared; FileConsumer::SharedState file_consumer_shared;
// Start indexer threads. // Start indexer threads.

View File

@ -1419,13 +1419,13 @@ void indexEntityReference(CXClientData client_data,
std::vector<std::unique_ptr<IndexedFile>> Parse(FileConsumer::SharedState* file_consumer_shared, std::string filename, std::vector<std::string> args, bool dump_ast) { std::vector<std::unique_ptr<IndexedFile>> Parse(IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, std::string filename, std::vector<std::string> args, bool dump_ast) {
filename = NormalizePath(filename); filename = NormalizePath(filename);
clang::Index index(0 /*excludeDeclarationsFromPCH*/, clang::Index index(0 /*excludeDeclarationsFromPCH*/,
0 /*displayDiagnostics*/); 0 /*displayDiagnostics*/);
std::vector<CXUnsavedFile> unsaved_files; std::vector<CXUnsavedFile> unsaved_files;
clang::TranslationUnit tu(index, filename, args, unsaved_files, CXTranslationUnit_KeepGoing); clang::TranslationUnit tu(config, index, filename, args, unsaved_files, CXTranslationUnit_KeepGoing);
if (dump_ast) if (dump_ast)
Dump(tu.document_cursor()); Dump(tu.document_cursor());

View File

@ -4,6 +4,7 @@
#include "position.h" #include "position.h"
#include "serializer.h" #include "serializer.h"
#include "utils.h" #include "utils.h"
#include "language_server_api.h"
#include "libclangmm/clangmm.h" #include "libclangmm/clangmm.h"
#include "libclangmm/Utility.h" #include "libclangmm/Utility.h"
@ -456,5 +457,5 @@ struct IndexedFile {
std::string ToString(); std::string ToString();
}; };
std::vector<std::unique_ptr<IndexedFile>> Parse(FileConsumer::SharedState* file_consumer_shared, std::string filename, std::vector<std::string> args, bool dump_ast = false); std::vector<std::unique_ptr<IndexedFile>> Parse(IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, std::string filename, std::vector<std::string> args, bool dump_ast = false);
void IndexInit(); void IndexInit();

View File

@ -61,8 +61,9 @@ struct IndexerConfig {
NonElidedVector<std::string> blacklist; NonElidedVector<std::string> blacklist;
int indexerCount = 1; int indexerCount = 1;
int maxWorkspaceSearchResults = 1000; int maxWorkspaceSearchResults = 1000;
std::vector<std::string> extraClangArguments;
}; };
MAKE_REFLECT_STRUCT(IndexerConfig, cacheDirectory, whitelist, blacklist, indexerCount, maxWorkspaceSearchResults); MAKE_REFLECT_STRUCT(IndexerConfig, cacheDirectory, whitelist, blacklist, indexerCount, maxWorkspaceSearchResults, extraClangArguments);

View File

@ -10,6 +10,7 @@
namespace clang { namespace clang {
TranslationUnit::TranslationUnit( TranslationUnit::TranslationUnit(
IndexerConfig* config,
Index &index, Index &index,
const std::string& filepath, const std::string& filepath,
const std::vector<std::string>& arguments, const std::vector<std::string>& arguments,
@ -24,6 +25,9 @@ TranslationUnit::TranslationUnit(
for (const auto& arg : platform_args) for (const auto& arg : platform_args)
args.push_back(arg.c_str()); args.push_back(arg.c_str());
for (const std::string& arg : config->extraClangArguments)
args.push_back(arg.c_str());
std::cerr << "Parsing " << filepath << " with args "; std::cerr << "Parsing " << filepath << " with args ";
for (const auto& arg : args) for (const auto& arg : args)
std::cerr << arg << " "; std::cerr << arg << " ";

View File

@ -10,11 +10,13 @@
#include "Tokens.h" #include "Tokens.h"
#include "CodeCompleteResults.h" #include "CodeCompleteResults.h"
#include "Cursor.h" #include "Cursor.h"
#include "../language_server_api.h"
namespace clang { namespace clang {
class TranslationUnit { class TranslationUnit {
public: public:
TranslationUnit(Index &index, TranslationUnit(IndexerConfig* config,
Index &index,
const std::string &filepath, const std::string &filepath,
const std::vector<std::string>& arguments, const std::vector<std::string>& arguments,
std::vector<CXUnsavedFile> unsaved_files, std::vector<CXUnsavedFile> unsaved_files,

View File

@ -130,11 +130,12 @@ void RunTests() {
// Parse expected output from the test, parse it into JSON document. // Parse expected output from the test, parse it into JSON document.
std::unordered_map<std::string, std::string> all_expected_output = ParseTestExpectation(path); std::unordered_map<std::string, std::string> all_expected_output = ParseTestExpectation(path);
IndexerConfig config;
FileConsumer::SharedState file_consumer_shared; FileConsumer::SharedState file_consumer_shared;
// Run test. // Run test.
std::cout << "[START] " << path << std::endl; std::cout << "[START] " << path << std::endl;
std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(&file_consumer_shared, path, { std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(&config, &file_consumer_shared, path, {
"-xc++", "-xc++",
"-std=c++11", "-std=c++11",
"-IC:/Users/jacob/Desktop/superindex/indexer/third_party/", "-IC:/Users/jacob/Desktop/superindex/indexer/third_party/",