Fix #29
This commit is contained in:
parent
68949ee04e
commit
ebb608bba5
43
client.d
43
client.d
|
@ -28,48 +28,11 @@ import std.path;
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.string;
|
import std.string;
|
||||||
//version(Windows)
|
|
||||||
//{
|
|
||||||
// import core.runtime;
|
|
||||||
// import core.sys.windows.windows;
|
|
||||||
// import std.string;
|
|
||||||
//}
|
|
||||||
import msgpack;
|
import msgpack;
|
||||||
import messages;
|
import messages;
|
||||||
|
|
||||||
//version(Windows)
|
int main(string[] args)
|
||||||
//{
|
|
||||||
// extern(Windows) int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
|
||||||
// {
|
|
||||||
// int result;
|
|
||||||
// void exceptionHandler(Throwable e) {
|
|
||||||
// throw e;
|
|
||||||
// }
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// Runtime.
|
|
||||||
// Runtime.initialize(&exceptionHandler);
|
|
||||||
// result = _main(["dcd-client"] ~ to!string(lpCmdLine).split(" ").array());
|
|
||||||
// Runtime.terminate(&exceptionHandler);
|
|
||||||
// }
|
|
||||||
// catch (Throwable e) // catch any uncaught exceptions
|
|
||||||
// {
|
|
||||||
// MessageBoxA(null, e.toString().toStringz(), "Error",
|
|
||||||
// MB_OK | MB_ICONEXCLAMATION);
|
|
||||||
// result = 0; // failed
|
|
||||||
// }
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// int main(string[] args)
|
|
||||||
// {
|
|
||||||
// return _main(args);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
int /*_*/main(string[] args)
|
|
||||||
{
|
{
|
||||||
size_t cursorPos = size_t.max;
|
size_t cursorPos = size_t.max;
|
||||||
string[] importPaths;
|
string[] importPaths;
|
||||||
|
@ -110,7 +73,7 @@ int /*_*/main(string[] args)
|
||||||
{
|
{
|
||||||
AutocompleteRequest request;
|
AutocompleteRequest request;
|
||||||
request.kind = RequestKind.addImport;
|
request.kind = RequestKind.addImport;
|
||||||
request.importPaths = importPaths.map!(a => isRooted(a) ? a : absolutePath(a)).array;
|
request.importPaths = importPaths.map!(a => absolutePath(a)).array;
|
||||||
TcpSocket socket = createSocket(port);
|
TcpSocket socket = createSocket(port);
|
||||||
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
||||||
return sendRequest(socket, request) ? 0 : 1;
|
return sendRequest(socket, request) ? 0 : 1;
|
||||||
|
|
70
server.d
70
server.d
|
@ -25,6 +25,7 @@ import std.algorithm;
|
||||||
import std.path;
|
import std.path;
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.array;
|
import std.array;
|
||||||
|
import std.process;
|
||||||
|
|
||||||
import msgpack;
|
import msgpack;
|
||||||
|
|
||||||
|
@ -32,17 +33,17 @@ import messages;
|
||||||
import autocomplete;
|
import autocomplete;
|
||||||
import modulecache;
|
import modulecache;
|
||||||
|
|
||||||
version(Posix)
|
enum CONFIG_FILE_NAME = "dcd.conf";
|
||||||
{
|
|
||||||
enum CONFIG_FILE_PATH = "~/.config/dcd";
|
version(linux) version = useXDG;
|
||||||
}
|
version(BSD) version = useXDG;
|
||||||
else version(Windows)
|
version(FreeBSD) version = useXDG;
|
||||||
{
|
|
||||||
enum CONFIG_FILE_PATH = "dcd.conf";
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
|
// No relative paths
|
||||||
|
version (Posix) chdir("/");
|
||||||
|
|
||||||
ushort port = 9166;
|
ushort port = 9166;
|
||||||
bool help;
|
bool help;
|
||||||
string[] importPaths;
|
string[] importPaths;
|
||||||
|
@ -141,21 +142,50 @@ int main(string[] args)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getConfigurationLocation()
|
||||||
|
{
|
||||||
|
version (useXDG)
|
||||||
|
{
|
||||||
|
string configDir = environment.get("XDG_CONFIG_HOME", null);
|
||||||
|
if (configDir is null)
|
||||||
|
{
|
||||||
|
configDir = environment.get("HOME", null);
|
||||||
|
if (configDir is null)
|
||||||
|
throw new Exception("Both $XDG_CONFIG_HOME and $HOME are unset");
|
||||||
|
configDir = buildPath(configDir, ".config", "dcd", CONFIG_FILE_NAME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
configDir = buildPath(configDir, "dcd", CONFIG_FILE_NAME);
|
||||||
|
}
|
||||||
|
return configDir;
|
||||||
|
}
|
||||||
|
else version(Windows)
|
||||||
|
{
|
||||||
|
return CONFIG_FILE_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void warnAboutOldConfigLocation()
|
||||||
|
{
|
||||||
|
version (linux) if ("~/.config/dcd".expandTilde().isFile())
|
||||||
|
{
|
||||||
|
writeln("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
writeln("!! Upgrade warning:");
|
||||||
|
writeln("!! '~/.config/dcd' should be moved to '$XDG_CONFIG_HOME/dcd/dcd.conf'");
|
||||||
|
writeln("!! or '$HOME/.config/dcd/dcd.conf'");
|
||||||
|
writeln("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string[] loadConfiguredImportDirs()
|
string[] loadConfiguredImportDirs()
|
||||||
{
|
{
|
||||||
version(Windows)
|
warnAboutOldConfigLocation();
|
||||||
{
|
immutable string configLocation = getConfigurationLocation();
|
||||||
string fullPath = buildPath(getcwd(), CONFIG_FILE_PATH);
|
if (!configLocation.exists())
|
||||||
}
|
|
||||||
else version(Posix)
|
|
||||||
{
|
|
||||||
string fullPath = expandTilde(CONFIG_FILE_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exists(fullPath))
|
|
||||||
return [];
|
return [];
|
||||||
|
writeln("Loading configuration from ", configLocation);
|
||||||
File f = File(fullPath, "rt");
|
File f = File(configLocation, "rt");
|
||||||
return f.byLine(KeepTerminator.no).map!(a => a.idup).filter!(a => a.exists()).array();
|
return f.byLine(KeepTerminator.no).map!(a => a.idup).filter!(a => a.exists()).array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue