global code completion and architecture of clangd
play

Global code completion and architecture of clangd Ilya Biryukov - PowerPoint PPT Presentation

Global code completion and architecture of clangd Ilya Biryukov Google EuroLLVM April 16, 2018 Overview 1. Language Server Protocol 2. Architecture of clangd 3. Code completion 4. Current state and future work Language Server Protocol


  1. Global code completion and architecture of clangd Ilya Biryukov Google EuroLLVM April 16, 2018

  2. Overview 1. Language Server Protocol 2. Architecture of clangd 3. Code completion 4. Current state and future work

  3. Language Server Protocol

  4. Editor integration problem C++ Java C# Vim C++ Vim plugin Java Vim plugin C# Vim plugin Emacs C++ Emacs plugin Java Emacs plugin C# Emacs plugin Atom C++ Atom plugin Java Atom plugin C# Atom plugin Sublime Text C++ Sublime plugin Java Sublime plugin C# Sublime plugin

  5. Editor integration problem clang_complete vim vim-clang … libclang irony-mode Emacs rtags …

  6. Language Server Protocol (LSP) Language Servers clangd(C++) Editors (native or via cquery (C++) plugins) Eclipse jdt.ls (Java) vim VSCode LSP TypeScript Emacs Atom rlc (Rust) Sublime … …

  7. YouCompleteMe Completers Editors (via ycm plugins) C++ completer vim VSCode YCM C# completer HTTP Server Emacs Atom Java completer Sublime … …

  8. clangd

  9. clangd Language Server based on clang. ● Developed as part of LLVM in clang-tools-extra ● Supported features ○ Diagnostics ○ Code completion ○ Go to definition ○ Documentation ○ Local rename ○ Formatting ○ …

  10. Architecture of clangd clangd LSP features completion goto definition signature help … Index AST Cache clang Frontend

  11. Index ● Provides project-wide information ● AST Decl → Index Symbol Name: StringRef ● Example: Scope: llvm Kind: class namespace llvm { ID: llvm::StringRef class StringRef { /* ... */ }; … } int dropFirst(llvm::StringRef S, size_t N); Name: dropFirst Scope: <global-namespace> Kind: function ID: dropFirst(llvm::StringRef, size_t) …

  12. Models of your program AST Index Dynamic Static ● Single file ● Up-to-date ● Active files ● All files ● ~1 minute old ● ~1 day old ● external?

  13. Code completion

  14. Clang completion of class members.

  15. Clang completion inside namespaces.

  16. Clang completion inside namespaces.

  17. Idea of global completion

  18. Idea of global completion

  19. Idea of global completion

  20. Global completion ● Completion returns results std::vector< bool > from all headers vec_bool.flip(); // ok ○ adds #include if needed ● General case is hard std::vector< int > vec_int; vec_int.flip(); // error

  21. Completion items: AST or Index? namespace llvm { int getAsUnsignedInteger( const char *); llvm::Optional llvm::DenseSet class StringRef { llvm::ArrayRef const char *Ptr; … public: StringRef substr( size_t N) { const char *NewPtr = Ptr + N; | }

  22. Code completion flow scopes index clang PCH results Frontend AST completions

  23. Scopes #include "my_class.h" using namespace std; void my_class::do_work() { vec| } Index.fuzzyFind( /*Scopes*/ {"::", "std::"}, /*Query*/ "vec");

  24. Ranking ● Query match score ● Symbol signals ○ Uses ○ Type information ○ Proximity

  25. Ranking example Query: “uniq” Uses Uses Symbol Match Total uniq ue 0.9 0.3 45 0.27 uniq ue_ptr 1.0 0.9 1504 0.9 × = make_ uniq ue 0.6 0.5 403 0.30 Make Uniq ue 0.7 0.5 607 0.35

  26. Ranking example Query: “uniq” Symbol Total uniq ue_ptr 0.9 Make Uniq ue 0.35 make_ uniq ue 0.30 uniq ue 0.27

  27. Current state and future work

  28. Current state ● Basic LSP support ○ completion, diagnostics, fix-its, signature help, local rename, go to definition, formatting ● Global completion (experimental) ● Project-wide index (experimental)

  29. Embedding in a Web IDE ● Used by internal Web IDE at Google ● Runs in Cloud ● Implementation challenges: ○ Virtual File System ○ Buildsystem integration ○ Tracing requests

  30. cquery ● Language Server based on libclang ● More features than clangd ● Highly optimized in-memory index ● Designed to run locally

  31. Future plans ● More LSP features ● clang-tidy ● index-while-build ● Better build system integration

  32. Thanks to all contributors! ● Ben Jackson ● Benjamin Kramer ● Eric Liu ● Haojian Wu ● Krasimir Georgiev ● Marc-André Laperle ● Raoul Wols ● Sam McCall ● Simon Marchi ● Stanislav Ionascu ● William Enright ● …

  33. ● Feedback welcome! ○ https://clang.llvm.org/extra/clangd.html ● Contributions welcome! ○ https://reviews.llvm.org/source/CTE/browse/clang-tools-extra/trunk/clangd/ ○ https://clang.llvm.org/extra/clangd.html#getting-involved ● Reach us at “cfe-dev”

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend