diff --git a/client.d b/client.d index cab3d6b..5c3469a 100644 --- a/client.d +++ b/client.d @@ -57,6 +57,8 @@ int main(string[] args) return 1; } + AutocompleteRequest request; + if (help) { printHelp(args[0]); @@ -64,7 +66,6 @@ int main(string[] args) } else if (shutdown || clearCache) { - AutocompleteRequest request; if (shutdown) request.kind = RequestKind.shutdown; else if (clearCache) @@ -73,6 +74,19 @@ int main(string[] args) scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); } return sendRequest(socket, request) ? 0 : 1; } + else if (importPaths.length > 0) + { + request.kind |= RequestKind.addImport; + request.importPaths = importPaths.map!(a => absolutePath(a)).array; + if (cursorPos == size_t.max) + { + TcpSocket socket = createSocket(port); + scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); } + if (!sendRequest(socket, request)) + return 1; + return 0; + } + } else if (cursorPos == size_t.max) { // cursor position is a required argument @@ -107,19 +121,11 @@ int main(string[] args) f.rawRead(sourceCode); } - // Create message - AutocompleteRequest request; request.fileName = fileName; request.importPaths = importPaths; request.sourceCode = sourceCode; request.cursorPosition = cursorPos; - if (importPaths.length > 0) - { - request.kind |= RequestKind.addImport; - request.importPaths = importPaths.map!(a => absolutePath(a)).array; - } - if (symbolLocation) request.kind |= RequestKind.symbolLocation; else if (doc) diff --git a/modulecache.d b/modulecache.d index 05e4310..1fe21c9 100644 --- a/modulecache.d +++ b/modulecache.d @@ -141,7 +141,10 @@ struct ModuleCache import std.stdio; import std.typecons; File f = File(cachedLocation); - ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(cast(size_t)f.size); + immutable fileSize = cast(size_t)f.size; + if (fileSize == 0) + return symbols; + ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(fileSize); f.rawRead(source); LexerConfig config; config.fileName = cachedLocation; diff --git a/server.d b/server.d index d14cdd0..f630d45 100644 --- a/server.d +++ b/server.d @@ -145,8 +145,6 @@ int main(string[] args) AutocompleteRequest request; msgpack.unpack(buffer[size_t.sizeof .. bytesReceived], request); - if (request.kind & RequestKind.addImport) - ModuleCache.addImportPaths(request.importPaths); if (request.kind & RequestKind.clearCache) { Log.info("Clearing cache."); @@ -157,6 +155,8 @@ int main(string[] args) Log.info("Shutting down."); break serverLoop; } + if (request.kind & RequestKind.addImport) + ModuleCache.addImportPaths(request.importPaths); else if (request.kind & RequestKind.autocomplete) { Log.info("Getting completions");