mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 13:48:04 +00:00
wip
This commit is contained in:
parent
cf1012b98c
commit
a19d4f732f
@ -1,14 +1,30 @@
|
||||
# Language
|
||||
-xc++
|
||||
-std=c++11
|
||||
|
||||
# Includes
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/doctest/doctest
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include
|
||||
-IC:/Program Files/LLVM/include
|
||||
-I/usr/local/Cellar/llvm/3.9.1/include
|
||||
|
||||
# Use libcxx (platform args)
|
||||
#-stdlib=libc++
|
||||
#-nostdinc++
|
||||
#-IC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
#-fms-compatibility
|
||||
#-fdelayed-template-parsing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--sysrootC:/Users/jacob/Desktop/superindex/indexer/libcxx
|
||||
#-IC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
#-FC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
|
||||
-fms-compatibility
|
||||
-fdelayed-template-parsing
|
||||
#-L<libcxx-install-prefix>/lib \
|
||||
#-Wl,-rpath,<libcxx-install-prefix>/lib \
|
||||
#-I<libcxx-install-prefix>/include/c++/v1 \
|
@ -1,13 +1,30 @@
|
||||
# Language
|
||||
-xc++
|
||||
-std=c++11
|
||||
|
||||
# Includes
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/doctest/doctest
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include
|
||||
-IC:/Program Files/LLVM/include
|
||||
|
||||
# Use libcxx
|
||||
-stdlib=libc++
|
||||
-nostdinc++
|
||||
-IC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
#-fms-compatibility
|
||||
#-fdelayed-template-parsing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--sysrootC:/Users/jacob/Desktop/superindex/indexer/libcxx
|
||||
#-IC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
#-FC:/Users/jacob/Desktop/superindex/indexer/libcxx/include
|
||||
|
||||
-fms-compatibility
|
||||
-fdelayed-template-parsing
|
||||
#-L<libcxx-install-prefix>/lib \
|
||||
#-Wl,-rpath,<libcxx-install-prefix>/lib \
|
||||
#-I<libcxx-install-prefix>/include/c++/v1 \
|
@ -311,8 +311,7 @@ void QueryDbMainLoop(
|
||||
|
||||
std::vector<std::unique_ptr<BaseIpcMessage>> messages = language_client->GetMessages(&language_client->for_server);
|
||||
for (auto& message : messages) {
|
||||
// std::cerr << "Processing message " << static_cast<int>(message->ipc_id)
|
||||
// << std::endl;
|
||||
std::cerr << "[querydb] Processing message " << static_cast<int>(message->method_id) << std::endl;
|
||||
|
||||
switch (message->method_id) {
|
||||
case IpcId::Quit: {
|
||||
@ -392,58 +391,62 @@ void QueryDbMainLoop(
|
||||
response.id = msg->id;
|
||||
|
||||
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
|
||||
if (file) {
|
||||
for (UsrRef ref : file->outline) {
|
||||
SymbolIdx symbol = db->usr_to_symbol[ref.usr];
|
||||
if (!file) {
|
||||
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
lsSymbolInformation info;
|
||||
info.location.range.start.line =
|
||||
ref.loc.line - 1; // TODO: cleanup indexer to negate by 1.
|
||||
info.location.range.start.character =
|
||||
ref.loc.column - 1; // TODO: cleanup indexer to negate by 1.
|
||||
// TODO: store range information.
|
||||
info.location.range.end.line = info.location.range.start.line;
|
||||
info.location.range.end.character =
|
||||
info.location.range.start.character;
|
||||
std::cerr << "File outline size is " << file->outline.size() << std::endl;
|
||||
for (UsrRef ref : file->outline) {
|
||||
SymbolIdx symbol = db->usr_to_symbol[ref.usr];
|
||||
|
||||
// TODO: cleanup namespace/naming so there is only one SymbolKind.
|
||||
switch (symbol.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryableTypeDef& def = db->types[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
info.kind = lsSymbolKind::Class;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryableFuncDef& def = db->funcs[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
if (def.def.declaring_type.has_value()) {
|
||||
info.kind = lsSymbolKind::Method;
|
||||
Usr declaring = def.def.declaring_type.value();
|
||||
info.containerName =
|
||||
db->types[db->usr_to_symbol[declaring].idx]
|
||||
.def.qualified_name;
|
||||
}
|
||||
else {
|
||||
info.kind = lsSymbolKind::Function;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryableVarDef& def = db->vars[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
info.kind = lsSymbolKind::Variable;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
case SymbolKind::Invalid: {
|
||||
assert(false && "unexpected");
|
||||
break;
|
||||
}
|
||||
};
|
||||
lsSymbolInformation info;
|
||||
info.location.range.start.line =
|
||||
ref.loc.line - 1; // TODO: cleanup indexer to negate by 1.
|
||||
info.location.range.start.character =
|
||||
ref.loc.column - 1; // TODO: cleanup indexer to negate by 1.
|
||||
// TODO: store range information.
|
||||
info.location.range.end.line = info.location.range.start.line;
|
||||
info.location.range.end.character =
|
||||
info.location.range.start.character;
|
||||
|
||||
response.result.push_back(info);
|
||||
// TODO: cleanup namespace/naming so there is only one SymbolKind.
|
||||
switch (symbol.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryableTypeDef& def = db->types[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
info.kind = lsSymbolKind::Class;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryableFuncDef& def = db->funcs[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
if (def.def.declaring_type.has_value()) {
|
||||
info.kind = lsSymbolKind::Method;
|
||||
Usr declaring = def.def.declaring_type.value();
|
||||
info.containerName =
|
||||
db->types[db->usr_to_symbol[declaring].idx]
|
||||
.def.qualified_name;
|
||||
}
|
||||
else {
|
||||
info.kind = lsSymbolKind::Function;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryableVarDef& def = db->vars[symbol.idx];
|
||||
info.name = def.def.qualified_name;
|
||||
info.kind = lsSymbolKind::Variable;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
case SymbolKind::Invalid: {
|
||||
assert(false && "unexpected");
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
response.result.push_back(info);
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
@ -459,46 +462,49 @@ void QueryDbMainLoop(
|
||||
lsDocumentUri file_as_uri = msg->params.textDocument.uri;
|
||||
|
||||
QueryableFile* file = FindFile(db, file_as_uri.GetPath());
|
||||
if (file) {
|
||||
for (UsrRef ref : file->outline) {
|
||||
SymbolIdx symbol = db->usr_to_symbol[ref.usr];
|
||||
switch (symbol.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryableTypeDef& def = db->types[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
true /*only_interesting*/, "reference",
|
||||
"references");
|
||||
AddCodeLens(&response.result, db, ref.loc, def.derived,
|
||||
false /*only_interesting*/, "derived", "derived");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryableFuncDef& def = db->funcs[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
false /*only_interesting*/, "reference",
|
||||
"references");
|
||||
AddCodeLens(&response.result, ref.loc, def.callers,
|
||||
false /*only_interesting*/, "caller", "callers");
|
||||
AddCodeLens(&response.result, ref.loc, def.def.callees,
|
||||
false /*only_interesting*/, "callee", "callees");
|
||||
AddCodeLens(&response.result, db, ref.loc, def.derived,
|
||||
false /*only_interesting*/, "derived", "derived");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryableVarDef& def = db->vars[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
false /*only_interesting*/, "reference",
|
||||
"references");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
case SymbolKind::Invalid: {
|
||||
assert(false && "unexpected");
|
||||
break;
|
||||
}
|
||||
};
|
||||
if (!file) {
|
||||
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
for (UsrRef ref : file->outline) {
|
||||
SymbolIdx symbol = db->usr_to_symbol[ref.usr];
|
||||
switch (symbol.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryableTypeDef& def = db->types[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
true /*only_interesting*/, "reference",
|
||||
"references");
|
||||
AddCodeLens(&response.result, db, ref.loc, def.derived,
|
||||
false /*only_interesting*/, "derived", "derived");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryableFuncDef& def = db->funcs[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
false /*only_interesting*/, "reference",
|
||||
"references");
|
||||
AddCodeLens(&response.result, ref.loc, def.callers,
|
||||
false /*only_interesting*/, "caller", "callers");
|
||||
AddCodeLens(&response.result, ref.loc, def.def.callees,
|
||||
false /*only_interesting*/, "callee", "callees");
|
||||
AddCodeLens(&response.result, db, ref.loc, def.derived,
|
||||
false /*only_interesting*/, "derived", "derived");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryableVarDef& def = db->vars[symbol.idx];
|
||||
AddCodeLens(&response.result, ref.loc, def.uses,
|
||||
false /*only_interesting*/, "reference",
|
||||
"references");
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
case SymbolKind::Invalid: {
|
||||
assert(false && "unexpected");
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
@ -693,7 +699,7 @@ void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
||||
|
||||
response.result.capabilities.completionProvider = lsCompletionOptions();
|
||||
response.result.capabilities.completionProvider->resolveProvider = false;
|
||||
response.result.capabilities.completionProvider->triggerCharacters = { ".", "::", "->", ":", ">" };
|
||||
response.result.capabilities.completionProvider->triggerCharacters = { ".", "::", "->" };
|
||||
|
||||
response.result.capabilities.codeLensProvider = lsCodeLensOptions();
|
||||
response.result.capabilities.codeLensProvider->resolveProvider = false;
|
||||
@ -724,6 +730,7 @@ void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
||||
case IpcId::TextDocumentDocumentSymbol:
|
||||
case IpcId::TextDocumentCodeLens:
|
||||
case IpcId::WorkspaceSymbol:
|
||||
std::cerr << "Spending message " << (int)message->method_id << std::endl;
|
||||
ipc->SendMessage(&ipc->for_server, message->method_id, *message.get());
|
||||
break;
|
||||
}
|
||||
|
@ -666,9 +666,8 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
IndexedFile* db = param->db;
|
||||
NamespaceHelper* ns = param->ns;
|
||||
|
||||
// std::cerr << "DECL kind=" << decl->entityInfo->kind << " at " <<
|
||||
// db->id_cache.Resolve(decl->cursor, false).ToPrettyString(&db->id_cache) <<
|
||||
// std::endl;
|
||||
|
||||
//std::cerr << "DECL kind=" << decl->entityInfo->kind << " at " << db->id_cache.Resolve(decl->cursor, false).ToPrettyString(&db->id_cache) << std::endl;
|
||||
|
||||
switch (decl->entityInfo->kind) {
|
||||
case CXIdxEntity_CXXNamespace: {
|
||||
@ -1197,21 +1196,11 @@ void indexEntityReference(CXClientData client_data,
|
||||
}
|
||||
}
|
||||
|
||||
void emptyIndexDeclaration(CXClientData client_data,
|
||||
const CXIdxDeclInfo* decl) {}
|
||||
void emptyIndexEntityReference(CXClientData client_data,
|
||||
const CXIdxEntityRefInfo* ref) {}
|
||||
|
||||
IndexedFile Parse(std::string filename,
|
||||
std::vector<std::string> args,
|
||||
bool dump_ast) {
|
||||
//clang_enableStackTraces();
|
||||
//clang_toggleCrashRecovery(1);
|
||||
|
||||
#if defined(_WIN32)
|
||||
args.push_back("-fms-compatibility");
|
||||
args.push_back("-fdelayed-template-parsing");
|
||||
#endif
|
||||
clang_enableStackTraces();
|
||||
clang_toggleCrashRecovery(1);
|
||||
|
||||
clang::Index index(0 /*excludeDeclarationsFromPCH*/,
|
||||
0 /*displayDiagnostics*/);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "TranslationUnit.h"
|
||||
#include "Tokens.h"
|
||||
#include "Utility.h"
|
||||
#include "../platform.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
@ -16,9 +17,12 @@ TranslationUnit::TranslationUnit(
|
||||
unsigned flags) {
|
||||
|
||||
std::vector<const char*> args;
|
||||
for (const std::string& a : arguments) {
|
||||
for (const std::string& a : arguments)
|
||||
args.push_back(a.c_str());
|
||||
}
|
||||
|
||||
std::vector<std::string> platform_args = GetPlatformClangArguments();
|
||||
for (const auto& arg : platform_args)
|
||||
args.push_back(arg.c_str());
|
||||
|
||||
CXErrorCode error_code = clang_parseTranslationUnit2(
|
||||
index.cx_index,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct PlatformMutex {
|
||||
virtual ~PlatformMutex();
|
||||
@ -26,3 +27,6 @@ std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
||||
void PlatformInit();
|
||||
std::string GetWorkingDirectory();
|
||||
std::string NormalizePath(const std::string& path);
|
||||
|
||||
// Returns any clang arguments that are specific to the current platform.
|
||||
std::vector<std::string> GetPlatformClangArguments();
|
@ -137,6 +137,14 @@ std::string NormalizePath(const std::string& path) {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetPlatformClangArguments() {
|
||||
// TODO: use install config variable for path?
|
||||
return {
|
||||
"-stdlib=libc++",
|
||||
"-nostdinc++",
|
||||
"-I/usr/local/Cellar/llvm/3.9.1/include"
|
||||
};
|
||||
}
|
||||
#undef CHECKED
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <io.h>
|
||||
#include <Windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -16,21 +17,21 @@ namespace {
|
||||
DWORD CheckForError(std::vector<DWORD> allow) {
|
||||
DWORD error = GetLastError();
|
||||
if (error == ERROR_SUCCESS ||
|
||||
std::find(allow.begin(), allow.end(), error) != allow.end())
|
||||
std::find(allow.begin(), allow.end(), error) != allow.end())
|
||||
return error;
|
||||
|
||||
// See http://stackoverflow.com/a/17387176
|
||||
LPSTR message_buffer = nullptr;
|
||||
size_t size = FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&message_buffer, 0, NULL);
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&message_buffer, 0, NULL);
|
||||
std::string message(message_buffer, size);
|
||||
LocalFree(message_buffer);
|
||||
|
||||
std::cerr << "Windows error code=" << error << ", message=" << message
|
||||
<< std::endl;
|
||||
<< std::endl;
|
||||
|
||||
assert(false); // debugger break
|
||||
exit(1);
|
||||
@ -42,7 +43,7 @@ struct PlatformMutexWin : public PlatformMutex {
|
||||
PlatformMutexWin(const std::string& name) {
|
||||
std::cerr << "[win] Creating mutex with name " << name << std::endl;
|
||||
raw_mutex = CreateMutex(nullptr, false /*initial_owner*/, name.c_str());
|
||||
CheckForError({ERROR_ALREADY_EXISTS});
|
||||
CheckForError({ ERROR_ALREADY_EXISTS });
|
||||
}
|
||||
|
||||
~PlatformMutexWin() override {
|
||||
@ -72,15 +73,15 @@ struct PlatformSharedMemoryWin : public PlatformSharedMemory {
|
||||
|
||||
PlatformSharedMemoryWin(const std::string& name, size_t capacity) {
|
||||
std::cerr << "[win] Creating shared memory with name " << name
|
||||
<< " and capacity " << capacity << std::endl;
|
||||
<< " and capacity " << capacity << std::endl;
|
||||
this->name = name;
|
||||
|
||||
shmem_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
|
||||
capacity, name.c_str());
|
||||
CheckForError({ERROR_ALREADY_EXISTS} /*allow*/);
|
||||
capacity, name.c_str());
|
||||
CheckForError({ ERROR_ALREADY_EXISTS } /*allow*/);
|
||||
|
||||
data = MapViewOfFile(shmem_, FILE_MAP_ALL_ACCESS, 0, 0, capacity);
|
||||
CheckForError({ERROR_ALREADY_EXISTS} /*allow*/);
|
||||
CheckForError({ ERROR_ALREADY_EXISTS } /*allow*/);
|
||||
|
||||
this->capacity = capacity;
|
||||
}
|
||||
@ -101,14 +102,14 @@ std::unique_ptr<PlatformMutex> CreatePlatformMutex(const std::string& name) {
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformScopedMutexLock> CreatePlatformScopedMutexLock(
|
||||
PlatformMutex* mutex) {
|
||||
PlatformMutex* mutex) {
|
||||
return MakeUnique<PlatformScopedMutexLockWin>(
|
||||
static_cast<PlatformMutexWin*>(mutex)->raw_mutex);
|
||||
static_cast<PlatformMutexWin*>(mutex)->raw_mutex);
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
||||
const std::string& name,
|
||||
size_t size) {
|
||||
const std::string& name,
|
||||
size_t size) {
|
||||
return MakeUnique<PlatformSharedMemoryWin>(name, size);
|
||||
}
|
||||
|
||||
@ -138,6 +139,15 @@ std::string NormalizePath(const std::string& path) {
|
||||
if (retval == 0)
|
||||
return path;
|
||||
|
||||
return buffer;
|
||||
std::string result = buffer;
|
||||
std::replace(result.begin(), result.end(), '\\', '/');
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetPlatformClangArguments() {
|
||||
return {
|
||||
"-fms-compatibility",
|
||||
"-fdelayed-template-parsing"
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user