Pure-D / serve-d

D LSP server (dlang language server protocol server)
MIT License
200 stars 48 forks source link

importPaths in dub "configurations" is ignored where there are multiple, only the 1st config works #260

Open ryuukk opened 1 year ago

ryuukk commented 1 year ago

Let's take this dub:

{
    "name": "my_project",
    "targetPath": "bin",
    "workingDirectory": "bin",
    "stringImportPaths": [ "bin/" ],

    "configurations": [
        {
            "name": "app",
            "targetType": "executable",
            "targetName": "app",

            "sourcePaths": [
                "app/src",
            ],
            "importPaths": [
                "app/src",
            ],
        },
        {
            "name": "dll",
            "targetType": "dynamicLibrary",
            "targetName": "dll",

            "excludedSourceFiles": [
                "src"
            ],

            "sourcePaths": [
                "dll/src",
            ],
            "importPaths": [
                "dll/src",
            ],
        }
    ]
}

2 configs: 'app' and 'dll'

By default i get completion for everything that is specified in importPaths from 'app' configuration

app/src/main.d <---- here i can 'import data;' and get completion
app/src/data.d

However, when i am in:

dll/src/dllmain.d <--- here, i can't 'import other;', i get 0 completion
dll/src/other.d

To fix that i must add 'importPaths' at the root of the 'dub.json' file, wich is the indication that 'importPaths' is ignored from the configuration

    "importPaths": [
        "dll/src"
    ],

And yes, i tried to switch it here: image

It's on 'dll' and no changes, doesn't work

ryuukk commented 1 year ago
[0] C:\Users\ryuukk\AppData\Roaming\code-d\bin\dcd-server.exe

[1] --port

[2] 9166

[3] -IC:\D\dmd2\windows\bin\..\..\src\phobos

[4] -IC:\D\dmd2\windows\bin\..\..\src\druntime\import

[FULL] C:\Users\ryuukk\AppData\Roaming\code-d\bin\dcd-server.exe --port "9166" -IC:\D\dmd2\windows\bin\..\..\src\phobos -IC:\D\dmd2\windows\bin\..\..\src\druntime\import

dcd-server was starting with these paths, why it's missing the projects paths?

serve-d should parse all the dub.json file and append to -I all the import paths

then serve-d should communicate with dcd-server based on what file you are working with and filter things based on the configuration

I think i'll write an alternative to serve-d it's too slow to compile for me to do any work with it, all my projects compile under 1 second

lucasnethaj commented 1 year ago

@WebFreak001 could you maybe point me in the right direction if i want to fix this? I am not really familliar with the codebase

WebFreak001 commented 1 year ago

@lucasnethaj the import paths are gathered from DUB inside workspaced/com/dub.d (it registers itself through importPathProvider = &imports; in load())

in workspaced/com/dcd.d it uses the importPathProvider through just the property importPaths, e.g. refreshImports

now this may either be:

  1. the configuration isn't properly loaded inside dub.d / it doesn't return the correct import paths in the provider
  2. DCD doesn't get its import paths reloaded properly

Back when I implemented the dcd code it also wasn't possible to remove import paths, but that is now possible. That might also be a factor at play here.

lucasnethaj commented 1 year ago

Okay thank you, i'll give it a look :-)