This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Use the active file's language for hover code blocks
ClosedPublic

Authored by dgoldman on Aug 23 2021, 1:47 PM.

Details

Summary

This helps improve the syntax highlighting for Objective-C code,
although it currently doesn't work well in VS Code with
methods/properties/ivars since we don't currently include the proper
decl context (e.g. class).

Diff Detail

Event Timeline

dgoldman created this revision.Aug 23 2021, 1:47 PM
dgoldman requested review of this revision.Aug 23 2021, 1:47 PM

LMK if you can think of a better approach to decide which language to use here. Likely will send a follow up diff to include more context in the Objective-C decl printing so they highlight properly.

thanks, mostly looks good. any reason for not doing it centrally though ?

clang-tools-extra/clangd/Hover.cpp
1019

can we set it once around here instead?

Likely will send a follow up diff to include more context in the Objective-C decl printing so they highlight properly.

This might make sense if it provides useful context to human readers without too much syntactic weight.
However if the issue is that particular editors are mis-highlighting snippets of ObjC, that's probably rather bugs to file against those editors (or maybe reasons to drop the language and fall back to regular highlighting)

Likely will send a follow up diff to include more context in the Objective-C decl printing so they highlight properly.

This might make sense if it provides useful context to human readers without too much syntactic weight.
However if the issue is that particular editors are mis-highlighting snippets of ObjC, that's probably rather bugs to file against those editors (or maybe reasons to drop the language and fall back to regular highlighting)

Right, we're just missing the decl context (since objc decls must be in a top level container)

e.g. currently we have:

// In AppDelegate()
@property(nonatomic, assign, unsafe_unretained, readwrite) NSInteger version;

instead we could show

@interface AppDelegate()
@property(nonatomic, assign, unsafe_unretained, readwrite) NSInteger version;
@end
dgoldman updated this revision to Diff 368395.Aug 24 2021, 10:44 AM

Simplify setting the definition language

dgoldman marked an inline comment as done.Aug 24 2021, 10:44 AM
kadircet accepted this revision.Sep 2 2021, 3:31 AM

thanks, lgtm!

clang-tools-extra/clangd/unittests/HoverTests.cpp
968

nit: we can drop that since we're only checking for definition language field.

This revision is now accepted and ready to land.Sep 2 2021, 3:31 AM
dgoldman updated this revision to Diff 370590.Sep 3 2021, 8:35 AM

Remove unnecessary build flag

dgoldman marked an inline comment as done.Sep 3 2021, 8:35 AM
This revision was landed with ongoing or failed builds.Sep 3 2021, 8:38 AM
This revision was automatically updated to reflect the committed changes.