<div dir="ltr">FYI this mailing list is going away very soon (hours), replaced by llvm.discourse.group.<div><br></div><div>Clangd handles locations in many places for various features - are you only concerned about diagnostic locations or other features too?</div><div>It'd be useful to file a bug with details (a minimal example, how you expect it to behave).</div><div><a href="https://github.com/clangd/clangd">https://github.com/clangd/clangd</a></div><div><br></div><div>However I can imagine what you want may be a lot of work/infeasible:</div><div><br></div><div>- Clang only needs to print the filenames where it claims the source is from, while clangd needs to point at a location in an actual file that the editor will display. In general #line directives can (and do!) point at files that don't exist or are out-of-sync with the files we're parsing.</div><div><br></div><div>- Clangd is designed to be used interactively while editing. If diagnostics appear in foo.newlang, but editing foo.newlang doesn't cause them to update, this is confusing.</div><div><br></div><div>- Clangd manipulates locations for output in many places for various features. It's likely we'd need to add #line handling on a case-by-case basis to each feature (many features require locations/ranges to properly nest, which #line doesn't guarantee).</div><div><br></div><div>- Clangd really targets C-family languages supported by clang - doing small cleanups to better support other use cases makes sense, but we can't really justify adding much complexity for this.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 1, 2022 at 6:38 PM Benedikt Weiß via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
I am currently using the clangd for writing my own language server <br>
implementation for a new programming language, let's call it newlang.<br>
<br>
In this new programming language, it is possible to write C++ source <br>
code in specific places, so it is possible to embed C++ code in specific <br>
syntax constructs. Afterwards the files are compiled to C++ to use the <br>
normal C++ toolchain.<br>
<br>
As you can imagine, the embedded C++ from the original file is now also <br>
contained in the generated C++ file but in other places (at other line <br>
numbers etc because of additional generated C++ code). So, the embedded <br>
C++ source code which was at, for example, line 52 (in the original file <br>
of the new programming language) is now at line 132 in the generated C++ <br>
file.<br>
<br>
To generate meaningful compiler messages, those places in the C++ file <br>
are annotated with #line directives which link back to the original file <br>
because you do not want to edit and analyze *generated* files but the <br>
original source file in the new programming language.<br>
<br>
So, if I am using the standalone clang compiler, everything is correct <br>
and as expected:<br>
<br>
benedikt@fedora:~$ clang /path/to/example_file.cxx<br>
/path/to/example_file.newlang:39:9: warning: expression result unused <br>
[-Wunused-value]<br>
<br>
because of something like<br>
<br>
#line 22 "/path/to/example_file.newlang"<br>
<br>
in the generated example_file.cxx. This is correct because the <br>
example_file.cxx is generated from the example_file.newlang and "links <br>
back" to the original location of the C++ source code, via those #line <br>
directives.<br>
<br>
Now my question is: How can I get the *clangd* to recognize/consider <br>
#line directives? I could not get it to work. clangd seems to ignore <br>
them. clangd compiles the file correctly and generates <br>
"publishDiagnostics" with the same warning and error messages etc but <br>
without considering the #line directives, it only considers the line <br>
numbers from the C++ file (in this example_file.cxx it would be like <br>
line 132).<br>
<br>
I also tried "-fuse-line-directives" but without success.<br>
<br>
<br>
Thanks you for your time.<br>
<br>
<br>
<br>
<br>
With kind regards,<br>
<br>
<br>
Benedikt Weiß<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div>