[PATCH] D122101: [clangd] Simplify `insertDecl` and support insertion after the last declaration in a file

Adrian Vogelsgesang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 20 07:44:07 PDT 2022


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

So far `insertDecl`, did not support insertion of new code after the
last top-level declaration in a file. This was, because a
`TranslationUnitDecl` does not have a valid `getEndLoc()`.

Also, the logic of `Anchor::Below` was somewhat surprising: I would have
expected `Below` to insert below the first match. Instead it insert
after the first contigous run of matches. I found this highly
unintuitive, and replaced it by an additional optional `First`/`Last`
flag which can be specified for an anchor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122101

Files:
  clang-tools-extra/clangd/refactor/InsertionPoint.cpp
  clang-tools-extra/clangd/refactor/InsertionPoint.h
  clang-tools-extra/clangd/unittests/InsertionPointTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122101.416783.patch
Type: text/x-patch
Size: 9709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220320/e33cca6c/attachment.bin>


More information about the cfe-commits mailing list