<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59254>59254</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clangd] Wrong compilation flags are chosen for some header files
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Febbe
      </td>
    </tr>
</table>

<pre>
    When having a huge project structure with multiple dependencies and also multiple targets,
header files, which do not have a main source file, might fail to be analyzed via clangd.

This happens, because clangd is choosing a source file, that is completely out of context / an independent other target.

For example, the compile_command.json contains sources of:

```
C:\cpm_cache\OpenMesh\*
C:\Users\myuser\Desktop\workspace\my\project\subproject1\include\subproject1\*
C:\Users\myuser\Desktop\workspace\my\project\subproject2\include\subproject2\*
C:\Users\myuser\Desktop\workspace\my\project\subproject1\src\*
C:\Users\myuser\Desktop\workspace\my\project\subproject2\src\*
C:\Users\myuser\Desktop\workspace\my\project\executable\*
```

It might be, that a header, which is located in `subproject1\include\subproject1\` is analyzed with compile flags from a source in `C:\cpm_cache\OpenMesh\*` But the header is never included in that file. And there is not even the include path appended, which refers to the header.

My proposal:
 - Do not pretend to analyze a header file with the compile options of another unrelated source file. 
  - This is the case, when no include in a source file in combination with the include paths refer to the header.
 - Add a warning to a header file, which fails due to too many errors, where the compile commands actually came from.
 - Don't emit any errors and warnings for unresolved symbols, when the analysis has been stopped due to too many errors.
  - They are nearly all false positives anyway.
 - Change the search direction to source files with a minimal relative path distance.
 

 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vk2P2zYQ_TXyhYhhy5bXPvjg7MJAD0EvLXIMKGpsMaFIgUPZ6_76PpJaW5umaA8JYEiUSM178_XGtWtu-88tWdHKi7ZnIUU7nEn03n0lFQQHP6gweBJXHVrRDSbo3pBoqCfbkFWaWEjbCGnYPbaD9GcKXJTP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