[all-commits] [llvm/llvm-project] 9ef2ac: [clangd] Handle lambda scopes inside Node::getDecl...

Younan Zhang via All-commits all-commits at lists.llvm.org
Thu Jan 11 00:59:30 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9ef2ac3ad1bd5aa9e589f63047e8abeac11ad1b2
      https://github.com/llvm/llvm-project/commit/9ef2ac3ad1bd5aa9e589f63047e8abeac11ad1b2
  Author: Younan Zhang <zyn7109 at gmail.com>
  Date:   2024-01-11 (Thu, 11 Jan 2024)

  Changed paths:
    M clang-tools-extra/clangd/Selection.cpp
    M clang-tools-extra/clangd/unittests/SelectionTests.cpp
    M clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp

  Log Message:
  -----------
  [clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)

We used to consider the `DeclContext` for selection nodes inside a
lambda as the enclosing scope of the lambda expression, rather than the
lambda itself.

For example,

```cpp
void foo();
auto lambda = [] {
  return ^foo();
};
```

where `N` is the selection node for the expression `foo()`,
`N.getDeclContext()` returns the `TranslationUnitDecl` previously, which
IMO is wrong, since the method `operator()` of the lambda is closer.

Incidentally, this fixes a glitch in add-using-declaration tweaks.
(Thanks @HighCommander4 for the test case.)




More information about the All-commits mailing list