From cf1012b98c571d54406b7a45aa6c16e08a943384 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Mon, 27 Mar 2017 22:27:06 -0700 Subject: [PATCH] small fixes --- src/compilation_database_loader.cc | 12 +++++------- src/compilation_database_loader.h | 1 - src/indexer.cpp | 7 ++----- src/language_server_api.cc | 10 ++++++++++ src/platform_win.cc | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/compilation_database_loader.cc b/src/compilation_database_loader.cc index ddd4638b..4a9dda2e 100644 --- a/src/compilation_database_loader.cc +++ b/src/compilation_database_loader.cc @@ -41,8 +41,7 @@ std::vector LoadFromDirectoryListing(const std::string& projec EndsWith(file, ".hpp")) { CompilationEntry entry; - entry.directory = project_directory; - entry.filename = file; + entry.filename = NormalizePath(file); entry.args = args; result.push_back(entry); } @@ -145,11 +144,10 @@ std::vector LoadCompilationEntriesFromDirectory(const std::str 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); + std::string directory = clang::ToString(clang_CompileCommand_getDirectory(cx_command)); + std::string relative_filename = clang::ToString(clang_CompileCommand_getFilename(cx_command)); + std::string absolute_filename = directory + "/" + relative_filename; + entry.filename = NormalizePath(absolute_filename); unsigned int num_args = clang_CompileCommand_getNumArgs(cx_command); entry.args.reserve(num_args); diff --git a/src/compilation_database_loader.h b/src/compilation_database_loader.h index cbb5638a..96d12dde 100644 --- a/src/compilation_database_loader.h +++ b/src/compilation_database_loader.h @@ -4,7 +4,6 @@ #include struct CompilationEntry { - std::string directory; std::string filename; std::vector args; }; diff --git a/src/indexer.cpp b/src/indexer.cpp index 05f4a850..7a07c949 100644 --- a/src/indexer.cpp +++ b/src/indexer.cpp @@ -1208,13 +1208,10 @@ IndexedFile Parse(std::string filename, //clang_enableStackTraces(); //clang_toggleCrashRecovery(1); - args.push_back("-std=c++11"); +#if defined(_WIN32) args.push_back("-fms-compatibility"); args.push_back("-fdelayed-template-parsing"); - // args.push_back("-isystem - // C:\\Users\\jacob\\Desktop\\superindex\\indexer\\libcxx-3.9.1\\include"); - // args.push_back("--sysroot - // C:\\Users\\jacob\\Desktop\\superindex\\indexer\\libcxx-3.9.1"); +#endif clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/); diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 5d5be350..6136558d 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -126,7 +126,12 @@ void lsDocumentUri::SetPath(const std::string& path) { raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1, "%3A"); } + // TODO: proper fix +#if defined(_WIN32) + raw_uri = "file:///" + raw_uri; +#else raw_uri = "file://" + raw_uri; +#endif //std::cerr << "Set uri to " << raw_uri << " from " << path; } @@ -141,7 +146,12 @@ std::string lsDocumentUri::GetPath() const { index = result.find("file://"); if (index != -1) { +// TODO: proper fix +#if defined(_WIN32) + result.replace(result.begin() + index, result.begin() + index + 8, ""); +#else result.replace(result.begin() + index, result.begin() + index + 7, ""); +#endif } std::replace(result.begin(), result.end(), '\\', '/'); diff --git a/src/platform_win.cc b/src/platform_win.cc index 917a6cb1..65e3c33f 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -125,4 +125,19 @@ std::string GetWorkingDirectory() { char result[MAX_PATH]; return std::string(result, GetModuleFileName(NULL, result, MAX_PATH)); } + +std::string NormalizePath(const std::string& path) { + DWORD retval = 0; + BOOL success = false; + TCHAR buffer[MAX_PATH] = TEXT(""); + TCHAR buf[MAX_PATH] = TEXT(""); + TCHAR** lpp_part = { NULL }; + + retval = GetFullPathName(path.c_str(), MAX_PATH, buffer, lpp_part); + // fail, return original + if (retval == 0) + return path; + + return buffer; +} #endif