fix #521 - Add a request allowing to remove a set of import path (#522)

fix #521 - Add a request allowing to remove a set of import path
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
Laurent Tréguier 2018-08-10 09:15:07 +02:00 committed by The Dlang Bot
parent 6beae1ebb9
commit 436778fd1b
11 changed files with 44 additions and 12 deletions

View File

@ -224,6 +224,12 @@ this, run the client with the -I option:
dcd-client -Ipath/to/imports
## Remove import search path
Import paths can be removed from the server without restarting it. To accomplish
this, run the client with the -R option:
dcd-client -Rpath/to/imports
## Find declaration of symbol at cursor

@ -1 +1 @@
Subproject commit 3b546ed2b2551f61e0cf30d04f45682546387422
Subproject commit 3a562af26b008084c7f70520f5b91b6357a7c919

View File

@ -7,7 +7,7 @@
],
"license": "GPL-3.0",
"dependencies": {
"dsymbol": "~>0.4.1",
"dsymbol": "~>0.4.3",
"libdparse": "~>0.9.1",
"msgpack-d": "~>1.0.0-beta.3",
"stdx-allocator": "~>2.77.2"

View File

@ -39,7 +39,8 @@ int main(string[] args)
sharedLog.fatalHandler = () {};
size_t cursorPos = size_t.max;
string[] importPaths;
string[] addedImportPaths;
string[] removedImportPaths;
ushort port;
bool help;
bool shutdown;
@ -66,10 +67,11 @@ int main(string[] args)
try
{
getopt(args, "cursorPos|c", &cursorPos, "I", &importPaths,
"port|p", &port, "help|h", &help, "shutdown", &shutdown,
"clearCache", &clearCache, "symbolLocation|l", &symbolLocation,
"doc|d", &doc, "query|status|q", &query, "search|s", &search,
getopt(args, "cursorPos|c", &cursorPos, "I", &addedImportPaths,
"R", &removedImportPaths, "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, "listImports", &listImports,
"tcp", &useTCP, "socketFile", &socketFile,
"getIdentifier", &getIdentifier,
@ -136,10 +138,12 @@ int main(string[] args)
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
return sendRequest(socket, request) ? 0 : 1;
}
else if (importPaths.length > 0)
else if (addedImportPaths.length > 0 || removedImportPaths.length > 0)
{
request.kind |= RequestKind.addImport;
request.importPaths = importPaths.map!(a => absolutePath(a)).array;
immutable bool adding = addedImportPaths.length > 0;
request.kind |= adding ? RequestKind.addImport : RequestKind.removeImport;
request.importPaths = (adding ? addedImportPaths : removedImportPaths)
.map!(a => absolutePath(a)).array;
if (cursorPos == size_t.max)
{
Socket socket = createSocket(socketFile, port);
@ -199,7 +203,7 @@ int main(string[] args)
}
request.fileName = fileName;
request.importPaths = importPaths;
request.importPaths = addedImportPaths;
request.sourceCode = sourceCode;
request.cursorPosition = cursorPos;
request.searchName = search;

View File

@ -74,8 +74,10 @@ enum RequestKind : ushort
search = 0b00000000_10000000,
/// List import directories
listImports = 0b00000001_00000000,
/// local symbol usage
/// Local symbol usage
localUse = 0b00000010_00000000,
/// Remove import directory from server
removeImport = 0b00000100_00000000,
// dfmt on
}

View File

@ -256,6 +256,11 @@ int main(string[] args)
cache.addImportPaths(request.importPaths);
}
if (request.kind & RequestKind.removeImport)
{
cache.removeImportPaths(request.importPaths);
}
if (request.kind & RequestKind.listImports)
{
AutocompleteResponse response;

View File

@ -4,6 +4,7 @@ GREEN="\033[32m"
YELLOW="\033[33m"
NORMAL="\033[0m"
IMPORTS=$(pwd)/imports
export IMPORTS
fail_count=0
pass_count=0

View File

@ -0,0 +1,2 @@
identifiers
Point s

View File

View File

@ -0,0 +1 @@
import point:;

11
tests/tc_rm_import/run.sh Executable file
View File

@ -0,0 +1,11 @@
set -e
set -u
../../bin/dcd-client $1 file.d -c13 > actual1.txt
diff actual1.txt expected1.txt
../../bin/dcd-client $1 file.d -R$IMPORTS
../../bin/dcd-client $1 file.d -c13 > actual2.txt
diff actual2.txt expected2.txt
../../bin/dcd-client $1 -I$IMPORTS
../../bin/dcd-client $1 file.d -c13 > actual1.txt
diff actual1.txt expected1.txt