[PATCH] D151166: [clangd] Interactive AST matchers with #pragma clang query

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 15:29:44 PDT 2023


sammccall created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The idea: you can type in AST matchers, and clangd shows you matches
within the document.

Syntax is like:

  #pragma clang query varDecl().bind("var")

Features:

- matches are shown within the document as diagnostics
- find-references on the pragma will produce a list of matches
- errors within matchers are shown as diagnostics
- code completion is available within matchers

There are some rough edges here, e.g. the diagnostics are warnings and
have no LSP diagnostic code, the diagnostic text for matcher errors
isn't ideal etc.
I think this is a good start as-is and we can work out if we want to
improve these cases later, if this feature ends up being useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151166

Files:
  clang-tools-extra/clangd/ASTMatchers.cpp
  clang-tools-extra/clangd/ASTMatchers.h
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151166.524514.patch
Type: text/x-patch
Size: 27571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230522/35501abb/attachment-0001.bin>


More information about the cfe-commits mailing list