How to get serve-d to find dub dependencies

Renato renato at athaydes.com
Sat Dec 23 16:28:28 UTC 2023


On Saturday, 23 December 2023 at 16:13:01 UTC, Renato wrote:
> I am trying to use dependencies, so I need dub.
>
> On emacs, the imports from dub libraries cannot be found, even 
> though dub can build it fine.
>
> How can I get emacs/serve-d to "see" the libraries added by dub?
>
> I found that dub has a command for letting the compiler know 
> about the load paths:
>
> ```
> dub describe --data=import-paths
> ```
>
> This shows the correct paths for the project, so perhaps I can 
> pass this to serve-d somehow?

I've managed to kind of hack it by adding the paths to my 
`.dir-locals.el`:

```
((nil . ((indent-tabs-mode . nil)
          (tab-width . 4)))
  (d-mode . ((compile-command . "dmd -L-ld_classic -run")
             (eglot-workspace-configuration . (:importPath 
("/Users/renato/.dub/packages/console-colors/1.1.1/console-colors/source/"))))))
```

Far from ideal but this makes it half work... it actually shows 
the definitions in the library now and I can even navigate to the 
source, but still for some reason the import is shown as an error:

```
Expected 'consolecolors.d' or 'consolecolors/package.d' in one of 
the following import paths:
```

I believe that's because this is coming from d-mode, not serve-d 
(as serve-d actually "sees" it now)?!

Anyway, would love to know how to get serve-d to automatically 
detect dub libs.

Does the VS Code do that? If it does, this should work also on 
emacs.


More information about the Digitalmars-d-learn mailing list