This commit is contained in:
Jacob Dufault 2017-03-28 23:33:38 -07:00
parent cf1012b98c
commit a19d4f732f
8 changed files with 183 additions and 128 deletions

View File

@ -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 \

View File

@ -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 \

View File

@ -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,7 +391,12 @@ void QueryDbMainLoop(
response.id = msg->id;
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
if (file) {
if (!file) {
std::cerr << "Unable to find file " << msg->params.textDocument.uri.GetPath() << std::endl;
break;
}
std::cerr << "File outline size is " << file->outline.size() << std::endl;
for (UsrRef ref : file->outline) {
SymbolIdx symbol = db->usr_to_symbol[ref.usr];
@ -444,7 +448,6 @@ void QueryDbMainLoop(
response.result.push_back(info);
}
}
SendOutMessageToClient(language_client, response);
break;
@ -459,7 +462,11 @@ void QueryDbMainLoop(
lsDocumentUri file_as_uri = msg->params.textDocument.uri;
QueryableFile* file = FindFile(db, file_as_uri.GetPath());
if (file) {
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) {
@ -499,7 +506,6 @@ void QueryDbMainLoop(
}
};
}
}
SendOutMessageToClient(language_client, response);
break;
@ -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;
}

View File

@ -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*/);

View File

@ -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,

View File

@ -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();

View File

@ -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

View File

@ -7,6 +7,7 @@
#include <io.h>
#include <Windows.h>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
@ -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 {
@ -77,10 +78,10 @@ struct PlatformSharedMemoryWin : public PlatformSharedMemory {
shmem_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
capacity, name.c_str());
CheckForError({ERROR_ALREADY_EXISTS} /*allow*/);
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;
}
@ -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