Read import paths from configuration file instead of hard coding them

This commit is contained in:
Hackerpilot 2013-08-11 01:16:48 +00:00
parent dffd348a12
commit 79afeb2538
2 changed files with 41 additions and 16 deletions

View File

@ -95,17 +95,28 @@ containing a call tip for an overload of the given function.
##Clear server's autocomplete cache ##Clear server's autocomplete cache
```dcd-client --clearCache``` ```dcd-client --clearCache```
##Specify server port
```dcd-client -p4242```
##Add import search path ##Add import search path
```dcd-client -Ipath/to/imports``` Import paths can be added to the server without restarting it. To accomplish
this, run the client with the -I option:
##Shut down the server dcd-client -Ipath/to/imports
```dcd-client --shutdown```
#Server usage #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 ## 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 ## 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.

View File

@ -22,6 +22,9 @@ import std.socket;
import std.stdio; import std.stdio;
import std.getopt; import std.getopt;
import std.algorithm; import std.algorithm;
import std.path;
import std.file;
import std.array;
import msgpack; import msgpack;
@ -29,6 +32,9 @@ import messages;
import autocomplete; import autocomplete;
import modulecache; import modulecache;
// TODO: Portability would be nice...
enum CONFIG_FILE_PATH = "~/.config/dcd";
int main(string[] args) int main(string[] args)
{ {
ushort port = 9166; ushort port = 9166;
@ -46,13 +52,7 @@ int main(string[] args)
return 1; return 1;
} }
// begin hack importPaths ~= loadConfiguredImportDirs();
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
foreach (path; importPaths) foreach (path; importPaths)
ModuleCache.addImportPath(path); ModuleCache.addImportPath(path);
@ -124,6 +124,20 @@ int main(string[] args)
return 0; 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) void printHelp(string programName)
{ {
writefln( writefln(