- Notifications
You must be signed in to change notification settings - Fork71
The D Completion Daemon is an auto-complete program for the D programming language
License
dlang-community/DCD
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The D Completion Daemon is an auto-complete program for the D programming language.
(The above is a screenshot ofTextadept)
DCD is not an IDE. DCD is designed to provide autocompletion for your favoritetext editor. If you are looking for an IDE, tryone of these.
DCD consists of a client and a server. The client (dcd-client) is almost alwaysused through a text editor script or plugin, though it can be used from thecommand line. The server (dcd-server) is responsible for caching imported files,calculating autocomplete information, and sending it back to the client.
This program is reasonably stable. Please report problems on the Github issuetracker. Please be sure that you have read the documentation before filing anissue. (If you want to help your bug to get fixed faster, you can create atest case that helps isolatethe issue.)
- Working:
- Autocompletion of properties of built-in types such as int, float, double, etc.
- Autocompletion of __traits, scope, and extern arguments
- Autocompletion of enums
- Autocompletion of class, struct, and interface instances.
- Display of call tips for functions, constructors, and variables of function type
- alias declarations
- Public imports
- Finding the declaration location of a symbol at the cursor
- import statement completions
- Display of documentation comments in function call tips
- alias this
- auto declarations (Mostly)
- with statements
- Simple UFCS suggestions for concrete types and fundamental types.
- Not working:
- UFCS completion for templates, literals, aliased types, UFCS function arguments, and '.' chaining with other UFCS functions.
- UFCS calltips
- Autocompletion of declarations with template arguments (This will work to some extent, but it won't do things like replace T with int)
- Determining the type of an enum member when no base type is specified, but the first member has an initializer
- auto functions (which can then propagate the failure to auto declarations)
- That one feature that youREALLY needed
- Install a recent D compiler. DCD is tested with DMD 2.068.2, DMD 2.069.0-rc2, and LDC 0.16 (Do not use DMD 2.068.1)
- Follow the directions listed below for Homebrew, Git + Make, or Dub, depending on how you would like to build DCD.
- Configure your text editor to call the dcd-client program. See thewiki for information on configuring your specific editor.
- Start the dcd-server program before editing code. (Unless, of course, your editor's plugin handles this for you)
- Install a recent D compiler.
- Run
git submodule update --init --recursive
after cloning this repository to grab the various dependencies. - Optionally set the environment variable
DC
if you wish to use another compiler than the DMD known by the system. - Run
make
to build the client and server. (Or run build.bat on Windows).
brew install dcd
dub build --build=release --config=client
dub build --build=release --config=server
On Windows DCD will use TCP sockets to communicate between the client and server.DCD can use TCP sockets on other operating systems if the client and server usethe--tcp
or--port
command-line switches.
Operating systems that support UNIX domain sockets will use them by default.The path to the socket file can be overriden with the--socketFile
option.These are the default paths:
The socket will be created at/var/tmp/dcd-${UID}.socket
The client and server will attempt to create the socket in the following locations:
${XDG_RUNTIME_DIR}/dcd.socket
/tmp/dcd-${UID}.socket
ifXDG_RUNTIME_DIR
is not defined.
Because DCD is designed to be used from a text editor, this section is writtenprimarily for plugin authors.
The primary use case of the client is to query the server for autocomplete information.To do this, provide the client with the file that the user is editing along with thecursor position (in bytes).
dcd-client -c123 sourcefile.d
This will cause the client to print a listing of completions tostdout.The client will print either a listing of function call tips, or a listing of ofcompletions depending on if the cursor was directly after a dot character or aftera left parenthesis.
The file name is optional. If it is not specified, input will be read fromstdin.
When the first line of output is "identifiers", the editor should display acompletion list.
A line containing the string "identifiers" followed by the completions that areavailable, one per line. Each line consists of the completion name followed by atab character, followed by a completion kind
- c - class name
- i - interface name
- s - struct name
- u - union name
- v - variable name
- m - member variable name
- k - keyword, built-in version, scope statement
- f - function or method
- F - UFCS function
- g - enum name
- e - enum member
- P - package name
- M - module name
- a - array
- A - associative array
- l - alias name
- t - template name
- T - mixin template name
- h - template type parameter (when no colon constraint)
- p - template variadic parameter
identifierspartsvnamevlocationvqualifiervkindvtypevresolvedTypevcalltipvgetPartByNamef
You can pass--extended
to dcd-client to get more information. Output will now beescaped (newlines get escaped to\n
, tabs get escaped to\t
, backslash gets escaped to\\
).
Calltips are slightly different here because they first start with the function name instead ofarguments and the second part will be blank. The actual calltip is now in the third column.
Columns may be empty, in which case there will be multiple tabs next to each other.
The following information will be available in every line for completion in this format then ina tab separated format:
- identifier: raw name of a variable or function, etc
- kind: empty for calltips, see above for rest
- definition: function or variable definition string or close approximation for information display purpose
- symbol location: in which file (or
stdin
) & byte offset this symbol is defined. Separated with a space. - documentation: escaped documentation string of this symbol
- typeOf: resolved type name of this symbol:
- For variables, fields, globals, constants: resolved type or empty if unresolved.
- For functions: resolved return type or empty if unresolved.
- For constructors: may be struct/class name or empty in any case.
- Otherwise (probably) empty.
identifierslibraryFunctionfTuple!long libraryFunction(string s, string s2)stdin 190foobarlibraryFunctionfint* libraryFunction(string s)stdin 99Hello\nWorldint*libraryVariablevint libraryVariablestdin 56My variableintlibreTypesgstdin 298
DCD's output will start with "identifiers" when completing at a left parencharacter if the keywordspragma,scope,__traits,extern, orversionwere just before the paren.
Types in the calltips and typeOf column may not be complete, e.g. missingtemplate parameters or typeof expressions, etc.
When the first line of output is "calltips", the editor should display a functioncall tip.
A line containing the string "calltips", followed by zero or more lines, eachcontaining a call tip for an overload of the given function.
calltipsSymbol findSymbolInCurrentScope(size_t cursorPosition, string name)
dcd-client --doc -c 4298
When run with the --doc or -d option, DCD will attempt to display documentationcomments associated with the symbol at the cursor position. In the case offunctions there can be more than one documentation comment associated with asymbol. One doc comment will be printed per line. Newlines within the doccomments will be replaced with "\n", and backslashes escaped as "\".
An example doc comment\nParams: a = first param\n Returns: nothingAn example doc comment\nParams: a = first param\n b = second param\n Returns: nothing
dcd-client --clearCache
Import paths can be added to the server without restarting it. To accomplishthis, run the client with the -I option:
dcd-client -Ipath/to/imports
Import paths can be removed from the server without restarting it. To accomplishthis, run the client with the -R option:
dcd-client -Rpath/to/imports
dcd-client --symbolLocation -c 123
The "--symbolLocation" or "-l" flags cause the client to instruct the serverto return the path to the file and the byte offset of the declaration of thesymbol at the given cursor position.
The output consists of the absolute path to the file followed by a tab characterfollowed by the byte offset, followed by a newline character. For example:
/home/example/src/project/bar.d3482
The "--search" or "-s" option causes the server to return location informationfor all symbols with the given name in both the file being edited as well asthe server cache. The output format is one result per line, with the path, thesymbol type, and the byte offset of the symbol separated by tab characters.
Search the server's cache for symbols named "toImpl". (Using echo to give an EOFin place of a file being edited.)
echo | dcd-client --search toImpl/usr/include/dmd/phobos/std/conv.d f 48491/usr/include/dmd/phobos/std/conv.d f 47527/usr/include/dmd/phobos/std/conv.d f 47229/usr/include/dmd/phobos/std/conv.d f 40358/usr/include/dmd/phobos/std/conv.d f 38348/usr/include/dmd/phobos/std/conv.d f 35619/usr/include/dmd/phobos/std/conv.d f 32743/usr/include/dmd/phobos/std/conv.d f 22486/usr/include/dmd/phobos/std/conv.d f 16322/usr/include/dmd/phobos/std/conv.d f 14829/usr/include/dmd/phobos/std/conv.d f 14066/usr/include/dmd/phobos/std/conv.d f 13058/usr/include/dmd/phobos/std/conv.d f 12717/usr/include/dmd/phobos/std/conv.d f 9494
dcd-client --localUse -c 123
The "--localUse" or "-u" flags cause the client to instruct the serverto return all the uses, within the same module, of the symbol located at the given cursor position.
When uses exist, if the source symbol is an identifier (a type, a variable name, etc.)and if the symbol is not ambiguous then the first line contains the location of the symbol(a file name or literallystdin), a tab then the offset to the symbol declaration.Following the first line is a list of all known uses of the symbol in the current file.The list is composed of lines each containing a single number that indicates the byte offsetfrom the start of the file to the i-th use.
Otherwise the client outputs00000 so that the length of the answer is guaranteed to be at least 5 bytes.
stdin 452645133
Build a list of extra annoations for your IDE to display.You must submit the content of the current file displayed in your editor.
dcd-client --inlayHints
This is a W.I.P., currently it only provide annoatations about aliases for your variables,more is planned.
l ->MyAlias->MyType 42
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 fornow it must be started manually or (usually) by an editor plugin.
The server will attempt to read the file${XDG_CONFIG_HOME}/dcd/dcd.conf
(~/.config/dcd/dcd.conf
if XDG_CONFIG_HOME is not set) on Posix systems, ordcd.conf
on Windows in the current working directory on startup.If it exists, each line of the file is interpreted as a path that should besearched when looking for module imports. Lines that start with the "#" characterare ignored. Lines can contain environment variables which will be expandedduring loading. The name of the environment variable needs to the enclosed in${VAR}. For example:
${HOME}/sysroot/usr/include/dmd/phobos
Keep in mind that DCD treats import paths the same way that the compiler does.For example, a configuration file like this will not work as expected:
/usr/include/dmd/
What you actually want is this:
/usr/include/dmd/druntime/import/usr/include/dmd/phobos
The server can be shut down by running the client with the--shutdown
option:
dcd-client --shutdown
Import directories can be specified on the command line at startup:
dcd-server -I/home/user/code/one -I/home/user/code/two
The--port
or-p
option lets you specify the port number that theserver will listen on. The default port is 9166.
About
The D Completion Daemon is an auto-complete program for the D programming language