spaces -> tabs
This commit is contained in:
parent
7b73793d58
commit
6a13723533
120
client.d
120
client.d
|
@ -32,28 +32,28 @@ import messages;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
size_t cursorPos = size_t.max;
|
size_t cursorPos = size_t.max;
|
||||||
string[] importPaths;
|
string[] importPaths;
|
||||||
ushort port = 9166;
|
ushort port = 9166;
|
||||||
bool help;
|
bool help;
|
||||||
bool shutdown;
|
bool shutdown;
|
||||||
bool clearCache;
|
bool clearCache;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getopt(args, "cursorPos|c", &cursorPos, "I", &importPaths,
|
getopt(args, "cursorPos|c", &cursorPos, "I", &importPaths,
|
||||||
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
|
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
|
||||||
"clearCache", &clearCache);
|
"clearCache", &clearCache);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
stderr.writeln(e.msg);
|
stderr.writeln(e.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (help)
|
if (help)
|
||||||
{
|
{
|
||||||
printHelp(args[0]);
|
printHelp(args[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (shutdown || clearCache)
|
else if (shutdown || clearCache)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,7 @@ int main(string[] args)
|
||||||
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
||||||
messageBuffer[8 .. $] = message[];
|
messageBuffer[8 .. $] = message[];
|
||||||
return socket.send(messageBuffer) == messageBuffer.length ? 0 : 1;
|
return socket.send(messageBuffer) == messageBuffer.length ? 0 : 1;
|
||||||
}
|
}
|
||||||
else if (importPaths.length > 0)
|
else if (importPaths.length > 0)
|
||||||
{
|
{
|
||||||
AutocompleteRequest request;
|
AutocompleteRequest request;
|
||||||
|
@ -90,25 +90,25 @@ int main(string[] args)
|
||||||
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
||||||
messageBuffer[8 .. $] = message[];
|
messageBuffer[8 .. $] = message[];
|
||||||
return socket.send(messageBuffer) == messageBuffer.length ? 0 : 1;
|
return socket.send(messageBuffer) == messageBuffer.length ? 0 : 1;
|
||||||
}
|
}
|
||||||
else if (cursorPos == size_t.max)
|
else if (cursorPos == size_t.max)
|
||||||
{
|
{
|
||||||
// cursor position is a required argument
|
// cursor position is a required argument
|
||||||
printHelp(args[0]);
|
printHelp(args[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read in the source
|
// Read in the source
|
||||||
bool usingStdin = args.length <= 1;
|
bool usingStdin = args.length <= 1;
|
||||||
string fileName = usingStdin ? "stdin" : args[1];
|
string fileName = usingStdin ? "stdin" : args[1];
|
||||||
if (!usingStdin && !exists(args[1]))
|
if (!usingStdin && !exists(args[1]))
|
||||||
{
|
{
|
||||||
stderr.writefln("%s does not exist");
|
stderr.writefln("%s does not exist");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
File f = usingStdin ? stdin : File(args[1]);
|
File f = usingStdin ? stdin : File(args[1]);
|
||||||
ubyte[] sourceCode;
|
ubyte[] sourceCode;
|
||||||
if (usingStdin)
|
if (usingStdin)
|
||||||
{
|
{
|
||||||
ubyte[4096] buf;
|
ubyte[4096] buf;
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -125,36 +125,36 @@ int main(string[] args)
|
||||||
f.rawRead(sourceCode);
|
f.rawRead(sourceCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create message
|
// Create message
|
||||||
AutocompleteRequest request;
|
AutocompleteRequest request;
|
||||||
request.fileName = fileName;
|
request.fileName = fileName;
|
||||||
request.importPaths = importPaths;
|
request.importPaths = importPaths;
|
||||||
request.sourceCode = sourceCode;
|
request.sourceCode = sourceCode;
|
||||||
request.cursorPosition = cursorPos;
|
request.cursorPosition = cursorPos;
|
||||||
ubyte[] message = msgpack.pack(request);
|
ubyte[] message = msgpack.pack(request);
|
||||||
|
|
||||||
// Send message to server
|
// Send message to server
|
||||||
TcpSocket socket = new TcpSocket(AddressFamily.INET);
|
TcpSocket socket = new TcpSocket(AddressFamily.INET);
|
||||||
socket.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, dur!"seconds"(5));
|
socket.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, dur!"seconds"(5));
|
||||||
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
||||||
socket.connect(new InternetAddress("127.0.0.1", port));
|
socket.connect(new InternetAddress("127.0.0.1", port));
|
||||||
socket.blocking = true;
|
socket.blocking = true;
|
||||||
ubyte[] messageBuffer = new ubyte[message.length + message.length.sizeof];
|
ubyte[] messageBuffer = new ubyte[message.length + message.length.sizeof];
|
||||||
auto messageLength = message.length;
|
auto messageLength = message.length;
|
||||||
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
messageBuffer[0 .. 8] = (cast(ubyte*) &messageLength)[0 .. 8];
|
||||||
messageBuffer[8 .. $] = message[];
|
messageBuffer[8 .. $] = message[];
|
||||||
auto bytesSent = socket.send(messageBuffer);
|
auto bytesSent = socket.send(messageBuffer);
|
||||||
|
|
||||||
// Get response and write it out
|
// Get response and write it out
|
||||||
ubyte[1024 * 16] buffer;
|
ubyte[1024 * 16] buffer;
|
||||||
auto bytesReceived = socket.receive(buffer);
|
auto bytesReceived = socket.receive(buffer);
|
||||||
if (bytesReceived == Socket.ERROR)
|
if (bytesReceived == Socket.ERROR)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutocompleteResponse response;
|
AutocompleteResponse response;
|
||||||
msgpack.unpack(buffer[0..bytesReceived], response);
|
msgpack.unpack(buffer[0..bytesReceived], response);
|
||||||
|
|
||||||
if (response.completions.length > 0)
|
if (response.completions.length > 0)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +174,7 @@ int main(string[] args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printHelp(string programName)
|
void printHelp(string programName)
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct CacheEntry
|
||||||
*/
|
*/
|
||||||
struct ModuleCache
|
struct ModuleCache
|
||||||
{
|
{
|
||||||
@disable this();
|
@disable this();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the completion cache
|
* Clears the completion cache
|
||||||
|
@ -150,18 +150,18 @@ private:
|
||||||
* Returns:
|
* Returns:
|
||||||
* true if the module needs to be reparsed, false otherwise
|
* true if the module needs to be reparsed, false otherwise
|
||||||
*/
|
*/
|
||||||
static bool needsReparsing(string mod)
|
static bool needsReparsing(string mod)
|
||||||
{
|
{
|
||||||
if (!exists(mod) || mod !in cache)
|
if (!exists(mod) || mod !in cache)
|
||||||
return true;
|
return true;
|
||||||
SysTime access;
|
SysTime access;
|
||||||
SysTime modification;
|
SysTime modification;
|
||||||
getTimes(mod, access, modification);
|
getTimes(mod, access, modification);
|
||||||
return cache[mod].modificationTime != modification;
|
return cache[mod].modificationTime != modification;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapping of file paths to their cached symbols.
|
// Mapping of file paths to their cached symbols.
|
||||||
static CacheEntry[string] cache;
|
static CacheEntry[string] cache;
|
||||||
|
|
||||||
// Listing of paths to check for imports
|
// Listing of paths to check for imports
|
||||||
static string[] importPaths;
|
static string[] importPaths;
|
||||||
|
|
Loading…
Reference in New Issue