DCD D Language Autocomplete

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

DCD D Language Autocomplete

Post by jussij »

The latest version of Zeus has support for DCD, which can be used to provide D language autocomplete and code navigation.

DCD Setup Instructions
To make this work do the following:
  1. Make sure you are running the latest version of Zeus found here: https://www.zeusedit.com/download.html
  2. Download the latest release of DCD found here: https://github.com/dlang-community/DCD/releases
  3. Unzip the DCD client and server utilities and make sure they are somewhere in the PATH, And easy option is to put these files in this Zeus folder location: C:\Users\<your User ID>\AppData\Local\Programs\Zeus (x64)\zGNU
  4. Start Zeus and use the Macros menu to start the DCD server, making sure it starts correctly
  5. With the server running the dot complete and brace complete should now work
  6. Edit some D code and you should see intellisense on the dot key and the open bracket key
NOTE: For all the macros mention below, by using the Options, Editor Options menu and in the Keyboard Mapping section, the macros found can be bound to the keyboard to making it possible to fire these macros using a key press.

Automatically Starting/Stopping the DCD Server
By using the Zeus application starting and application closing triggers it is also possible to configure Zeus to automatically start and stop the DCD server.

Use the Options, Editor Options menu and select the editor Triggers panel.

For the Application Starting use the dcd_app_starting.lua script.

For the Application Closing use the dcd_app_closing.lua script.

With these scripts in place Zeus will manage the starting and stopping of the DCD server.

Manually Starting/Stopping the DCD Server
For the autocomplete to work the DCD server first needs to be started, using the Macros menu shown below:
dcd_menu.png
dcd_menu.png (122.85 KiB) Viewed 4844 times
NOTE: That menu will only show if a D file is being edited.

Example of Dot Completion
Image

Example of Brace Completion
Image

Example of Display Document Comment
Consider this sample D code where the | indicates the cursor location:

Code: Select all

module main;

import std.stdio;
import std.datetime;

/*******************************
* This is a D Doccumment for the TestStruct structure.
*
* This comment is displayed in a tool tip.
*/
struct TestStruct
{
    int test;
}

void main()
{
    TestStruct|
}
Running that display documentation macro from the menu will results in the following tooltip:
Image

Example of Find Declaration
Consider this code:

Code: Select all

import std.stdio;
import std.datetime;

int main(string[] args)
{
	StopWatch sw = StopWatch(AutoStart.yes);

	return 0;
}
Placing the cursor on the StopWatch word and using the Goto Declaration macro menu will take you to this file:

Code: Select all

C:\dmd2\src\phobos\std\datetime.d
and to this code location:

Code: Select all

@safe struct StopWatch
{
public:
....
NOTE: Other Zeus, D language specific features can be found here:
Using the dfmt with Zeus
Using the Dscanner (D Language) inside Zeus
Using the D Programming Language with Zeus
Last edited by jussij on Thu Jan 30, 2014 11:11 pm, edited 3 times in total.
sturt
Posts: 31
Joined: Wed Mar 13, 2024 12:57 am

Re: DCD D Language Autocomplete

Post by sturt »

I followed these instructions exactly but the paths for library source being just the single path C:\dmd2\src\phobos is wrong mostly because of two things.

1. The default installation directory of DMD is C:\D\dmd2 nowadays, not C:\dmd2.
2. D's runtime system has been separated out into C:\D\dmd2\src\runtime nowadays.

Bearing these in mind, I edited dcd_app_starting.lua so that the DCD server is started with

Code: Select all

os.execute('start "DCD Server" "dcd-server.exe" "-iC:/D/dmd2/src/phobos" "-iC:/D/dmd2/src/druntime/src"')
and this took care of most but not all problems and the solution basically worked.

I'll post more here if and when I resolve remaining "can't find" problems.
sturt
Posts: 31
Joined: Wed Mar 13, 2024 12:57 am

Re: DCD D Language Autocomplete

Post by sturt »

Tried the "Goto Declaration" action of DCD to find the declaration of Object which should be in object.d in the druntime source (see previous message), and got this.

Code: Select all

---------------------------------------------------------------------------
      Zeus IDE - Version 3.99bj
      Copyright (c) Xidicone P/L 2024  All rights reserved.
---------------------------------------------------------------------------
 **** Unregistered Software. To be used for evaluation purposes only. ****
---------------------------------------------------------------------------

Traceback (most recent call last):
  File "C:\Users\sturt\AppData\Local\Programs\Zeus (x64)\zScript\dcd_goto_declaration.py", line 28, in <module>
    key_macro() # run the macro
    ^^^^^^^^^^^
  File "C:\Users\sturt\AppData\Local\Programs\Zeus (x64)\zScript\dcd_goto_declaration.py", line 26, in key_macro
    dcd_code.symbolLocation()
  File "C:\Users\sturt\AppData\Local\Programs\Zeus (x64)\zScript\dcd_code.py", line 326, in symbolLocation
    code = loadFile(current_file, result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sturt\AppData\Local\Programs\Zeus (x64)\zScript\dcd_code.py", line 216, in loadFile
    line = buffer.count('\n')
           ^^^^^^^^^^^^^^^^^^
TypeError: argument should be integer or bytes-like object, not 'str'

PYTHONHOME=


PYTHONPATH=
Macro script generated '116' Debug, Error and/or Warning message(s).
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: DCD D Language Autocomplete

Post by jussij »

This is an unfortunate side effect caused by the age of these DCD macros.

As I would have mentioned in other posts, D language support was added to Zeus more than a decade ago, so it is now dated.

The issue you have run into in this case relates to that aging of that macro code.

In particular, at the time the macro was written, Zeus was running Python 2.xx but now Zeus is running Python 3.xx and one of the breaking changes between those versions of Python was the changing of strings from ASCII to Unicode.

As the trace shows the error happens at this file and line location:

Code: Select all

C:\Users\sturt\AppData\Local\Programs\Zeus (x64)\zScript\dcd_code.py", line 216
NOTE: You can click on that line in the output window and Zeus will load the file at that line.

This is the line of code that is at fault:

Code: Select all

line = buffer.count('\n')
With this being the error message:
TypeError: argument should be integer or bytes-like object, not 'str'
And this is exactly the problem mentioned earlier; the buffer is a byte array but the String is Unicode.

Could you try changing the line to read as follows:

Code: Select all

line = buffer.count(b'\n')
The line at location 230 will also need to be changed to read as follows:

Code: Select all

cursor = buffer.rindex(b'\n')
Cheers Jussi
sturt
Posts: 31
Joined: Wed Mar 13, 2024 12:57 am

Re: DCD D Language Autocomplete

Post by sturt »

Okay, did that, and it fixed the problem. Thank you. Explanation understood.
Post Reply