<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Getting "trying to get AST for non-added document" from Clangd"
   href="https://bugs.llvm.org/show_bug.cgi?id=44088">44088</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Getting "trying to get AST for non-added document" from Clangd
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang-tools-extra
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows XP
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>clangd
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ken.domino@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I am trying to get VS2019 (v 16.3.9 community edition) to work with clangd.exe
on Windows 10. I wrote a simple "Hello world" program, installed version 9.0 of
LLVM, which includes clangd.exe, for Windows. Clang.exe compiles the test
program fine and the a.out runs.

In order to get VS2019 to work with Clangd, I wrote an extremely small
extension that uses Microsoft.VisualStudio.LanguageServer.Client library, which
really contains all the LSP code. I wrote another extension that works with the
Eclipse LSP server for Java source code and that works fine.

In the extension, I spawn Clangd.exe and this is the output with --log=verbose.

I[11:01:54.734] clangd version 9.0.0 (tags/RELEASE_900/final)
I[11:01:54.741] Working directory:
C:\Users\kenne\source\repos\ConsoleApplication2\ConsoleApplication2
I[11:01:54.749] argv[0]: C:\Program Files\LLVM\bin\clangd.exe
I[11:01:54.761] argv[1]:
--compile-commands-dir=C:/Users/kenne/source/repos/ConsoleApplication2/ConsoleApplication2/compile_commands.json
I[11:01:54.763] argv[2]: --log=verbose
I[11:01:54.764] Starting LSP over stdin/stdout
V[11:01:54.766] <<<
{"id":2,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"supportsVisualStudioExtensions":true,"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dynamicRegistration":false},"codeLens":{"dynamicRegistration":false},"completion":{"completionItem":{"commitCharactersSupport":true,"snippetSupport":false},"contextSupport":false,"dynamicRegistration":false},"definition":{"dynamicRegistration":false},"documentHighlight":{"dynamicRegistration":false},"documentLink":{"dynamicRegistration":false},"documentSymbol":{"dynamicRegistration":false},"foldingRange":{"dynamicRegistration":false,"lineFoldingOnly":false},"formatting":{"dynamicRegistration":false},"hover":{"contentFormat":["plaintext"],"dynamicRegistration":false},"implementation":{"dynamicRegistration":false},"onTypeFormatting":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":true},"rangeFormatting":{"dynamicRegistration":false},"references":{"dynamicRegistration":false},"rename":{"dynamicRegistration":false},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"documentationFormat":["plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true,"dynamicRegistration":false,"willSave":false,"willSaveWaitUntil":false},"typeDefinition":{"dynamicRegistration":false}},"workspace":{"applyEdit":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":false},"executeCommand":{"dynamicRegistration":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true}}},"processId":2608,"trace":"off"}}

I[11:01:54.860] <-- initialize(2)
I[11:01:54.867] --> reply:initialize(2) 7 ms
V[11:01:54.868] >>>
{"id":2,"jsonrpc":"2.0","result":{"capabilities":{"codeActionProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",">",":"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"hoverProvider":true,"referencesProvider":true,"renameProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":2,"typeHierarchyProvider":true,"workspaceSymbolProvider":true}}}

V[11:01:57.168] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[11:01:57.170] <-- initialized
I[11:01:57.170] unhandled notification initialized
V[11:01:57.544] <<<
{"id":3,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///C:/Users/kenne/source/repos/ConsoleApplication2/ConsoleApplication2/test.cpp"}}}

I[11:01:57.551] <-- textDocument/documentSymbol(3)
I[11:01:57.551] --> reply:textDocument/documentSymbol(3) 0 ms, error: -32602:
trying to get AST for non-added document
V[11:01:57.552] >>> {"error":{"code":-32602,"message":"trying to get AST for
non-added document"},"id":3,"jsonrpc":"2.0"}

The compile_commands.json file was generated using cmake/ninja. It looks like
this:

[
{
  "directory":
"C:/Users/kenne/source/repos/ConsoleApplication2/ConsoleApplication2",
  "command":
"C:\\PROGRA~2\\MIB055~1\\2019\\COMMUN~1\\VC\\Tools\\MSVC\\1423~1.281\\bin\\Hostx86\\x86\\cl.exe
 /nologo /TP   /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1  
/FoCMakeFiles\\app.dir\\test.obj /FdTARGET_COMPILE_PDB /FS -c
C:\\Users\\kenne\\source\\repos\\ConsoleApplication2\\ConsoleApplication2\\test.cpp",
  "file":
"C:/Users/kenne/source/repos/ConsoleApplication2/ConsoleApplication2/test.cpp"
}
]

I have tried to get this to work in a number of different ways by altering the
options to Clangd and the .json file to get past this "non-added document"
error. However, I believe here is that either Clangd or the LSP client that MS
wrote does not follow the LSP protocol. Can someone guess why Clangd is not
working?

--Ken Domino</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>