dlang-community / D-Scanner

Swiss-army knife for D source code
Boost Software License 1.0
240 stars 80 forks source link

Support for compilation database #930

Open ricardaxel opened 1 year ago

ricardaxel commented 1 year ago

Some build systems (bazel, meson, ..) can generate compilation database, that contain information about import directories.

For D code, such file looks like that :

[
      { 
        "directory": "build", 
        "command": "dmd -I=hello.p -I=. -I=.. -color=on -wi -g -debug -makedeps=hello.p/main.d.o.deps -of=hello.p/main.d.o -c ../main.d",
        "file": "../main.d",
        "output": "hello.p/main.d.o"
      }
    ]

Would it be possible to add an option --compile-database that could automatically resolve imports from compilation database ? I might do a PR if you're ok with the concept.

WebFreak001 commented 1 year ago

D-Scanner doesn't currently properly expose the import path setting, although it is used for some checks. However it fails even including phobos on its own and also explicitly hides the warnings that show that your import paths are not configured properly, to not break compatibility with people's projects that would suddenly start giving linter warnings just after upgrading the tool and not having the newly exposed old feature configured.

So it would first be a good idea to properly expose the import paths / dsymbol index through the D-Scanner API (for serve-d to manipulate) and then also include code to automatically include the default import paths for the current / user specified compiler that also works in the standalone version.

A lot of this work, including compilation database support and extended linter things, are already implemented in serve-d, however it's not possible to run the improved linting standalone for CI output.