[clangd-dev] New LSP language service supporting Swift and C-family languages, using clangd
Argyrios Kyrtzidis via clangd-dev
clangd-dev at lists.llvm.org
Tue Oct 23 13:29:32 PDT 2018
> On Oct 23, 2018, at 12:10 PM, Sam McCall <sammccall at google.com> wrote:
>
> On Tue, Oct 23, 2018, 20:34 Argyrios Kyrtzidis <akyrtzi at gmail.com <mailto:akyrtzi at gmail.com>> wrote:
> Since you started looking at background indexing functionality here’s some feedback based on our experiences, which will also provide some context for why we pursued index-while-building.
> Yes, when looking at your designs we saw there are huge benefits to index-while-build when you can use the "real" build.
>
> This relies on on the build toolchain being a recent enough/version-locked clang so that it produces usable IWB output.
> I think this is ~always the case for Xcode+mac and ~never for cmake+linux type projects. The system compiler is probably GCC most of the time!
>
> So we figured we needed to have a solid story without relying on actual index-while-build. With some sadness!
> (We actually do have a build-integrated indexer internally at Google where we control the toolchain)
To clarify a bit more, we still have a ‘background indexer’ but what it does is that it essentially invokes clang with ‘-fsyntax-only’ and ‘-index-store-path’ in order to get the index data, the same data that we would get if the file is built.
We have similar situations where a project doesn’t actually produce index data during building, e.g. CMake-generated or the Unreal project, in which case we fallback to getting the data from the background indexer.
That means that even if the system compiler is GCC you could still use the mechanism by essentially doing a ‘-fsyntax-only’ “build" in the background. However if the project is able to use clang for building then it can naturally take advantage of generating the same data during a build.
>
> We haven’t looked into Dex in details but it seems that it could play the role of what we currently use LMDB for, speed up queries to efficiently figure out where certain information resides in the record files, generated by index-while-building.
>
> There's a couple of layers: the token/posting list/iterator stuff is fairly generic search engine machinery.
> If the lookup you need is something like "top N items whose properties satisfy some boolean expression tree" it might fit the bill.
>
> In top of that, the actual SymbolIndex implementation implements the fuzzyFind operation we use for code completion. That might be useful if it's harder to build such things on LMDB.
>
> The biggest limitation is these structures aren't incremental - we have to rebuild when the data changes. So in practice we overlay frequently-changing data (memindex).
>> One question I have is a practical one - I'm sure changes are needed to clangd, are these likely to happen upstream or in a fork/merge cycle?
>
> CC’ed AlexL and JanK, they can speak more about this. Beyond clangd, I’d like to also mention that we’ll be resuming our upstreaming effort for the index-while-building patches.
>
>>
>> Looking forward to seeing more details!
>> Cheers, Sam
>>
>> On Tue, Oct 23, 2018 at 8:32 AM Argyrios Kyrtzidis via clangd-dev <clangd-dev at lists.llvm.org <mailto:clangd-dev at lists.llvm.org>> wrote:
>> Hey all,
>>
>> We've recently announced that we'll be starting a new open-source project for an LSP language service supporting Swift and C-family languages, see more details in the announcement post (https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform <https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform>). I wanted to also mention additional details that relate to Clangd.
>>
>> Currently, for our C-family support in Xcode (code-completion, clang AST queries) we use libclang, but for the new LSP service we will switch to using Clangd. We will also open-source a C++ library for global index queries, which is built on top of LMDB (https://symas.com/lmdb <https://symas.com/lmdb>). The functionality of this library is described by Nathan in his Index-While-Building design document (https://docs.google.com/document/d/1cH2sTpgSnJZCkZtJl1aY-rzy4uGPcrI-6RrUpdATO2Q <https://docs.google.com/document/d/1cH2sTpgSnJZCkZtJl1aY-rzy4uGPcrI-6RrUpdATO2Q>), specifically in the 'Using the index store' section.
>>
>> Let me elaborate a bit more on how we use this library. From Clang (and Swift) we get raw index data files, either directly from building or from invoking clang for background indexing. These data record files are designed to be efficient to write and update, ensuring that record files for headers are only written once, so that index-while-building has minimal overhead. But they are not designed to do efficient global queries (give me all symbol occurrences of this symbol USR). To accommodate this we use this database library which is a lightweight index layer on top of the raw index records. It reads the raw index data files and populates a key-value database that enables efficient global queries (it essentially determines what raw index record files contain the relevant information and retrieves the data).
>>
>> In our design for having full cross-language support for Swift and Clang languages (e.g. call-hierarchy across languages), we prefer to have a language-independent indexing component that is layered on top of the compiler-specific support (Clang/Clangd and Swift/sourcekitd). That means that our LSP service will contain an indexing and global refactoring engine and it will delegate to Clangd for clang-specific document queries, like code-completion.
>>
>> I understand that Clangd is intended to be a self-contained language service, that includes functionality for global index queries along with document-specific queries, but we believe we could still collaborate on common infrastructure shared by both Clangd and our new cross-language LSP service. See AlexL's previous post about how we intend to use Clangd, https://lists.llvm.org/pipermail/cfe-dev/2018-April/057668.html <https://lists.llvm.org/pipermail/cfe-dev/2018-April/057668.html> and what kind of improvements we want to make.
>>
>> Once we have the repositories up, you'll be able to check out our overall design in more detail, and in the meantime I'd be happy to hear any feedback or questions you may have!
>> _______________________________________________
>> clangd-dev mailing list
>> clangd-dev at lists.llvm.org <mailto:clangd-dev at lists.llvm.org>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20181023/0b5bd447/attachment-0001.html>
More information about the clangd-dev
mailing list