diff --git a/README.md b/README.md index 60d5fd9..adee78a 100644 --- a/README.md +++ b/README.md @@ -95,17 +95,28 @@ containing a call tip for an overload of the given function. ##Clear server's autocomplete cache ```dcd-client --clearCache``` -##Specify server port -```dcd-client -p4242``` - ##Add import search path -```dcd-client -Ipath/to/imports``` - -##Shut down the server -```dcd-client --shutdown``` +Import paths can be added to the server without restarting it. To accomplish +this, run the client with the -I option: + dcd-client -Ipath/to/imports #Server usage +The server must be running for the DCD client to provide autocomplete information. +In future versions the client may start the server if it is not running, but for +now it must be started manually. + +## Configuration Files +The server will attempt to read the file ```~/.config/dcd``` on startup. +If it exists, each line of the file is interpreted as a path that should be +searched when looking for module imports. + +##Shut down the server +The server can be shut down by running the client with the correct option: + dcd-client --shutdown + ## Import directories -The ```-I``` option allows you to specify directories to be searched for modules +Import directories can be specified on the command line at startup: + dcd-server -I/home/user/code/one -I/home/user/code/two + ## Port number -The ```--port``` or ```-p``` option lets you specify the port number that the server will listen on +The ```--port``` or ```-p``` option lets you specify the port number that the server will listen on. diff --git a/server.d b/server.d index ce0be93..c2b39d7 100644 --- a/server.d +++ b/server.d @@ -22,6 +22,9 @@ import std.socket; import std.stdio; import std.getopt; import std.algorithm; +import std.path; +import std.file; +import std.array; import msgpack; @@ -29,6 +32,9 @@ import messages; import autocomplete; import modulecache; +// TODO: Portability would be nice... +enum CONFIG_FILE_PATH = "~/.config/dcd"; + int main(string[] args) { ushort port = 9166; @@ -46,13 +52,7 @@ int main(string[] args) return 1; } - // begin hack - importPaths ~= "/home/alaran/src/dcd"; - importPaths ~= "/home/alaran/src/dscanner"; - importPaths ~= "/usr/include/d2/core"; - importPaths ~= "/usr/include/d2/phobos"; - importPaths ~= "/usr/include/d2/druntime/import"; - // end hack + importPaths ~= loadConfiguredImportDirs(); foreach (path; importPaths) ModuleCache.addImportPath(path); @@ -124,6 +124,20 @@ int main(string[] args) return 0; } +version(linux) +{ +string[] loadConfiguredImportDirs() +{ + string fullPath = expandTilde(CONFIG_FILE_PATH); + if (!exists(fullPath)) + return []; + File f = File(fullPath); + return f.byLine(KeepTerminator.no).map!(a => a.idup).filter!(a => a.exists()).array(); +} +} +else + static assert (false, "Only Linux is supported at the moment"); + void printHelp(string programName) { writefln(