Fix #222
This commit is contained in:
parent
724aa4fd09
commit
7bbe4ddf39
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module client;
|
module client.client;
|
||||||
|
|
||||||
import std.socket;
|
import std.socket;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
@ -31,8 +31,8 @@ import std.string;
|
||||||
import std.experimental.logger;
|
import std.experimental.logger;
|
||||||
|
|
||||||
import msgpack;
|
import msgpack;
|
||||||
import messages;
|
import common.messages;
|
||||||
import dcd_version;
|
import common.dcd_version;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,7 @@ int main(string[] args)
|
||||||
bool doc;
|
bool doc;
|
||||||
bool query;
|
bool query;
|
||||||
bool printVersion;
|
bool printVersion;
|
||||||
|
bool listImports;
|
||||||
string search;
|
string search;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -54,7 +55,7 @@ int main(string[] args)
|
||||||
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
|
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
|
||||||
"clearCache", &clearCache, "symbolLocation|l", &symbolLocation,
|
"clearCache", &clearCache, "symbolLocation|l", &symbolLocation,
|
||||||
"doc|d", &doc, "query|status|q", &query, "search|s", &search,
|
"doc|d", &doc, "query|status|q", &query, "search|s", &search,
|
||||||
"version", &printVersion);
|
"version", &printVersion, "listImports", &listImports);
|
||||||
}
|
}
|
||||||
catch (ConvException e)
|
catch (ConvException e)
|
||||||
{
|
{
|
||||||
|
@ -126,6 +127,16 @@ int main(string[] args)
|
||||||
return 0;
|
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)
|
else if (search == null && cursorPos == size_t.max)
|
||||||
{
|
{
|
||||||
// cursor position is a required argument
|
// cursor position is a required argument
|
||||||
|
@ -342,3 +353,10 @@ void printSearchResponse(const AutocompleteResponse response)
|
||||||
response.locations[i]);
|
response.locations[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printImportList(const AutocompleteResponse response)
|
||||||
|
{
|
||||||
|
import std.algorithm.iteration : each;
|
||||||
|
|
||||||
|
response.importPaths.each!(a => writeln(a));
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module constants;
|
module common.constants;
|
||||||
|
|
||||||
// The lists in this module should be kept sorted.
|
// The lists in this module should be kept sorted.
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module dcd_version;
|
module common.dcd_version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Human-readable version number
|
* Human-readable version number
|
||||||
*/
|
*/
|
||||||
enum DCD_VERSION = "v0.6.1-dev";
|
enum DCD_VERSION = "v0.7.0-alpha";
|
||||||
|
|
||||||
version (Windows) {}
|
version (Windows) {}
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module messages;
|
module common.messages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of completion list being returned
|
* The type of completion list being returned
|
||||||
|
@ -42,31 +42,37 @@ enum CompletionType : string
|
||||||
/**
|
/**
|
||||||
* The response contains documentation comments for the symbol.
|
* The response contains documentation comments for the symbol.
|
||||||
*/
|
*/
|
||||||
ddoc = "ddoc"
|
ddoc = "ddoc",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request kind
|
* Request kind
|
||||||
*/
|
*/
|
||||||
enum RequestKind : ubyte
|
enum RequestKind : ushort
|
||||||
{
|
{
|
||||||
uninitialized = 0b00000000,
|
// dfmt off
|
||||||
|
|
||||||
|
uninitialized = 0b00000000_00000000,
|
||||||
/// Autocompletion
|
/// Autocompletion
|
||||||
autocomplete = 0b00000001,
|
autocomplete = 0b00000000_00000001,
|
||||||
/// Clear the completion cache
|
/// Clear the completion cache
|
||||||
clearCache = 0b00000010,
|
clearCache = 0b00000000_00000010,
|
||||||
/// Add import directory to server
|
/// Add import directory to server
|
||||||
addImport = 0b00000100,
|
addImport = 0b00000000_00000100,
|
||||||
/// Shut down the server
|
/// Shut down the server
|
||||||
shutdown = 0b00001000,
|
shutdown = 0b00000000_00001000,
|
||||||
/// Get declaration location of given symbol
|
/// Get declaration location of given symbol
|
||||||
symbolLocation = 0b00010000,
|
symbolLocation = 0b00000000_00010000,
|
||||||
/// Get the doc comments for the symbol
|
/// Get the doc comments for the symbol
|
||||||
doc = 0b00100000,
|
doc = 0b00000000_00100000,
|
||||||
/// Query server status
|
/// Query server status
|
||||||
query = 0b01000000,
|
query = 0b00000000_01000000,
|
||||||
/// Search for symbol
|
/// 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.
|
* Symbol locations for symbol searches.
|
||||||
*/
|
*/
|
||||||
size_t[] locations;
|
size_t[] locations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import paths that are registered by the server.
|
||||||
|
*/
|
||||||
|
string[] importPaths;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module autocomplete;
|
module server.autocomplete;
|
||||||
|
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.allocator;
|
import std.allocator;
|
||||||
|
@ -45,8 +45,8 @@ import dsymbol.builtin.symbols;
|
||||||
|
|
||||||
import memory.allocators;
|
import memory.allocators;
|
||||||
|
|
||||||
import constants;
|
import common.constants;
|
||||||
import messages;
|
import common.messages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets documentation for the symbol at the cursor
|
* Gets documentation for the symbol at the cursor
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module server;
|
module server.server;
|
||||||
|
|
||||||
import std.socket;
|
import std.socket;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
@ -36,11 +36,11 @@ import msgpack;
|
||||||
|
|
||||||
import dsymbol.string_interning;
|
import dsymbol.string_interning;
|
||||||
|
|
||||||
import messages;
|
import common.messages;
|
||||||
import autocomplete;
|
import server.autocomplete;
|
||||||
import dsymbol.modulecache;
|
import dsymbol.modulecache;
|
||||||
import dsymbol.symbol;
|
import dsymbol.symbol;
|
||||||
import dcd_version;
|
import common.dcd_version;
|
||||||
|
|
||||||
/// Name of the server configuration file
|
/// Name of the server configuration file
|
||||||
enum CONFIG_FILE_NAME = "dcd.conf";
|
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];
|
(cast(ubyte*) &messageLength)[0..size_t.sizeof] = buffer[0..size_t.sizeof];
|
||||||
while (bytesReceived < messageLength + 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)
|
if (b == Socket.ERROR)
|
||||||
{
|
{
|
||||||
bytesReceived = Socket.ERROR;
|
bytesReceived = Socket.ERROR;
|
||||||
|
@ -180,12 +180,21 @@ int main(string[] args)
|
||||||
response.completionType = "ack";
|
response.completionType = "ack";
|
||||||
ubyte[] responseBytes = msgpack.pack(response);
|
ubyte[] responseBytes = msgpack.pack(response);
|
||||||
s.send(responseBytes);
|
s.send(responseBytes);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (request.kind & RequestKind.addImport)
|
if (request.kind & RequestKind.addImport)
|
||||||
{
|
{
|
||||||
ModuleCache.addImportPaths(request.importPaths);
|
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");
|
info("Getting completions");
|
||||||
AutocompleteResponse response = complete(request);
|
AutocompleteResponse response = complete(request);
|
||||||
|
|
Loading…
Reference in New Issue