I am currently using the clangd for writing my own language server implementation for a new programming language, let's call it newlang.
In this new programming language, it is possible to write C++ source code in specific places, so it is possible to embed C++ code in specific syntax constructs. Afterwards the files are compiled to C++ to use the normal C++ toolchain.
As you can imagine, the embedded C++ from the original file is now also contained in the generated C++ file but in other places (at other line numbers etc because of additional generated C++ code). So, the embedded C++ source code which was at, for example, line 52 (in the original file of the new programming language) is now at line 132 in the generated C++ file.
To generate meaningful compiler messages, those places in the C++ file are annotated with #line directives which link back to the original file because you do not want to edit and analyze *generated* files but the original source file in the new programming language.
So, if I am using the standalone clang compiler, everything is correct and as expected:
benedikt@fedora:~$ clang /path/to/example_file.cxx
/path/to/example_file.newlang:39:9: warning: expression result unused [-Wunused-value]
because of something like
#line 22 "/path/to/example_file.newlang"
in the generated example_file.cxx. This is correct because the example_file.cxx is generated from the example_file.newlang and "links back" to the original location of the C++ source code, via those #line directives.
Now my question is: How can I get the *clangd* to recognize/consider #line directives? I could not get it to work. clangd seems to ignore them. clangd compiles the file correctly and generates "publishDiagnostics" with the same warning and error messages etc but without considering the #line directives, it only considers the line numbers from the C++ file (in this example_file.cxx it would be like line 132).
I also tried "-fuse-line-directives" but without success.
Thanks you for your time.
With kind regards,