www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to configure D autocompletion in Vim?

reply p.shkadzko <p.shkadzko gmail.com> writes:
I'd like to set up autocompletion in Vim akin to VS Code "code-d" 
plugin which uses DCD server for completion. According to 
https://wiki.dlang.org/D_in_Vim, one can use dutyl plugin for 
this purpose. I have installed the plugin as well as 
dcd-server/client, Dscanner and dfmt, everything that was 
mentioned in dutyl README. However, after starting the server and 
working on a D script I am not getting any autocompletion results.
Moreover, I simply don't know how to invoke dutyl autocompletion. 
Although looking into the plugin source code, I believe 
autocompletion should just work once you type "." or parenthesis. 
It does not. This is how my .vimrc set for dutyl:

let g:dutyl_stdImportPaths=['/usr/bin/dmd']
let g:dutyl_dontUseVimProc=1

If would be great if some D Vimers shared their setup or gave and 
advice on how to configure D autocompletion in Vim.
Dec 26 2019
next sibling parent reply user7892 <user7892 vlognet.ch> writes:
On Thursday, 26 December 2019 at 18:38:23 UTC, p.shkadzko wrote:
 I'd like to set up autocompletion in Vim akin to VS Code 
 "code-d" plugin which uses DCD server for completion. According 
 to https://wiki.dlang.org/D_in_Vim, one can use dutyl plugin 
 for this purpose. I have installed the plugin as well as 
 dcd-server/client, Dscanner and dfmt, everything that was 
 mentioned in dutyl README. However, after starting the server 
 and working on a D script I am not getting any autocompletion 
 results.
 Moreover, I simply don't know how to invoke dutyl 
 autocompletion. Although looking into the plugin source code, I 
 believe autocompletion should just work once you type "." or 
 parenthesis. It does not. This is how my .vimrc set for dutyl:

 let g:dutyl_stdImportPaths=['/usr/bin/dmd']
 let g:dutyl_dontUseVimProc=1

 If would be great if some D Vimers shared their setup or gave 
 and advice on how to configure D autocompletion in Vim.
do you get something after `void main(){ int.` ?. This invokes builtin completions but generally DCD needs to know a few root paths to D libraries. So if the sample I give you works then you must certainly configure dcd so that it knows phobos sources path and druntime sources path.
Dec 26 2019
parent reply p.shkadzko <p.shkadzko gmail.com> writes:
On Thursday, 26 December 2019 at 18:59:16 UTC, user7892 wrote:
 do you get something after

     `void main(){ int.`

 ?. This invokes builtin completions but generally DCD needs to 
 know a few root paths to D libraries. So if the sample I give 
 you works then you must certainly configure dcd so that it 
 knows phobos sources path and druntime sources path.
No, I am not getting any response from Vim after typing "int." inside main(){}. I tested dcd-server in console and it works as expected: $ echo | dcd-client --search toImpl /usr/include/dlang/dmd/std/conv.d f 55647 /usr/include/dlang/dmd/std/conv.d f 54285 /usr/include/dlang/dmd/std/conv.d f 52624 /usr/include/dlang/dmd/std/conv.d f 52314 /usr/include/dlang/dmd/std/conv.d f 45257 /usr/include/dlang/dmd/std/conv.d f 43253 /usr/include/dlang/dmd/std/conv.d f 39946 /usr/include/dlang/dmd/std/conv.d f 37388 /usr/include/dlang/dmd/std/conv.d f 29814 /usr/include/dlang/dmd/std/conv.d f 25478 /usr/include/dlang/dmd/std/conv.d f 21394 /usr/include/dlang/dmd/std/conv.d f 19900 /usr/include/dlang/dmd/std/conv.d f 19137 /usr/include/dlang/dmd/std/conv.d f 18129 /usr/include/dlang/dmd/std/conv.d f 17787 /usr/include/dlang/dmd/std/conv.d f 14365 dcd-server response 2019-12-26T21:07:55.997 [info] main.d:130:runServer Starting up... 2019-12-26T21:07:55.997 [info] server.d:94:loadConfiguredImportDirs Loading configuration from /etc/dcd.conf 2019-12-26T21:07:55.997 [info] main.d:157:runServer Cleaning up old socket file at /run/user/1000/dcd.socket 2019-12-26T21:07:55.998 [info] main.d:164:runServer Listening at /run/user/1000/dcd.socket 2019-12-26T21:07:55.998 [info] main.d:181:runServer Import directories: /usr/include/dlang/dmd 2019-12-26T21:07:55.998 [info] main.d:187:runServer 0 symbols cached. 2019-12-26T21:07:55.998 [info] main.d:188:runServer Startup completed in 0 milliseconds. 2019-12-26T21:16:20.015 [warning] first.d:459:visit Could not resolve location of module 'ldc/intrinsics' 2019-12-26T21:16:20.225 [warning] first.d:459:visit Could not resolve location of module 'core/sys/openbsd/sys/cdefs' 2019-12-26T21:16:20.310 [warning] first.d:459:visit Could not resolve location of module 'gcc/builtins' 2019-12-26T21:16:20.314 [warning] first.d:459:visit Could not resolve location of module 'gcc/builtins' 2019-12-26T21:16:20.334 [warning] first.d:459:visit Could not resolve location of module 'core/sys/netbsd/execinfo' 2019-12-26T21:16:20.546 [warning] first.d:459:visit Could not resolve location of module 'core/sys/openbsd/sys/cdefs' 2019-12-26T21:16:20.903 [info] main.d:302:runServer Request processed in 1250 milliseconds
Dec 26 2019
parent user7892 <user7892 vlognet.ch> writes:
On Thursday, 26 December 2019 at 19:20:18 UTC, p.shkadzko wrote:
 On Thursday, 26 December 2019 at 18:59:16 UTC, user7892 wrote:
 do you get something after

     `void main(){ int.`

 ?. This invokes builtin completions but generally DCD needs to 
 know a few root paths to D libraries. So if the sample I give 
 you works then you must certainly configure dcd so that it 
 knows phobos sources path and druntime sources path.
No, I am not getting any response from Vim after typing "int." inside main(){}. I tested dcd-server in console and it works as expected:
okay so it's clearly not what I imagined that could be the problem.
Dec 26 2019
prev sibling next sibling parent Laurent =?UTF-8?B?VHLDqWd1aWVy?= <laurent.treguier.sink gmail.com> writes:
On Thursday, 26 December 2019 at 18:38:23 UTC, p.shkadzko wrote:
 I'd like to set up autocompletion in Vim akin to VS Code 
 "code-d" plugin which uses DCD server for completion. According 
 to https://wiki.dlang.org/D_in_Vim, one can use dutyl plugin 
 for this purpose. I have installed the plugin as well as 
 dcd-server/client, Dscanner and dfmt, everything that was 
 mentioned in dutyl README. However, after starting the server 
 and working on a D script I am not getting any autocompletion 
 results.
 Moreover, I simply don't know how to invoke dutyl 
 autocompletion. Although looking into the plugin source code, I 
 believe autocompletion should just work once you type "." or 
 parenthesis. It does not. This is how my .vimrc set for dutyl:

 let g:dutyl_stdImportPaths=['/usr/bin/dmd']
 let g:dutyl_dontUseVimProc=1

 If would be great if some D Vimers shared their setup or gave 
 and advice on how to configure D autocompletion in Vim.
I would recommend using a language server [1] for this. You can install either Serve-D [2] or DLS [3], then use one of the many Vim/Neovim plugins [4] to use one of those servers. The best explanation for what language servers are and how they work is probably the official one [5]; but in a nutshell, it boils down to deferring things such as autocompletion to an external program, just like DCD, except those programs (the "language servers") follow a specification (the "Language Server Protocol") to make them usable with any editor that also conforms to the spec. Very often, for editors, the Language Server Protocol is implemented via plugins, and Vim and Neovim have 5 plugins listed for this [4], so you have ample choice on what you'd prefer to use. Each one of them should have the instructions you need to get started in their repository's README. [1] https://microsoft.github.io/language-server-protocol [2] https://github.com/Pure-D/serve-d [3] https://github.com/d-language-server/dls [4] https://microsoft.github.io/language-server-protocol/implementors/tools [5] https://microsoft.github.io/language-server-protocol/overview
Dec 26 2019
prev sibling parent p.shkadzko <p.shkadzko gmail.com> writes:
On Thursday, 26 December 2019 at 18:38:23 UTC, p.shkadzko wrote:
 I'd like to set up autocompletion in Vim akin to VS Code 
 "code-d" plugin which uses DCD server for completion. According 
 to https://wiki.dlang.org/D_in_Vim, one can use dutyl plugin 
 for this purpose. I have installed the plugin as well as 
 dcd-server/client, Dscanner and dfmt, everything that was 
 mentioned in dutyl README. However, after starting the server 
 and working on a D script I am not getting any autocompletion 
 results.
 Moreover, I simply don't know how to invoke dutyl 
 autocompletion. Although looking into the plugin source code, I 
 believe autocompletion should just work once you type "." or 
 parenthesis. It does not. This is how my .vimrc set for dutyl:

 [...]
It appears that I added to Windows PATH a bin folder with precompiled dmd binaries but not with phobos source files. dutyl requires a path to phobos sources. Thank you guys.
Dec 28 2019