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 symbolLocation;
|
||||
bool doc;
|
||||
bool query;
|
||||
|
||||
try
|
||||
{
|
||||
getopt(args, "cursorPos|c", &cursorPos, "I", &importPaths,
|
||||
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
|
||||
"clearCache", &clearCache, "symbolLocation|l", &symbolLocation,
|
||||
"doc|d", &doc);
|
||||
"doc|d", &doc, "query|q", &query);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -64,6 +65,31 @@ int main(string[] args)
|
|||
printHelp(args[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)
|
||||
{
|
||||
if (shutdown)
|
||||
|
@ -185,6 +211,10 @@ Options:
|
|||
Gets documentation comments associated with the symbol at the cursor
|
||||
location.
|
||||
|
||||
--query | -q
|
||||
Query the server statis. Returns 0 if the server is running. Returns
|
||||
1 if the server could not be contacted.
|
||||
|
||||
-IPATH
|
||||
Instructs the server to add PATH to its list of paths searced for
|
||||
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
|
||||
dcd-client \- autocompletion client for the D programming language
|
||||
.PD
|
||||
|
@ -10,6 +10,7 @@ dcd-client \- autocompletion client for the D programming language
|
|||
.OP "\-h, \-\-help"
|
||||
.OP "\-l, \-\-symbolLocation"
|
||||
.OP "\-d, \-\-doc"
|
||||
.OP "\-q, \-\-query"
|
||||
.OP "\-\-shutdown"
|
||||
.OP "\-\-clearCache"
|
||||
.RI [ filename ]
|
||||
|
@ -20,6 +21,12 @@ dcd-client \- autocompletion client for the D programming language
|
|||
editor scripts.
|
||||
.PD
|
||||
.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
|
||||
.I portNumber
|
||||
.RS
|
||||
|
@ -27,10 +34,6 @@ Choose the port number on which
|
|||
.B dcd-client
|
||||
listens.
|
||||
.RE
|
||||
.B -h, \-\-help
|
||||
.RS
|
||||
Prints a help message
|
||||
.RE
|
||||
.B \-I
|
||||
.I directory
|
||||
.RS
|
||||
|
@ -42,11 +45,22 @@ so that they will be included in responses to future
|
|||
.B dcd-client
|
||||
requests.
|
||||
.RE
|
||||
.B \-c, \-\-cursorPos
|
||||
.I cursorPosition
|
||||
.B -h, \-\-help
|
||||
.RS
|
||||
Provides auto-completion at the given cursor position. The cursor
|
||||
position is measured in bytes from the beginning of the source code.
|
||||
Prints a help message
|
||||
.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
|
||||
.B \-\-shutdown
|
||||
.RS
|
||||
|
|
|
@ -124,6 +124,8 @@ enum RequestKind : ubyte
|
|||
symbolLocation = 0b00010000,
|
||||
/// Get the doc comments for the symbol
|
||||
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.");
|
||||
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)
|
||||
ModuleCache.addImportPaths(request.importPaths);
|
||||
if (request.kind & RequestKind.autocomplete)
|
||||
|
@ -191,8 +198,6 @@ int main(string[] args)
|
|||
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");
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue