Giter Site home page Giter Site logo

dlang-community / dcd Goto Github PK

View Code? Open in Web Editor NEW
344.0 28.0 74.0 1.61 MB

The D Completion Daemon is an auto-complete program for the D programming language

License: GNU General Public License v3.0

Shell 8.60% NSIS 3.72% Makefile 0.64% D 85.04% Batchfile 0.43% Roff 1.07% Meson 0.50%
d autocomplete dlang code-completion symbols intellisense

dcd's Introduction

DCD CI status

The D Completion Daemon is an auto-complete program for the D programming language.

Teaser

(The above is a screenshot of Textadept)

DCD is not an IDE. DCD is designed to provide autocompletion for your favorite text editor. If you are looking for an IDE, try one of these.

DCD consists of a client and a server. The client (dcd-client) is almost always used through a text editor script or plugin, though it can be used from the command line. The server (dcd-server) is responsible for caching imported files, calculating autocomplete information, and sending it back to the client.

Status

This program is reasonably stable. Please report problems on the Github issue tracker. Please be sure that you have read the documentation before filing an issue. (If you want to help your bug to get fixed faster, you can create a test case that helps isolate the 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 you REALLY needed

Setup

General

  1. 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)
  2. Follow the directions listed below for Homebrew, Git + Make, or Dub, depending on how you would like to build DCD.
  3. Configure your text editor to call the dcd-client program. See the wiki for information on configuring your specific editor.
  4. Start the dcd-server program before editing code. (Unless, of course, your editor's plugin handles this for you)

Git + Make

  1. Install a recent D compiler.
  2. Run git submodule update --init --recursive after cloning this repository to grab the various dependencies.
  3. Optionally set the environment variable DC if you wish to use another compiler than the DMD known by the system.
  4. Run make to build the client and server. (Or run build.bat on Windows).

OS X w/ Homebrew

  1. brew install dcd

Dub

  1. dub build --build=release --config=client
  2. dub build --build=release --config=server

Sockets

TCP

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 use the --tcp or --port command-line switches.

UNIX domain sockets

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:

OSX

The socket will be created at /var/tmp/dcd-${UID}.socket

Linux/BSD

The client and server will attempt to create the socket in the following locations:

  • ${XDG_RUNTIME_DIR}/dcd.socket
  • /tmp/dcd-${UID}.socket if XDG_RUNTIME_DIR is not defined.

Client

Because DCD is designed to be used from a text editor, this section is written primarily for plugin authors.

Get autocomplete information

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 the cursor position (in bytes).

dcd-client -c123 sourcefile.d

This will cause the client to print a listing of completions to stdout. The client will print either a listing of function call tips, or a listing of of completions depending on if the cursor was directly after a dot character or after a left parenthesis.

The file name is optional. If it is not specified, input will be read from stdin.

Dot completion

When the first line of output is "identifiers", the editor should display a completion list.

Output format

A line containing the string "identifiers" followed by the completions that are available, one per line. Each line consists of the completion name followed by a tab character, followed by a completion kind

Completion kinds
  • 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

Example output

identifiers
parts	v
name	v
location	v
qualifier	v
kind	v
type	v
resolvedType	v
calltip	v
getPartByName	f

Extended output mode

You can pass --extended to dcd-client to get more information. Output will now be escaped (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 of arguments 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 in a 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.

Example --extended output

identifiers
libraryFunction	f	Tuple!long libraryFunction(string s, string s2)	stdin 190	foobar
libraryFunction	f	int* libraryFunction(string s)	stdin 99	Hello\nWorld	int*
libraryVariable	v	int libraryVariable	stdin 56	My variable	int
libreTypes	g		stdin 298

Note

DCD's output will start with "identifiers" when completing at a left paren character if the keywords pragma, scope, __traits, extern, or version were just before the paren.

Types in the calltips and typeOf column may not be complete, e.g. missing template parameters or typeof expressions, etc.

Parenthesis completion

When the first line of output is "calltips", the editor should display a function call tip.

Output format

A line containing the string "calltips", followed by zero or more lines, each containing a call tip for an overload of the given function.

Example output
calltips
Symbol findSymbolInCurrentScope(size_t cursorPosition, string name)

Doc comment display

dcd-client --doc -c 4298

When run with the --doc or -d option, DCD will attempt to display documentation comments associated with the symbol at the cursor position. In the case of functions there can be more than one documentation comment associated with a symbol. One doc comment will be printed per line. Newlines within the doc comments will be replaced with "\n", and backslashes escaped as "\".

Example output

An example doc comment\nParams: a = first param\n    Returns: nothing
An example doc comment\nParams: a = first param\n     b = second param\n    Returns: nothing

Clear server's autocomplete cache

dcd-client --clearCache

Add import search path

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

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

dcd-client --symbolLocation -c 123

The "--symbolLocation" or "-l" flags cause the client to instruct the server to return the path to the file and the byte offset of the declaration of the symbol at the given cursor position.

The output consists of the absolute path to the file followed by a tab character followed by the byte offset, followed by a newline character. For example:

/home/example/src/project/bar.d	3482

Search for symbols by name

The "--search" or "-s" option causes the server to return location information for all symbols with the given name in both the file being edited as well as the server cache. The output format is one result per line, with the path, the symbol type, and the byte offset of the symbol separated by tab characters.

Example

Search the server's cache for symbols named "toImpl". (Using echo to give an EOF in 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

Find the use of the symbol at the cursor

dcd-client --localUse -c 123

The "--localUse" or "-u" flags cause the client to instruct the server to return all the uses, within the same module, of the symbol located at the given cursor position.

Output format

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 literally stdin), 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 offset from the start of the file to the i-th use.

Otherwise the client outputs 00000 so that the length of the answer is guaranteed to be at least 5 bytes.

Example output

stdin 45
26
45
133

Inlay Hints

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.

Example output

l   ->MyAlias->MyType   42

Server

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 or (usually) by an editor plugin.

Configuration Files

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, or dcd.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 be searched when looking for module imports. Lines that start with the "#" character are ignored. Lines can contain environment variables which will be expanded during 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

Shut down the server

The server can be shut down by running the client with the --shutdown option:

dcd-client --shutdown

Import directories

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 default port is 9166.

dcd's People

Contributors

andre2007 avatar bbasile avatar brad-anderson avatar brianush1 avatar crsix avatar cybershadow avatar dav1dde avatar dlang-bot avatar dymk avatar fr86 avatar geod24 avatar gosella avatar hackerpilot avatar hk47196 avatar idanarye avatar jacob-carlborg avatar john-colvin avatar kelet avatar kubo39 avatar laurenttreguier avatar nordlow avatar ryuukk avatar skl131313 avatar snosov1 avatar some-bot avatar tsukimizake avatar vushu avatar webfreak001 avatar wilzbach avatar yazd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dcd's Issues

submodules out of date

The submodules aren't up to date and cause compilation to fail with dmd Git head without first checking out the master branches of them.

Crash on dub source

Starting the server with the source directory of dub as import directory leads to immediate crash.

Best regards,
Robert

dub: https://github.com/rejectedsoftware/dub

robert@linuxPC source $ pwd
/home/robert/projects/dub/source

robert@linuxPC source $ dcd-server -I .
Loading and caching completions for ./dub/compilers/ldc.d
Getting symbols for module ./dub/compilers/ldc.d
Loading and caching completions for ./dub/compilers/gdc.d
Getting symbols for module ./dub/compilers/gdc.d
Loading and caching completions for ./dub/compilers/compiler.d
Getting symbols for module ./dub/compilers/compiler.d
Loading and caching completions for ./dub/compilers/dmd.d
Getting symbols for module ./dub/compilers/dmd.d
Loading and caching completions for ./dub/dependency.d
Getting symbols for module ./dub/dependency.d
Loading and caching completions for ./dub/project.d
Getting symbols for module ./dub/project.d
Loading and caching completions for ./dub/dub.d
Getting symbols for module ./dub/dub.d
Loading and caching completions for ./dub/package_.d
Getting symbols for module ./dub/package_.d
Loading and caching completions for ./dub/internal/std/process.d
Getting symbols for module ./dub/internal/std/process.d
Loading and caching completions for ./dub/internal/std/processcompat.d
Getting symbols for module ./dub/internal/std/processcompat.d
Loading and caching completions for ./dub/internal/vibecompat/core/log.d
Getting symbols for module ./dub/internal/vibecompat/core/log.d
Loading and caching completions for ./dub/internal/vibecompat/core/file.d
Getting symbols for module ./dub/internal/vibecompat/core/file.d
Loading and caching completions for ./dub/internal/vibecompat/data/json.d
Getting symbols for module ./dub/internal/vibecompat/data/json.d
Loading and caching completions for ./dub/internal/vibecompat/data/utils.d
Getting symbols for module ./dub/internal/vibecompat/data/utils.d
Loading and caching completions for ./dub/internal/vibecompat/inet/path.d
Getting symbols for module ./dub/internal/vibecompat/inet/path.d
Loading and caching completions for ./dub/internal/vibecompat/inet/url.d
Getting symbols for module ./dub/internal/vibecompat/inet/url.d
Loading and caching completions for ./dub/packagemanager.d
Getting symbols for module ./dub/packagemanager.d
Could not resolve type
Loading and caching completions for ./dub/installation.d
Getting symbols for module ./dub/installation.d
Shutting down sockets...
Sockets shut down.

[email protected](2424): Range violation

dcd-server(d_array_bounds+0x26) [0x5c8b86]
dcd-server() [0x5b88f5]
dcd-server(const(pure nothrow ref @Property @safe const(ubyte) function()) stdx.d.lexer.LexSource!(ubyte[]).LexSource.front+0x6a) [0x5ade2a]
dcd-server(pure nothrow @safe void stdx.d.lexer.TokenRange!(stdx.d.lexer.LexSource!(ubyte[]).LexSource).TokenRange.nextChar()+0x40) [0x5b1770]
dcd-server(pure void stdx.d.lexer.TokenRange!(stdx.d.lexer.LexSource!(ubyte[]).LexSource).TokenRange.lexComment!(false).lexComment()+0x11a) [0x5b3dfa]
dcd-server(void stdx.d.lexer.TokenRange!(stdx.d.lexer.LexSource!(ubyte[]).LexSource).TokenRange.advance()+0x1248) [0x5af598]
dcd-server(void stdx.d.lexer.TokenRange!(stdx.d.lexer.LexSource!(ubyte[]).LexSource).TokenRange.popFront()+0x51) [0x5ae349]
dcd-server(stdx.d.lexer.TokenRange!(stdx.d.lexer.LexSource!(ubyte[]).LexSource).TokenRange stdx.d.lexer.byToken!(ubyte[]).byToken(ubyte[], stdx.d.lexer.LexerConfig)+0x9a) [0x5adc9a]
dcd-server(actypes.ACSymbol[] modulecache.ModuleCache.getSymbolsInModule(immutable(char)[])+0x1e3) [0x586133]
dcd-server(void modulecache.ModuleCache.addImportPath(immutable(char)[])+0x16b) [0x585f1b]
dcd-server(Dmain+0x249) [0x5223f9]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char**, extern (C) int function(char[][])*).void runMain()+0x18) [0x5c9294]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char**, extern (C) int function(char[][])).void tryExec(scope void delegate())+0x2a) [0x5c8dc6]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char
, extern (C) int function(char[][])
).void runAll()+0x40) [0x5c92e4]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char*, extern (C) int function(char[][])
).void tryExec(scope void delegate())+0x2a) [0x5c8dc6]
dcd-server(_d_run_main+0x1ae) [0x5c8d82]
dcd-server(main+0x17) [0x5c8bcf]

/lib64/libc.so.6(__libc_start_main+0xf5) [0x3e5ba21a05]

Another range violation error

With either the cursor at 8 or 9:

./dcd-server
./dcd-client -c8 < file.d

File.d contains:

 import s

A range violation occurs and the server dies.
addr2line points to dscanner/stdx/d/parser.d:6403

Handle incomplete code

Currently DCD doesn't seem to be able to handle incomplete code in all cases. Example:

module foo;

struct Foo
{
    int a;
}

void main ()
{
    Foo foo;
    foo.
}

Trigger code completion for the above works fine. But if I remove the last closing curly brace I get the following error in the server "Could not find declaration of foo".

Server freezes while autocompleting

Using test.d as follows:

import std.

Run the server and run the client using:

./dcd-server
./dcd-client -c1 test.d

You will notice the server increasing in memory usage until it blows up. The issue seems to be an infinite loop in lexer.d advance function.

Request to list all known global or module symbols for class view/outline support

To enable a class view in the clients a request should be implemented which lists all parsed global symbols. Some logic needs to be implemented to only list project symbols and not standard library functions and classes (maybe via different kinds of include dirs). The output format could be CTAGS like. Additionally the request could be parameterized to just include symbols of the current module to allow an outline view support.

"Jump to declaration" of symbol

The client/server should be enhanced to allow an action which returns the declaration (or maybe definiton?) of the symbol currently under the cursor. The filename and location of declaration should be returned. This way editors could implement an "Jump to declaration" action.

Does not walk up inheritance tree across imports

Scenario

A.d:

module A;
class Aclass { void Amember(); }

B.d:

module B;
import A;
class Bclass : Aclass { void Bmember(); }

main.d:

module main;
import B;
class MainClass : Bclass {}
void main()
{
    Bclass instanceB = new Bclass();
    MainClass instanceM = new MainClass();
    instanceB. // autocomplete here
    instanceM. // autocomplete here
}

Result

Expected

Amember and Bmember provided in DCD output for both.

Actual

Only Bmember is provided in either autocomplete suggestion list.

Additional notes

On commit 8083e9a (Oct. 2nd).

Importing module A in main.d allows DCD to find void Amember().

Dscanner

As I'm not sure if this is a bug in DCD or in the Dscanner source tree, here too is the commit and date for the Dscanner branch cloned on my machine for DCD: dlang-community/D-Scanner@cd3bb40 (Sep. 15).

And the obligatory...

Thanks so much for this project!

crash when adding new path and dlibraries to DCD

added /usr/local/include/d2 to the paths for DCD to scan. doing this causes dcd_server to crash with the following debug info.

Shutting down sockets...
Sockets shut down.

[email protected](6398): Range violation

dcd-server(d_array_bounds+0x26) [0x5c9096]
dcd-server() [0x5ad1a9]
dcd-server(const(@Property stdx.d.lexer.Token function()) stdx.d.parser.Parser.current+0x36) [0x5ab792]
dcd-server(stdx.d.ast.Declaration stdx.d.parser.Parser.parseDeclaration()+0x146) [0x5a0052]
dcd-server(stdx.d.ast.Module stdx.d.parser.Parser.parseModule()+0x94) [0x5a4570]
dcd-server(stdx.d.ast.Module stdx.d.parser.parseModule(const(stdx.d.lexer.Token)[], immutable(char)[], void function(immutable(char)[], int, int, immutable(char)[])
)+0x60) [0x59ce4c]
dcd-server(actypes.ACSymbol[] modulecache.ModuleCache.getSymbolsInModule(immutable(char)[])+0x23b) [0x5865d7]
dcd-server(void modulecache.ModuleCache.addImportPath(immutable(char)[])+0x16b) [0x586367]
dcd-server(Dmain+0x25f) [0x522573]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char
, extern (C) int function(char[][])).void runMain()+0x18) [0x5c97a4]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x5c92d6]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char**, extern (C) int function(char[][])).void runAll()+0x40) [0x5c97f4]
dcd-server(extern (C) int rt.dmain2.d_run_main(int, char
, extern (C) int function(char[][])
).void tryExec(scope void delegate())+0x2a) [0x5c92d6]
dcd-server(_d_run_main+0x1ae) [0x5c9292]
dcd-server(main+0x17) [0x5c90df]

/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f6b5546dde5]

Range violation when getting symbols from dmd or ldc

Using revision da48901 on Arch Linux.
Same file on both:

DMD 2.063.2

Which also has a smaller error about not being able to parse index.d

dcd-server -I /usr/include/dlang/dmd
Loading and caching completions for /usr/include/dlang/dmd/crc32.d
Getting symbols for module /usr/include/dlang/dmd/crc32.d
Loading and caching completions for /usr/include/dlang/dmd/object.di
Getting symbols for module /usr/include/dlang/dmd/object.di
Loading and caching completions for /usr/include/dlang/dmd/index.d
Getting symbols for module /usr/include/dlang/dmd/index.d
Couln't parse /usr/include/dlang/dmd/index.d due to exception: (13:4): Expected "'" to end character literal
Loading and caching completions for /usr/include/dlang/dmd/etc/linux/memoryerror.d
Getting symbols for module /usr/include/dlang/dmd/etc/linux/memoryerror.d
Loading and caching completions for /usr/include/dlang/dmd/etc/c/sqlite3.d
Getting symbols for module /usr/include/dlang/dmd/etc/c/sqlite3.d
Loading and caching completions for /usr/include/dlang/dmd/etc/c/curl.d
Getting symbols for module /usr/include/dlang/dmd/etc/c/curl.d
Loading and caching completions for /usr/include/dlang/dmd/etc/c/zlib.d
Getting symbols for module /usr/include/dlang/dmd/etc/c/zlib.d
Loading and caching completions for /usr/include/dlang/dmd/std/typecons.d
Getting symbols for module /usr/include/dlang/dmd/std/typecons.d
Could not resolve type
Could not resolve type
Loading and caching completions for /usr/include/dlang/dmd/std/socketstream.d
Getting symbols for module /usr/include/dlang/dmd/std/socketstream.d
Loading and caching completions for /usr/include/dlang/dmd/std/path.d
Getting symbols for module /usr/include/dlang/dmd/std/path.d
Loading and caching completions for /usr/include/dlang/dmd/std/numeric.d
Getting symbols for module /usr/include/dlang/dmd/std/numeric.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/processinit.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/processinit.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/math/biguintcore.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/math/biguintcore.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/math/gammafunction.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/math/gammafunction.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/math/biguintnoasm.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/math/biguintnoasm.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/math/errorfunction.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/math/errorfunction.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/math/biguintx86.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/math/biguintx86.d
Loading and caching completions for /usr/include/dlang/dmd/std/internal/windows/advapi32.d
Getting symbols for module /usr/include/dlang/dmd/std/internal/windows/advapi32.d
Shutting down sockets...
Sockets shut down.
[email protected](6435): Range violation
----------------
dcd-server(_d_array_bounds+0x16) [0x81d3886]
dcd-server() [0x81be8ff]
dcd-server(const(@property stdx.d.lexer.Token function()) stdx.d.parser.Parser.current+0x62) [0x81bcc72]
dcd-server(bool stdx.d.parser.Parser.isDeclaration()+0x4c) [0x81bbca4]
dcd-server(stdx.d.ast.ConditionalDeclaration stdx.d.parser.Parser.parseConditionalDeclaration()+0x89) [0x81b2989]
dcd-server(stdx.d.ast.Declaration stdx.d.parser.Parser.parseDeclaration()+0x6d4) [0x81b3724]
dcd-server(stdx.d.ast.Module stdx.d.parser.Parser.parseModule()+0xaf) [0x81b6d1f]
dcd-server(stdx.d.ast.Module stdx.d.parser.parseModule(const(stdx.d.lexer.Token)[], immutable(char)[], void function(immutable(char)[], int, int, immutable(char)[])*)+0x3f) [0x81b0647]
dcd-server(actypes.ACSymbol[] modulecache.ModuleCache.getSymbolsInModule(immutable(char)[])+0x19f) [0x81a157f]
dcd-server(void modulecache.ModuleCache.addImportPath(immutable(char)[])+0xd9) [0x81a13b9]
dcd-server(_Dmain+0x1ee) [0x81596fe]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runMain()+0x10) [0x81d3d80]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x18) [0x81d3a20]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runAll()+0x37) [0x81d3dc7]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x18) [0x81d3a20]
dcd-server(_d_run_main+0x121) [0x81d39f1]
dcd-server(main+0x14) [0x81d38c4]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0xb75989d3]
----------------

LDC 0.12.0

> dcd-server -I /usr/include/dlang/ldc
Loading and caching completions for /usr/include/dlang/ldc/object.di
Getting symbols for module /usr/include/dlang/ldc/object.di
Loading and caching completions for /usr/include/dlang/ldc/etc/linux/memoryerror.d
Getting symbols for module /usr/include/dlang/ldc/etc/linux/memoryerror.d
Loading and caching completions for /usr/include/dlang/ldc/etc/c/sqlite3.d
Getting symbols for module /usr/include/dlang/ldc/etc/c/sqlite3.d
Loading and caching completions for /usr/include/dlang/ldc/etc/c/curl.d
Getting symbols for module /usr/include/dlang/ldc/etc/c/curl.d
Loading and caching completions for /usr/include/dlang/ldc/etc/c/zlib.d
Getting symbols for module /usr/include/dlang/ldc/etc/c/zlib.d
Loading and caching completions for /usr/include/dlang/ldc/std/typecons.d
Getting symbols for module /usr/include/dlang/ldc/std/typecons.d
Could not resolve type
Could not resolve type
Loading and caching completions for /usr/include/dlang/ldc/std/socketstream.d
Getting symbols for module /usr/include/dlang/ldc/std/socketstream.d
Loading and caching completions for /usr/include/dlang/ldc/std/path.d
Getting symbols for module /usr/include/dlang/ldc/std/path.d
Loading and caching completions for /usr/include/dlang/ldc/std/numeric.d
Getting symbols for module /usr/include/dlang/ldc/std/numeric.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/processinit.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/processinit.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/math/biguintcore.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/math/biguintcore.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/math/gammafunction.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/math/gammafunction.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/math/biguintnoasm.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/math/biguintnoasm.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/math/errorfunction.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/math/errorfunction.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/math/biguintx86.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/math/biguintx86.d
Loading and caching completions for /usr/include/dlang/ldc/std/internal/windows/advapi32.d
Getting symbols for module /usr/include/dlang/ldc/std/internal/windows/advapi32.d
Shutting down sockets...
Sockets shut down.
[email protected](6435): Range violation
----------------
dcd-server(_d_array_bounds+0x16) [0x81d3886]
dcd-server() [0x81be8ff]
dcd-server(const(@property stdx.d.lexer.Token function()) stdx.d.parser.Parser.current+0x62) [0x81bcc72]
dcd-server(bool stdx.d.parser.Parser.isDeclaration()+0x4c) [0x81bbca4]
dcd-server(stdx.d.ast.ConditionalDeclaration stdx.d.parser.Parser.parseConditionalDeclaration()+0x89) [0x81b2989]
dcd-server(stdx.d.ast.Declaration stdx.d.parser.Parser.parseDeclaration()+0x6d4) [0x81b3724]
dcd-server(stdx.d.ast.Module stdx.d.parser.Parser.parseModule()+0xaf) [0x81b6d1f]
dcd-server(stdx.d.ast.Module stdx.d.parser.parseModule(const(stdx.d.lexer.Token)[], immutable(char)[], void function(immutable(char)[], int, int, immutable(char)[])*)+0x3f) [0x81b0647]
dcd-server(actypes.ACSymbol[] modulecache.ModuleCache.getSymbolsInModule(immutable(char)[])+0x19f) [0x81a157f]
dcd-server(void modulecache.ModuleCache.addImportPath(immutable(char)[])+0xd9) [0x81a13b9]
dcd-server(_Dmain+0x1ee) [0x81596fe]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runMain()+0x10) [0x81d3d80]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x18) [0x81d3a20]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runAll()+0x37) [0x81d3dc7]
dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x18) [0x81d3a20]
dcd-server(_d_run_main+0x121) [0x81d39f1]
dcd-server(main+0x14) [0x81d38c4]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0xb758b9d3]
----------------

Reduce Memory Usage

The server uses 168 megabytes of memory when caching phobos, derelict, dcd, and dscanner. See if it's possible to reduce this.

Server throws a range error

Using test.d as follows:

import std.s

Running the server and client as follows:

./dcd-server
./dcd-client -c10 test.d

Server throws:

[email protected](7372): Range violation
----------------
./dcd-server(_d_array_bounds+0x26) [0x5be82e]
./dcd-server() [0x5cf60e]
./dcd-server(pure nothrow @safe const(stdx.d.lexer.Token) std.range.SortedRange!(const(stdx.d.lexer.Token)[], "a < b").SortedRange.opIndex(ulong)+0x68) [0x575970]
./dcd-server(messages.AutocompleteResponse autocomplete.complete(messages.AutocompleteRequest, immutable(char)[][])+0x5f2) [0x585632]
./dcd-server(_Dmain+0x5bb) [0x51a6bb]
./dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runMain()+0x18) [0x5bef3c]
./dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x5bea6e]
./dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runAll()+0x40) [0x5bef8c]
./dcd-server(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x5bea6e]
./dcd-server(_d_run_main+0x1ae) [0x5bea2a]
./dcd-server(main+0x17) [0x5be877]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x3b77221b75]

According to addr2line, the line where it fails is autocomplete.d:104.

Sort result by best match

It would be nice if the server could return the result sorted by best match. Example:

module foo;

struct Foo
{
    string a;
    int b;
}

void main ()
{
    Foo foo;
    int c = foo. // cursor here
}

In the above code it's pretty easy to see that the best match is b. Because c is declared as int and the type of b is int as well. As a start, only simple algorithm can be used, basically just to check direct matches. No need to start with implicit conversions, alias this and so on.

Running DCD Server on Windows 7

Hi Brian,

I'm not sure if this is a bug or a configuration issue?

I was curious to see if DCD worked with Zeus.

When I run the server on Windows 7 (64 bit) I get this error:

C:\Program Files (x86)\Zeus>dcd-server.exe
Import directories: []
Startup complete
Shutting down sockets...
Sockets shut down.
std.socket.SocketOSException@std\socket.d(2438): Unable to set socket blocking: An operation was attempted on something
that is not a socket.
----------------
0x0047DF34 in @property void std.socket.Socket.blocking(bool)
0x0047BE54 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runMain()
0x0047BE8F in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runAll()
0x0047BA8D in _d_run_main
0x00470E0C in main
0x749D33AA in BaseThreadInitThunk
0x772B9F72 in RtlInitializeExceptionChain
0x772B9F45 in RtlInitializeExceptionChain
----------------

I got the same error running the dcd-server on Windows XP.

Running the gocode server on the same machine works fine:

C:\Program Files (x86)\Zeus>gocode.exe

The above command line starts the gocode server.

Cheers Jussi

Windows support

The server segfaults before the first line of "main()", so it's safe to say it doesn't work.

Segfault in AutocompleteVisitor

Resolving location of /home/dav1d/workspaces/d/BraLa/src/d/nbd/nbt.d

Program received signal SIGSEGV, Segmentation fault.
0x0000000000571229 in acvisitor.AutocompleteVisitor.visit() ()
(gdb) bt full
#0  0x0000000000571229 in acvisitor.AutocompleteVisitor.visit() ()
No symbol table info available.
#1  0x000000000057cdff in stdx.d.ast.Declaration.accept() ()
No symbol table info available.
#2  0x0000000000576f9f in stdx.d.ast.ASTVisitor.visit() ()
No symbol table info available.
#3  0x00000000005822ef in stdx.d.ast.TemplateDeclaration.accept() ()
No symbol table info available.
#4  0x0000000000579b9f in stdx.d.ast.ASTVisitor.visit() ()
No symbol table info available.
#5  0x000000000057f881 in stdx.d.ast.MixinTemplateDeclaration.accept() ()
No symbol table info available.
#6  0x00000000005786e7 in stdx.d.ast.ASTVisitor.visit() ()
No symbol table info available.
#7  0x000000000057cd63 in stdx.d.ast.Declaration.accept() ()
No symbol table info available.
#8  0x0000000000576f9f in stdx.d.ast.ASTVisitor.visit() ()
No symbol table info available.
#9  0x000000000057fa2c in stdx.d.ast.Module.accept() ()
No symbol table info available.
#10 0x00000000005726c0 in acvisitor.AutocompleteVisitor.visit() ()
No symbol table info available.
#11 0x000000000056e7ba in modulecache.ModuleCache.getSymbolsInModule() ()
No symbol table info available.
#12 0x000000000056e545 in modulecache.ModuleCache.addImportPath() ()
No symbol table info available.

That's the file: https://github.com/Dav1dde/nbd/blob/master/nbt.d

I will investigate this further.

Edit: -g -gc

esolving location of /home/dav1d/workspaces/d/BraLa/src/d/nbd/nbt.d

Program received signal SIGSEGV, Segmentation fault.
0x000000000057478d in _D9acvisitor19AutocompleteVisitor5visitMFC4stdx1d3ast11ConstructorZv (this=0x7ffff663df80, dec=0x7ffff6625c80) at acvisitor.d:159
159             symbol.calltip = format("%s this%s", parentSymbol.name,
(gdb) bt full
#0  0x000000000057478d in _D9acvisitor19AutocompleteVisitor5visitMFC4stdx1d3ast11ConstructorZv (this=0x7ffff663df80, dec=0x7ffff6625c80) at acvisitor.d:159
        _TMP1966 = 0x7ffff663df80
        symbol = 0x7ffff65c6900
        _TMP1967 = 0x7ffff65c6900
        parameterSymbols = {0x7ffff65c6800, 0x7ffff65c6780}
        __aggr3930 = {0x7ffff6625c00, 0x7ffff6625a80}
        __key3931 = 2
        parameter = 0x7ffff6625a80
        paramSymbol = 0x7ffff65c6780
        _TMP1969 = 0x7ffff65c6780
        _TMP1970 = {0x7ffff65c6800, 0x7ffff65c6780}
        p = 0x7ffff6627000
        functionBody = 0x7ffff663df80
        s = 0x7ffff663df80
        _TMP1972 = 0x57d251 <_D4stdx1d3ast10ASTVisitor5visitMFC4stdx1d3ast12StorageClassZv+105>
        __aggr3939 = 0x0
        __key3940 = 0
        parameterSymbol = 0x7ffff6627000
        _TMP1973 = 0x7ffff65c6980
        _TMP1974 = 0x5f4fd0 <acvisitor.AutocompleteVisitor.__vtbl()>



^C        _TMP1975 = Quit
(gdb) bt
#0  0x000000000057478d in _D9acvisitor19AutocompleteVisitor5visitMFC4stdx1d3ast11ConstructorZv (this=0x7ffff663df80, dec=0x7ffff6625c80) at acvisitor.d:159
#1  0x0000000000580e59 in _D4stdx1d3ast11Declaration6acceptMFC4stdx1d3ast10ASTVisitorZv (this=0x7ffff5ad3200, visitor=0x7ffff663df80) at dscanner/stdx/d/ast.d:952
#2  0x000000000057a899 in _D4stdx1d3ast10ASTVisitor5visitMFC4stdx1d3ast11DeclarationZv (this=0x7ffff663df80, declaration=0x7ffff5ad3200) at dscanner/stdx/d/ast.d:91
#3  0x00000000005867de in _D4stdx1d3ast19TemplateDeclaration6acceptMFC4stdx1d3ast10ASTVisitorZv (this=0x7ffff6627280, visitor=0x7ffff663df80) at dscanner/stdx/d/ast.d:2396
#4  0x000000000057d801 in _D4stdx1d3ast10ASTVisitor5visitMFC4stdx1d3ast19TemplateDeclarationZv (this=0x7ffff663df80, templateDeclaration=0x7ffff6627280) at dscanner/stdx/d/ast.d:199
#5  0x0000000000583b44 in _D4stdx1d3ast24MixinTemplateDeclaration6acceptMFC4stdx1d3ast10ASTVisitorZv (this=0x7ffff5ac2b40, visitor=0x7ffff663df80) at dscanner/stdx/d/ast.d:1696
#6  0x000000000057c1b1 in _D4stdx1d3ast10ASTVisitor5visitMFC4stdx1d3ast24MixinTemplateDeclarationZv (this=0x7ffff663df80, mixinTemplateDeclaration=0x7ffff5ac2b40)
    at dscanner/stdx/d/ast.d:148
#7  0x0000000000580dbd in _D4stdx1d3ast11Declaration6acceptMFC4stdx1d3ast10ASTVisitorZv (this=0x7ffff5ad3800, visitor=0x7ffff663df80) at dscanner/stdx/d/ast.d:948
#8  0x000000000057a899 in _D4stdx1d3ast10ASTVisitor5visitMFC4stdx1d3ast11DeclarationZv (this=0x7ffff663df80, declaration=0x7ffff5ad3800) at dscanner/stdx/d/ast.d:91
#9  0x0000000000583d0b in _D4stdx1d3ast6Module6acceptMFC4stdx1d3ast10ASTVisitorZv (this=0x7ffff5a98bc0, visitor=0x7ffff663df80) at dscanner/stdx/d/ast.d:1721
#10 0x0000000000575d3f in _D9acvisitor19AutocompleteVisitor5visitMFC4stdx1d3ast6ModuleZv (this=0x7ffff663df80, mod=0x7ffff5a98bc0) at acvisitor.d:364
#11 0x0000000000571b56 in _D11modulecache11ModuleCache18getSymbolsInModuleFAyaZAC7actypes8ACSymbol (moduleName=...) at modulecache.d:94
#12 0x00000000005718c4 in _D11modulecache11ModuleCache13addImportPathFAyaZv (path=...) at modulecache.d:64
#13 0x000000000050d4e0 in _Dmain (args=...) at server.d:113
#14 0x00000000005af92c in rt.dmain2._d_run_main() ()
#15 0x00000000005af45e in rt.dmain2._d_run_main() ()
#16 0x00000000005af97c in rt.dmain2._d_run_main() ()
#17 0x00000000005af45e in rt.dmain2._d_run_main() ()
#18 0x00000000005af41a in _d_run_main ()
#19 0x00000000005af267 in main ()

Unfortunatly I can't paste the full bt full traceback, since gdb stops "printing" it, I have to Ctrl+c it...

Make Textadept module work properly with Textadept 7.0

On line 23 of init.lua it should be textadept.editing.autocomplete_word(keywords) as the _M was dropped.

Apologies if you are not targeting beta versions of TA.

I'd also just like to complement your work on this project. It is excellent and the client/server architecture and ability to easily hook it up with programmable editors is awesome. DCD really improves my experience of working with my D projects.

Add support to the client to read from stdin

If the client can read from stdin I think it will be easier for text editors to handle unsaved files. Instead of: A. force saving the file or B. save the file to a temporary file. The editor can just pass what it has in the buffer to the client.

Ignore invalid requests

The server should ignore invalid requests like this:

Sockets shut down.
std.file.FileException@std/file.d(2394): /home/dav1d/workspaces/BraLa: No such file or directory

Instead of shutting down.

Allow find usages of symbol names

The server/client should be enhanced to allow to find all usages of the symbol under the cursor. Filenames and locations could then be returned by the server to allow plugins in the supported editors which highlight the usages.

Basic "auto" declaration support

DCD should be able to determine the types of variables in the following situations:

  • foreach loop where the symbol being iterated over is an array, associative array, or defines front()
  • new expressions, e..g. auto x = new Y;
  • variable is declared and assigned to a symbol field
  • variable is declared and assigned to the result of a function call

Crash when using . for include path

I get a segmentation fault when running

dcd-server -I .

Expected behavior is that it includes the current directory. Otherwise, works fine when using absolute pathing. Using revision 80a9956 compiled with dmd 2.063.2 on Arch Linux.

Share more information

Currently the identifiers format looks like this:

identifiers
parts   v
name    v
getPartByName   f

I think that should be changed to (4 spaces = 1 tab):

identifiers
v    parts
v    name
f    getPartByName 

Allowing the client/server to share more information about variables and functions, like variable type, return-type, qualifiers/attributes of functions (protected, const, nothrow etc.). Also function arguments:

identifiers
v    int[]    parts
v    string    name
f    Part[]    getPartByName(string name, int something)    const nothrow @safe

This alone allows nicer completions, but combined with the next point about calltips it will be amazing ;)

For calltips send not only the actual calltips but also identifiers which could be used as completion, furthermore send this information if the cursor is anywhere between ( and ):

identifiers
v    int[]    parts
v    string    name
f     float     getX()    @safe
calltips
void foo(string name, float x)

This would allow the plugin to smartly find out the current cursor position the argument list and display a completion list according to it, with its own group of best matching arguments (_ = cursor, () = completion list, [] = completion group):

foo(_) -> ([name], [parts, getX])
foo(name, _) -> ([getX], [parts, name])

Even better would be if the server would complete after a comma, and send the list accordingly, this would get rid of some logic in the plugin.

Column/Line Positions instead of Byte offsets

KTextEditor has no easy way of getting the correct byte offset, but you can easily query line and column of the cursor. Adding support in D to jump to this position is way easier than doing that in C++ with KTextEditor.

Allow semantic highlighting

The protocol could be enhanced to send more information to the client to allow semantic highlighting in the editor plugins. Semantic highlighting could include visual effects on class names, interface functions, constants etc.

DCD does not support templated declarations

Given the following code (vertical pipe is the cursor position)

struct SomeStruct(T) { T field; }
SomeStruct!(float) bar;
bar.field.|

DCD should show completions such as "max", "epsilon", etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.