diff --git a/src/client/client.d b/src/client/client.d index aea6570..8d37826 100644 --- a/src/client/client.d +++ b/src/client/client.d @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -module client; +module client.client; import std.socket; import std.stdio; @@ -31,8 +31,8 @@ import std.string; import std.experimental.logger; import msgpack; -import messages; -import dcd_version; +import common.messages; +import common.dcd_version; int main(string[] args) { @@ -46,6 +46,7 @@ int main(string[] args) bool doc; bool query; bool printVersion; + bool listImports; string search; try @@ -54,7 +55,7 @@ int main(string[] args) "port|p", &port, "help|h", &help, "shutdown", &shutdown, "clearCache", &clearCache, "symbolLocation|l", &symbolLocation, "doc|d", &doc, "query|status|q", &query, "search|s", &search, - "version", &printVersion); + "version", &printVersion, "listImports", &listImports); } catch (ConvException e) { @@ -126,6 +127,16 @@ int main(string[] args) return 0; } } + else if (listImports) + { + request.kind |= RequestKind.listImports; + TcpSocket socket = createSocket(port); + scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); } + sendRequest(socket, request); + AutocompleteResponse response = getResponse(socket); + printImportList(response); + return 0; + } else if (search == null && cursorPos == size_t.max) { // cursor position is a required argument @@ -342,3 +353,10 @@ void printSearchResponse(const AutocompleteResponse response) response.locations[i]); } } + +void printImportList(const AutocompleteResponse response) +{ + import std.algorithm.iteration : each; + + response.importPaths.each!(a => writeln(a)); +} diff --git a/src/common/constants.d b/src/common/constants.d index d8947c7..34ec955 100644 --- a/src/common/constants.d +++ b/src/common/constants.d @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -module constants; +module common.constants; // The lists in this module should be kept sorted. diff --git a/src/common/dcd_version.d b/src/common/dcd_version.d index 0c1147b..4951c8e 100644 --- a/src/common/dcd_version.d +++ b/src/common/dcd_version.d @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -module dcd_version; +module common.dcd_version; /** * Human-readable version number */ -enum DCD_VERSION = "v0.6.1-dev"; +enum DCD_VERSION = "v0.7.0-alpha"; version (Windows) {} else diff --git a/src/common/messages.d b/src/common/messages.d index 88c352b..f1b0d95 100644 --- a/src/common/messages.d +++ b/src/common/messages.d @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -module messages; +module common.messages; /** * The type of completion list being returned @@ -42,31 +42,37 @@ enum CompletionType : string /** * The response contains documentation comments for the symbol. */ - ddoc = "ddoc" + ddoc = "ddoc", } /** * Request kind */ -enum RequestKind : ubyte +enum RequestKind : ushort { - uninitialized = 0b00000000, + // dfmt off + + uninitialized = 0b00000000_00000000, /// Autocompletion - autocomplete = 0b00000001, + autocomplete = 0b00000000_00000001, /// Clear the completion cache - clearCache = 0b00000010, + clearCache = 0b00000000_00000010, /// Add import directory to server - addImport = 0b00000100, + addImport = 0b00000000_00000100, /// Shut down the server - shutdown = 0b00001000, + shutdown = 0b00000000_00001000, /// Get declaration location of given symbol - symbolLocation = 0b00010000, + symbolLocation = 0b00000000_00010000, /// Get the doc comments for the symbol - doc = 0b00100000, + doc = 0b00000000_00100000, /// Query server status - query = 0b01000000, + query = 0b00000000_01000000, /// Search for symbol - search = 0b10000000, + search = 0b00000000_10000000, + /// List import directories + listImports = 0b00000001_00000000, + + // dfmt on } /** @@ -145,4 +151,9 @@ struct AutocompleteResponse * Symbol locations for symbol searches. */ size_t[] locations; + + /** + * Import paths that are registered by the server. + */ + string[] importPaths; } diff --git a/src/server/autocomplete.d b/src/server/autocomplete.d index 98baee9..3c8f250 100644 --- a/src/server/autocomplete.d +++ b/src/server/autocomplete.d @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -module autocomplete; +module server.autocomplete; import std.algorithm; import std.allocator; @@ -45,8 +45,8 @@ import dsymbol.builtin.symbols; import memory.allocators; -import constants; -import messages; +import common.constants; +import common.messages; /** * Gets documentation for the symbol at the cursor diff --git a/src/server/server.d b/src/server/server.d index 7ae2014..e290abb 100644 --- a/src/server/server.d +++ b/src/server/server.d @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -module server; +module server.server; import std.socket; import std.stdio; @@ -36,11 +36,11 @@ import msgpack; import dsymbol.string_interning; -import messages; -import autocomplete; +import common.messages; +import server.autocomplete; import dsymbol.modulecache; import dsymbol.symbol; -import dcd_version; +import common.dcd_version; /// Name of the server configuration file enum CONFIG_FILE_NAME = "dcd.conf"; @@ -147,7 +147,7 @@ int main(string[] args) (cast(ubyte*) &messageLength)[0..size_t.sizeof] = buffer[0..size_t.sizeof]; while (bytesReceived < messageLength + size_t.sizeof) { - auto b = s.receive(buffer[bytesReceived .. $]); + immutable b = s.receive(buffer[bytesReceived .. $]); if (b == Socket.ERROR) { bytesReceived = Socket.ERROR; @@ -180,12 +180,21 @@ int main(string[] args) response.completionType = "ack"; ubyte[] responseBytes = msgpack.pack(response); s.send(responseBytes); + continue; } if (request.kind & RequestKind.addImport) { ModuleCache.addImportPaths(request.importPaths); } - if (request.kind & RequestKind.autocomplete) + if (request.kind & RequestKind.listImports) + { + AutocompleteResponse response; + response.importPaths = ModuleCache.getImportPaths().array(); + ubyte[] responseBytes = msgpack.pack(response); + info("Returning import path list"); + s.send(responseBytes); + } + else if (request.kind & RequestKind.autocomplete) { info("Getting completions"); AutocompleteResponse response = complete(request);