This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Omit parameter hint for setter functions
ClosedPublic

Authored by nridge on Apr 18 2021, 12:26 PM.

Diff Detail

Event Timeline

nridge created this revision.Apr 18 2021, 12:26 PM
nridge requested review of this revision.Apr 18 2021, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2021, 12:26 PM
nridge added a comment.EditedApr 18 2021, 12:27 PM

I chose to be conservative here and only omit the hint in the case where the setter's name (after the "set") matches the parameter name (ignoring case).

I gave void setTimeout(int timeoutMillis); as a motivating example for where a non-matching parameter name could contain extra information that could be useful to show in a hint. Let me know if you agree with this reasoning.

I'm not sure how related this is, but Hover has methods that try to detect setter functions in class to give them a trivial description, would that be of any help here?

clang-tools-extra/clangd/InlayHints.cpp
119

This heuristic is far from perfect. There's definitely diminishing returns for the more advanced you make it, but I'd argue it makes sense to strip any underscore from the Name, e.g,
void set_timeout(int timeout)

nridge updated this revision to Diff 338397.Apr 18 2021, 3:15 PM

Handle snake_case setter functions

nridge marked an inline comment as done.Apr 18 2021, 3:16 PM
nridge added inline comments.
clang-tools-extra/clangd/InlayHints.cpp
119

Good call, snake_case is definitely worth supporting

nridge marked an inline comment as done.Apr 18 2021, 3:19 PM

I'm not sure how related this is, but Hover has methods that try to detect setter functions in class to give them a trivial description, would that be of any help here?

It looks like that code introspects the body of the function to see if it's a setter based on what it does, regardless of its name. Not sure if that's a good match for cases where it makes sense to omit a parameter hint.

sammccall accepted this revision.Apr 23 2021, 1:41 PM
sammccall added inline comments.
clang-tools-extra/clangd/InlayHints.cpp
113

This is nice and conservative, but a bit style dependent.
e.g. setSema(Sema &S)

Seems fine for now, maybe we want to tweak at some point.

119

This doesn't handle multi-word variable names if params use snake case and functions don't, e.g.:

e.g. void setExceptionHandler(EHFunc exception_handler)

This is fine for now but probably worth a comment.
Ultimately replacing equals_lower with some sloppy_equals that ignores case and skips underscores would solve this neatly.

clang-tools-extra/clangd/unittests/InlayHintTests.cpp
344

can you add setTimeoutMillis(int timeout_millis) just to show the current behavior?

This revision is now accepted and ready to land.Apr 23 2021, 1:41 PM
nridge updated this revision to Diff 340392.Apr 25 2021, 4:05 PM
nridge marked 2 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Apr 25 2021, 4:20 PM
This revision was automatically updated to reflect the committed changes.