Add --query option to the client so that it can determine if the server can be contacted
This commit is contained in:
parent
ee80955aab
commit
def0228263
32
client.d
32
client.d
|
@ -43,13 +43,14 @@ int main(string[] args)
|
||||||
bool clearCache;
|
bool clearCache;
|
||||||
bool symbolLocation;
|
bool symbolLocation;
|
||||||
bool doc;
|
bool doc;
|
||||||
|
bool query;
|
||||||
|
|
||||||
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, "symbolLocation|l", &symbolLocation,
|
"clearCache", &clearCache, "symbolLocation|l", &symbolLocation,
|
||||||
"doc|d", &doc);
|
"doc|d", &doc, "query|q", &query);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +65,31 @@ int main(string[] args)
|
||||||
printHelp(args[0]);
|
printHelp(args[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else if (query)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TcpSocket socket = createSocket(port);
|
||||||
|
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
||||||
|
request.kind = RequestKind.query;
|
||||||
|
if (sendRequest(socket, request))
|
||||||
|
{
|
||||||
|
AutocompleteResponse response = getResponse(socket);
|
||||||
|
if (response.completionType == "ack")
|
||||||
|
{
|
||||||
|
writeln("Server is running");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
writeln("Server is not running");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (shutdown || clearCache)
|
else if (shutdown || clearCache)
|
||||||
{
|
{
|
||||||
if (shutdown)
|
if (shutdown)
|
||||||
|
@ -185,6 +211,10 @@ Options:
|
||||||
Gets documentation comments associated with the symbol at the cursor
|
Gets documentation comments associated with the symbol at the cursor
|
||||||
location.
|
location.
|
||||||
|
|
||||||
|
--query | -q
|
||||||
|
Query the server statis. Returns 0 if the server is running. Returns
|
||||||
|
1 if the server could not be contacted.
|
||||||
|
|
||||||
-IPATH
|
-IPATH
|
||||||
Instructs the server to add PATH to its list of paths searced for
|
Instructs the server to add PATH to its list of paths searced for
|
||||||
imported modules.
|
imported modules.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.TH dcd-client 1 "March 6 2014" "" https://github.com/Hackerpilot/DCD
|
.TH dcd-client 1 "August 11 2014" "" https://github.com/Hackerpilot/DCD
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dcd-client \- autocompletion client for the D programming language
|
dcd-client \- autocompletion client for the D programming language
|
||||||
.PD
|
.PD
|
||||||
|
@ -10,6 +10,7 @@ dcd-client \- autocompletion client for the D programming language
|
||||||
.OP "\-h, \-\-help"
|
.OP "\-h, \-\-help"
|
||||||
.OP "\-l, \-\-symbolLocation"
|
.OP "\-l, \-\-symbolLocation"
|
||||||
.OP "\-d, \-\-doc"
|
.OP "\-d, \-\-doc"
|
||||||
|
.OP "\-q, \-\-query"
|
||||||
.OP "\-\-shutdown"
|
.OP "\-\-shutdown"
|
||||||
.OP "\-\-clearCache"
|
.OP "\-\-clearCache"
|
||||||
.RI [ filename ]
|
.RI [ filename ]
|
||||||
|
@ -20,6 +21,12 @@ dcd-client \- autocompletion client for the D programming language
|
||||||
editor scripts.
|
editor scripts.
|
||||||
.PD
|
.PD
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
.B \-c, \-\-cursorPos
|
||||||
|
.I cursorPosition
|
||||||
|
.RS
|
||||||
|
Provides auto-completion at the given cursor position. The cursor
|
||||||
|
position is measured in bytes from the beginning of the source code.
|
||||||
|
.RE
|
||||||
.B -p, \-\-port
|
.B -p, \-\-port
|
||||||
.I portNumber
|
.I portNumber
|
||||||
.RS
|
.RS
|
||||||
|
@ -27,10 +34,6 @@ Choose the port number on which
|
||||||
.B dcd-client
|
.B dcd-client
|
||||||
listens.
|
listens.
|
||||||
.RE
|
.RE
|
||||||
.B -h, \-\-help
|
|
||||||
.RS
|
|
||||||
Prints a help message
|
|
||||||
.RE
|
|
||||||
.B \-I
|
.B \-I
|
||||||
.I directory
|
.I directory
|
||||||
.RS
|
.RS
|
||||||
|
@ -42,11 +45,22 @@ so that they will be included in responses to future
|
||||||
.B dcd-client
|
.B dcd-client
|
||||||
requests.
|
requests.
|
||||||
.RE
|
.RE
|
||||||
.B \-c, \-\-cursorPos
|
.B -h, \-\-help
|
||||||
.I cursorPosition
|
|
||||||
.RS
|
.RS
|
||||||
Provides auto-completion at the given cursor position. The cursor
|
Prints a help message
|
||||||
position is measured in bytes from the beginning of the source code.
|
.RE
|
||||||
|
.B -l, \-\-symbolLocation
|
||||||
|
.RS
|
||||||
|
Get the file name and position that the symbol at the cursor location was defined.
|
||||||
|
.RE
|
||||||
|
.B \-d, \-\-doc
|
||||||
|
.RS
|
||||||
|
Gets documentation comments associated with the symbol at the cursor location.
|
||||||
|
.RE
|
||||||
|
.B \-q, \-\-query
|
||||||
|
.RS
|
||||||
|
Query the server statis. Returns 0 if the server is running. Returns 1 if the
|
||||||
|
server could not be contacted.
|
||||||
.RE
|
.RE
|
||||||
.B \-\-shutdown
|
.B \-\-shutdown
|
||||||
.RS
|
.RS
|
||||||
|
|
|
@ -124,6 +124,8 @@ enum RequestKind : ubyte
|
||||||
symbolLocation = 0b00010000,
|
symbolLocation = 0b00010000,
|
||||||
/// Get the doc comments for the symbol
|
/// Get the doc comments for the symbol
|
||||||
doc = 0b00100000,
|
doc = 0b00100000,
|
||||||
|
/// Query server status
|
||||||
|
query = 0b01000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
9
server.d
9
server.d
|
@ -155,6 +155,13 @@ int main(string[] args)
|
||||||
Log.info("Shutting down.");
|
Log.info("Shutting down.");
|
||||||
break serverLoop;
|
break serverLoop;
|
||||||
}
|
}
|
||||||
|
else if (request.kind & RequestKind.query)
|
||||||
|
{
|
||||||
|
AutocompleteResponse response;
|
||||||
|
response.completionType = "ack";
|
||||||
|
ubyte[] responseBytes = msgpack.pack(response);
|
||||||
|
s.send(responseBytes);
|
||||||
|
}
|
||||||
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.autocomplete)
|
||||||
|
@ -191,8 +198,6 @@ int main(string[] args)
|
||||||
Log.error("Could not get symbol location", e.msg);
|
Log.error("Could not get symbol location", e.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Log.error("Unknown request type");
|
|
||||||
Log.info("Request processed in ", requestWatch.peek().to!("msecs", float), " milliseconds");
|
Log.info("Request processed in ", requestWatch.peek().to!("msecs", float), " milliseconds");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue