This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Improve printing of Objective-C categories and methods
ClosedPublic

Authored by dgoldman on Feb 12 2021, 8:59 AM.

Details

Summary
  • Categories will now show up as MyClass(Category) instead of Category and MyCategory() instead of (anonymous) in document symbols
  • Methods will now be shown as -selector: or +selector: instead of selector: to differentiate between instance and class methods in document symbols

Diff Detail

Event Timeline

dgoldman created this revision.Feb 12 2021, 8:59 AM
dgoldman requested review of this revision.Feb 12 2021, 8:59 AM

I'm not an objc guy, but can you add a test case demonstrating class(?) methods showing as +name:?

clang-tools-extra/clangd/AST.cpp
224–226

nit: Can make these const auto * as the type is spelt in the initialisation.

dgoldman updated this revision to Diff 323443.Feb 12 2021, 12:20 PM
  • Add class method test case + swap to auto
sammccall added inline comments.Feb 15 2021, 10:19 AM
clang-tools-extra/clangd/AST.cpp
224

I'm not sure this fits with the contract of printName, which really is to print the name of the symbol rather than describe it.

Examples:

  • the title of a hovercard for a method will be "instance-method -[foo]" instead of "instance-method foo", which is inconsistent with c/c++
  • the title of a hovercard for a category will be "extension PotentiallyLongClassName(CatName)" instead of extension ClassName
  • the documentSymbol response will include the extra details in the name field rather than the detail field

We don't actually populate detail in documentSymbol, so maybe we do need a separate function that gives that level of detail.
Though I wonder whether it should mosty just print the decl (e.g. class X{};, @implementation PotentiallyLongClassName(CatName) etc. WDYT?

See also https://github.com/clangd/clangd/issues/520 https://github.com/clangd/clangd/issues/601 though both appear to have stalled.

228

in the other patch this was with -[brackets]

dgoldman marked 2 inline comments as done.Feb 16 2021, 3:06 PM
dgoldman added inline comments.
clang-tools-extra/clangd/AST.cpp
224

Maybe instead this should be split somehow into a separate specialization for Document Symbols?

e.g.

Hovercards:
instance-method foo
extension (anonymous) (current) or class-extension BTNButtonModel or BTNButtonModel()

Document Symbols:
-method
ClassName(Ext)

Since I think for the case here we would prefer to keep them different. Maybe if the LSP spec differentiated between instance methods and class/static methods -method that wouldn't be necessary? I guess I could revert the Method change here and just keep a special case for categories/class extensions?

The detail work seems worth doing too, but I think we would similarly just put the type information in there (for methods), for categories/class extensions I feel like it would be odd since it would at the very least repeat the name

dgoldman marked 2 inline comments as done.Feb 16 2021, 3:10 PM
dgoldman added inline comments.
clang-tools-extra/clangd/AST.cpp
228

We don't want to put the full form (e.g. including the container name) here - that would repeat the class name in the document symbols when the methods are already nested under the class.

dgoldman updated this revision to Diff 326719.Feb 26 2021, 9:10 AM
dgoldman marked an inline comment as done.

Limit changes to document symbols

dgoldman edited the summary of this revision. (Show Details)Feb 26 2021, 9:11 AM
sammccall accepted this revision.Feb 27 2021, 1:35 PM

Great, thanks!

clang-tools-extra/clangd/FindSymbols.cpp
176 ↗(On Diff #326719)

can we motivate this with a comment?
// print X rather than Y

This revision is now accepted and ready to land.Feb 27 2021, 1:35 PM
dgoldman updated this revision to Diff 327146.Mar 1 2021, 9:29 AM

Add comment and rebase

dgoldman marked an inline comment as done.Mar 1 2021, 9:30 AM
This revision was landed with ongoing or failed builds.Mar 1 2021, 9:38 AM
This revision was automatically updated to reflect the committed changes.