Autocompletion fails for configuration-specific dependencies
Originally posted this on the DCD repo but posting it here instead, as suggested.
Example dub.sdl:
name "dcd-unittest-bug"
configuration "application" {
targetType "executable"
}
configuration "unittest" {
dependency "unit-threaded" version="~>1.0.11"
}
And an example source/app.d (caret is at |):
import std.stdio;
version(unittest)
{
import unit_threaded : |;
}
else
{
void main()
{
writeln("Edit source/app.d to start your project.");
}
}
In code-d, with the caret at that position, when I trigger autocompletions it doesn't show me any symbols from unit-threaded. The output pane in VSCode shows the following:
[Trace - 10:59:51 p.m.] Sending request 'textDocument/completion - (16)'.
Params: {
"textDocument": {
"uri": "file:///home/andrej/Documents/Scribbles/dcd-unittest-bug/source/app.d"
},
"position": {
"line": 4,
"character": 27
},
"context": {
"triggerKind": 1
}
}
2020-12-05T22:59:51.776 [trace] app.d:79:processRequest Calling provideComplete
2020-12-05T22:59:51.776 [trace] complete.d:289:provideComplete Completing from instance /home/andrej/Documents/Scribbles/dcd-unittest-bug
2020-12-05T22:59:51.780 [trace] dcd.d:180:__lambda5 Server: 2020-12-05T22:59:51.780 [info] main.d:296:runServer Getting completions
2020-12-05T22:59:51.781 [trace] dcd.d:180:__lambda5 Server: 2020-12-05T22:59:51.781 [warning] complete.d:389:importCompletion Could not resolve location of unit_threaded
2020-12-05T22:59:51.781 [trace] dcd.d:180:__lambda5 Server: 2020-12-05T22:59:51.781 [info] main.d:313:runServer Request processed in 0 milliseconds
2020-12-05T22:59:51.781 [trace] dcd.d:503:__lambda3 DCD Client:
2020-12-05T22:59:51.786 [trace] complete.d:601:provideSnippetComplete got 0 snippets fitting in this context: []
[Trace - 10:59:51 p.m.] Received response 'textDocument/completion - (16)' in 51ms.
Result: {
"isIncomplete": false,
"items": []
}
If I move unit-threaded out of the "unittest" configuration block then restart VSCode, the autocompletion works. However, I would rather have my test-only dependencies declared in the unittest configuration block in the dub file.
you can change the dub configuration which serve-d uses in the status bar, that might already be enough (also try reloading import paths when you did that if it's not enough and report back if that did it)

Change the second last item there (configuration) from debug to unittest
Unfortunately that didn't work, even after reloading import paths. I tried it without the version(unittest) but it still didn't work. Then I tried reloading the window for good measure, but it just reset the chosen configuration back to debug.
I stumbled upon a workaround. While working on a different project (but with a similar dub.sdl as above), and I decided to try your suggestion again. But I misremembered, so instead of changing debug to unittest, I changed application to unittest (the one to the left of x86_64), and it worked!
To confirm, I tried it out in the same test project I used to create this issue and it worked there too. I did need to reload import paths manually though. Anyway, it works. It would still be nice if you could see the suggestions without having to change that option but this is still something.
oh yeah makes sense! you have to change the configuration, (--config) not the build type (--build) as that is also what you configure.
Changing both should work well too