This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Support define outline tweak for non cross file edits
Needs ReviewPublic

Authored by njames93 on Apr 15 2023, 3:03 AM.

Details

Summary

Currently this is limited to just defining method decls out of class in source files.

// Test.cpp
struct A {
  void Foo() {}
};
// Converted to
struct A {
  void Foo();
};
A::Foo() {}

Diff Detail

Event Timeline

njames93 created this revision.Apr 15 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 3:03 AM
Herald added a subscriber: arphaman. · View Herald Transcript
njames93 requested review of this revision.Apr 15 2023, 3:03 AM

Theres definitely scope to improve this in follow ups.
We could support this for template methods and classes

template <typename T> struct A {
  void [[Foo]]() {}
  template<typename U> void [[Bar]]() {}
};

// Both ranges transformed to
template <typename T> struct A {
  void Foo();
  template<typename U> void Bar();
};

template <typename T>
void A<T>::Foo() {}

template <typename T>
template <typename U>
void A<T>::Bar<U>() {}

In D147808 The restriction only only applying the tweak for non trivial member functions could be removed when making a non cross file edit.

We could also employ a better insertion point logic for these tweaks as we have the full AST for the file where the function is to be inserted.

njames93 updated this revision to Diff 513911.Apr 15 2023, 8:07 AM
  • Clang format changes
  • Update apply logic to not query the FS when its not a cross file edit