[llvm-bugs] [Bug 44088] New: Getting "trying to get AST for non-added document" from Clangd

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 20 08:20:38 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44088

            Bug ID: 44088
           Summary: Getting "trying to get AST for non-added document"
                    from Clangd
           Product: clang-tools-extra
           Version: unspecified
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: clangd
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ken.domino at gmail.com
                CC: llvm-bugs at lists.llvm.org

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191120/91525ae5/attachment-0001.html>


More information about the llvm-bugs mailing list