move platform init code to platform

This commit is contained in:
Jacob Dufault 2017-03-25 13:27:28 -07:00
parent 5d922a1e90
commit b6978b1a38
4 changed files with 36 additions and 34 deletions

View File

@ -1,33 +1,30 @@
// TODO: cleanup includes
#include "compilation_database_loader.h"
#include "indexer.h"
#include "query.h"
#include "language_server_api.h"
#include "platform.h"
#include "test.h"
#include "timer.h"
#include "threaded_queue.h"
#include "typed_bidi_message_queue.h"
#include <doctest/doctest.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <doctest/doctest.h> namespace {
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
// TODO: cleanup includes
#include "compilation_database_loader.h"
#include "indexer.h"
#include "query.h"
#include "language_server_api.h"
#include "test.h"
#include "timer.h"
#include "threaded_queue.h"
#include "typed_bidi_message_queue.h"
// TODO: move to platform
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
const char* kIpcLanguageClientName = "language_client"; const char* kIpcLanguageClientName = "language_client";
const int kNumIndexers = 8 - 1; const int kNumIndexers = 8 - 1;
const int kQueueSizeBytes = 1024 * 1024 * 32; const int kQueueSizeBytes = 1024 * 1024 * 32;
}
struct IndexTranslationUnitRequest { struct IndexTranslationUnitRequest {
std::string path; std::string path;
@ -910,22 +907,12 @@ void LanguageServerMain(std::string process_name) {
} }
} }
void PreMain() {
// We need to write to stdout in binary mode because in Windows, writing
// \n will implicitly write \r\n. Language server API will ignore a
// \r\r\n split request.
#ifdef _WIN32
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
#endif
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
bool loop = false; bool loop = false;
while (loop) while (loop)
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
PreMain(); PlatformInit();
RegisterMessageTypes(); RegisterMessageTypes();
// if (argc == 1) { // if (argc == 1) {

View File

@ -23,4 +23,5 @@ std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
const std::string& name, const std::string& name,
size_t size); size_t size);
void PlatformInit();
std::string GetWorkingDirectory(); std::string GetWorkingDirectory();

View File

@ -118,6 +118,9 @@ std::unique_ptr<PlatformScopedMutexLock> CreatePlatformScopedMutexLock(
static_cast<PlatformMutexLinux*>(mutex)->sem_); static_cast<PlatformMutexLinux*>(mutex)->sem_);
} }
void PlatformInit() {
}
std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory( std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
const std::string& name, size_t size) { const std::string& name, size_t size) {
std::string name2 = "/" + name; std::string name2 = "/" + name;

View File

@ -1,12 +1,15 @@
#if defined(_WIN32) #if defined(_WIN32)
#include "platform.h" #include "platform.h"
#include "utils.h"
#include <fcntl.h>
#include <io.h>
#include <Windows.h>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <Windows.h>
#include "utils.h"
namespace { namespace {
@ -108,6 +111,14 @@ std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
return MakeUnique<PlatformSharedMemoryWin>(name, size); return MakeUnique<PlatformSharedMemoryWin>(name, size);
} }
void PlatformInit() {
// We need to write to stdout in binary mode because in Windows, writing
// \n will implicitly write \r\n. Language server API will ignore a
// \r\r\n split request.
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
}
// See http://stackoverflow.com/a/19535628 // See http://stackoverflow.com/a/19535628
std::string GetWorkingDirectory() { std::string GetWorkingDirectory() {
char result[MAX_PATH]; char result[MAX_PATH];