mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
wip
This commit is contained in:
parent
a8a343420b
commit
4c601c4d37
@ -182,6 +182,8 @@ CompletionSession::CompletionSession(const CompilationEntry& file, WorkingFiles*
|
||||
std::vector<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles();
|
||||
|
||||
std::vector<std::string> args = file.args;
|
||||
args.push_back("-x");
|
||||
args.push_back("c++");
|
||||
args.push_back("-fparse-all-comments");
|
||||
|
||||
std::string sent_args = "";
|
||||
@ -387,4 +389,4 @@ CompletionSession* CompletionManager::GetOrOpenSession(const std::string& filena
|
||||
}
|
||||
sessions.push_back(MakeUnique<CompletionSession>(*entry, working_files));
|
||||
return sessions[sessions.size() - 1].get();
|
||||
}
|
||||
}
|
||||
|
@ -333,6 +333,8 @@ void QueryDbMainLoop(
|
||||
|
||||
project->entries = LoadCompilationEntriesFromDirectory(path);
|
||||
std::cerr << "Loaded compilation entries (" << project->entries.size() << " files)" << std::endl;
|
||||
//for (int i = 0; i < 10; ++i)
|
||||
//std::cerr << project->entries[i].filename << std::endl;
|
||||
for (int i = 0; i < project->entries.size(); ++i) {
|
||||
const CompilationEntry& entry = project->entries[i];
|
||||
std::string filepath = entry.filename;
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include "compilation_database_loader.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "libclangmm/Utility.h"
|
||||
#include "platform.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
|
||||
#include "libclangmm/Utility.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
// See http://stackoverflow.com/a/2072890
|
||||
bool EndsWith(const std::string& value, const std::string& ending) {
|
||||
@ -49,6 +51,83 @@ std::vector<CompilationEntry> LoadFromDirectoryListing(const std::string& projec
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// https://github.com/Andersbakken/rtags/blob/6b16b81ea93aeff4a58930b44b2a0a207b456192/src/Source.cpp
|
||||
static const char *kValueArgs[] = {
|
||||
"--param",
|
||||
"-G",
|
||||
"-I",
|
||||
"-MF",
|
||||
"-MQ",
|
||||
"-MT",
|
||||
"-T",
|
||||
"-V",
|
||||
"-Xanalyzer",
|
||||
"-Xassembler",
|
||||
"-Xclang",
|
||||
"-Xlinker",
|
||||
"-Xpreprocessor",
|
||||
"-arch",
|
||||
"-b",
|
||||
"-gcc-toolchain",
|
||||
"-imacros",
|
||||
"-imultilib",
|
||||
"-include",
|
||||
"-iprefix",
|
||||
"-isysroot",
|
||||
"-ivfsoverlay",
|
||||
"-iwithprefix",
|
||||
"-iwithprefixbefore",
|
||||
"-o",
|
||||
"-target",
|
||||
"-x"
|
||||
};
|
||||
static const char *kBlacklist[] = {
|
||||
"--param",
|
||||
"-M",
|
||||
"-MD",
|
||||
"-MF",
|
||||
"-MG",
|
||||
"-MM",
|
||||
"-MMD",
|
||||
"-MP",
|
||||
"-MQ",
|
||||
"-MT",
|
||||
"-Og",
|
||||
"-Wa,--32",
|
||||
"-Wa,--64",
|
||||
"-Wl,--incremental-full",
|
||||
"-Wl,--incremental-patch,1",
|
||||
"-Wl,--no-incremental",
|
||||
"-fbuild-session-file=",
|
||||
"-fbuild-session-timestamp=",
|
||||
"-fembed-bitcode",
|
||||
"-fembed-bitcode-marker",
|
||||
"-fmodules-validate-once-per-build-session",
|
||||
"-fno-delete-null-pointer-checks",
|
||||
"-fno-use-linker-plugin"
|
||||
"-fno-var-tracking",
|
||||
"-fno-var-tracking-assignments",
|
||||
"-fno-enforce-eh-specs",
|
||||
"-fvar-tracking",
|
||||
"-fvar-tracking-assignments",
|
||||
"-fvar-tracking-assignments-toggle",
|
||||
"-gcc-toolchain",
|
||||
"-march=",
|
||||
"-masm=",
|
||||
"-mcpu=",
|
||||
"-mfpmath=",
|
||||
"-mtune=",
|
||||
"-s",
|
||||
|
||||
//"-B",
|
||||
//"-f",
|
||||
//"-pipe",
|
||||
//"-W",
|
||||
"/",
|
||||
"..",
|
||||
};
|
||||
|
||||
std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::string& project_directory) {
|
||||
CXCompilationDatabase_Error cx_db_load_error;
|
||||
CXCompilationDatabase cx_db = clang_CompilationDatabase_fromDirectory(project_directory.c_str(), &cx_db_load_error);
|
||||
@ -65,13 +144,47 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
|
||||
CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i);
|
||||
CompilationEntry entry;
|
||||
|
||||
// TODO: remove ComplationEntry::directory
|
||||
entry.directory = clang::ToString(clang_CompileCommand_getDirectory(cx_command));
|
||||
entry.filename = clang::ToString(clang_CompileCommand_getFilename(cx_command));
|
||||
|
||||
std::string normalized = entry.directory + "/" + entry.filename;
|
||||
entry.filename = NormalizePath(normalized);
|
||||
|
||||
unsigned int num_args = clang_CompileCommand_getNumArgs(cx_command);
|
||||
entry.args.reserve(num_args);
|
||||
for (unsigned int j = 0; j < num_args; ++j) {
|
||||
entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, j)));
|
||||
std::string arg = clang::ToString(clang_CompileCommand_getArg(cx_command, j));
|
||||
|
||||
|
||||
bool bad = false;
|
||||
for (auto& entry : kValueArgs) {
|
||||
if (StartsWith(arg, entry)) {
|
||||
bad = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (bad) {
|
||||
++j;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (auto& entry : kBlacklist) {
|
||||
if (StartsWith(arg, entry)) {
|
||||
bad = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (bad) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
entry.args.push_back(arg);
|
||||
|
||||
//if (StartsWith(arg, "-I") || StartsWith(arg, "-D") || StartsWith(arg, "-std"))
|
||||
}
|
||||
|
||||
|
||||
@ -82,4 +195,4 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
|
||||
clang_CompilationDatabase_dispose(cx_db);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1205,8 +1205,8 @@ void emptyIndexEntityReference(CXClientData client_data,
|
||||
IndexedFile Parse(std::string filename,
|
||||
std::vector<std::string> args,
|
||||
bool dump_ast) {
|
||||
clang_enableStackTraces();
|
||||
clang_toggleCrashRecovery(1);
|
||||
//clang_enableStackTraces();
|
||||
//clang_toggleCrashRecovery(1);
|
||||
|
||||
args.push_back("-std=c++11");
|
||||
args.push_back("-fms-compatibility");
|
||||
|
@ -25,3 +25,4 @@ std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
||||
|
||||
void PlatformInit();
|
||||
std::string GetWorkingDirectory();
|
||||
std::string NormalizePath(const std::string& path);
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
@ -105,8 +106,6 @@ struct PlatformSharedMemoryLinux : public PlatformSharedMemory {
|
||||
}
|
||||
};
|
||||
|
||||
#undef CHECKED
|
||||
|
||||
std::unique_ptr<PlatformMutex> CreatePlatformMutex(const std::string& name) {
|
||||
std::string name2 = "/" + name;
|
||||
return MakeUnique<PlatformMutexLinux>(name2);
|
||||
@ -118,12 +117,24 @@ std::unique_ptr<PlatformScopedMutexLock> CreatePlatformScopedMutexLock(
|
||||
static_cast<PlatformMutexLinux*>(mutex)->sem_);
|
||||
}
|
||||
|
||||
void PlatformInit() {
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
||||
const std::string& name, size_t size) {
|
||||
std::string name2 = "/" + name;
|
||||
return MakeUnique<PlatformSharedMemoryLinux>(name2, size);
|
||||
}
|
||||
|
||||
void PlatformInit() {
|
||||
}
|
||||
|
||||
std::string NormalizePath(const std::string& path) {
|
||||
errno = 0;
|
||||
char name[PATH_MAX + 1];
|
||||
realpath(path.c_str(), name);
|
||||
if (errno)
|
||||
return path;
|
||||
return name;
|
||||
}
|
||||
|
||||
#undef CHECKED
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user