This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Provide suggestions with invalid config keys
ClosedPublic

Authored by njames93 on Dec 9 2020, 6:33 PM.

Details

Summary

Update the config file warning when an unknown key is detected which is likely a typo by suggesting the likely key.
This won't suggest a key that has already been seen in the block.

Appends the fix to the diag, however right now there is no support for presenting that fix to the user.

Diff Detail

Event Timeline

njames93 created this revision.Dec 9 2020, 6:33 PM
njames93 requested review of this revision.Dec 9 2020, 6:33 PM
njames93 updated this revision to Diff 310814.Dec 10 2020, 3:02 AM

Fix lit test failure

Adding in support for fix-its(at least in vscode) didn't seem to work. The language server there doesn't seem to send the textDocument/codeAction message to the server for the .clangd file.

This is cool! Detecting basic typos could save a fair bit of time.
I do want to be a bit wary of spending too much complexity on small enhancements to rarely used code - if it's more than a simple typo we're correcting, then I think it's ok to make the user look it up.

Adding in support for fix-its(at least in vscode) didn't seem to work. The language server there doesn't seem to send the textDocument/codeAction message to the server for the .clangd file.

Right, we can publish to any file, but we only expect to get requests for files we're active on, and users will expect us to track draft changes etc. I don't think we want to go down the path of being a full language server for config files, so I wouldn't pursue fixit support.

clang-tools-extra/clangd/ConfigYAML.cpp
225

i'm not sure it's actually worth the complexity to delay this, track the seen keys, and exclude them from the analysis.
Offering a suggestion already seems pretty good, but I don't think we should try too hard to make it perfect.

234

nit: drop explicit '4' size here
also drop get prefix here and for best-guess (matching the local style for functions used for value rather than for side-effect)

244

nit: drop unused default param

246

Comment here just echoes the code - remove?

254

This branch is confusing.
It seems to be saying if we have a tie for best, don't return either result. Why is that important/worth any complexity?

njames93 updated this revision to Diff 311067.Dec 10 2020, 4:42 PM
njames93 marked 3 inline comments as done.

Address some comments

This is cool! Detecting basic typos could save a fair bit of time.
I do want to be a bit wary of spending too much complexity on small enhancements to rarely used code - if it's more than a simple typo we're correcting, then I think it's ok to make the user look it up.

I always like to think users don't spend much time reading the instructions, so little pointers like this do add value and result in a more polished experience.

Adding in support for fix-its(at least in vscode) didn't seem to work. The language server there doesn't seem to send the textDocument/codeAction message to the server for the .clangd file.

Right, we can publish to any file, but we only expect to get requests for files we're active on, and users will expect us to track draft changes etc. I don't think we want to go down the path of being a full language server for config files, so I wouldn't pursue fixit support.

Ahh I don't know the full ins and outs of LSP. As nice as a fix-it would be, It appears that's a little too much work so should best be avoided.

clang-tools-extra/clangd/ConfigYAML.cpp
225

Perfection isn't needed, but suggesting a fix that will result in another error is arguably counter-productive.

234

Forgot about the new default SmallVector storage feature.

254

If we have 2 (or more) possible solutions, we can't say for certainty what the user wanted, in which case its best to not suggest anything, in case its incorrect and instead force the user to take an informed look. It doesn't really add much complexity to do this check, And most of this code is copied from somewhere else in llvm as its a pretty common routine. Maybe they could be coalesced into 1 class to reduce duplication,

Sorry about being slow here.
Just a couple of suggestions to avoid cluttering the config parsing bits too much, and IIUC fixits can be removed.

clang-tools-extra/clangd/ConfigYAML.cpp
234

I think inlining unseenKeys into warnUnknownKeys would be more readable by isolating the mechanics of typo correction into fewer places.

242

I think we can pull this function out of this class, since it doesn't have much to do with config parsing. (Probably just anonymous above - it's not so reusable since candidates aren't always just strings)

254

Well, there isn't *any* case where we can say for certain that we know what the user wanted.

If this were a common library then that shifts the complexity/accuracy tradeoff and justifies a bit of extra work. As it is, the fact that it's copy/pasted doesn't help much with maintaining/reading it. We can keep this, though I don't feel great about it.

(FWIW, these same copy/pasted numbers thresholds are used for clang's typo correction, and we're pretty sure they're not very good - @hokein has tuning them on his backlog)

287

please remove the SMFixIt bits, since we don't have any way to use them

njames93 updated this revision to Diff 311934.Dec 15 2020, 9:20 AM
njames93 marked 3 inline comments as done.

Address comments.

njames93 marked 2 inline comments as done.Dec 15 2020, 9:21 AM
sammccall accepted this revision.Dec 15 2020, 9:35 AM

LG, thanks!

clang-tools-extra/clangd/ConfigYAML.cpp
27

(nit: no need for static in anon namespace)

292

optional nit: these node variants are now just convenience wrappers, I'd drop the comment from them and group them accordingly with whitespace, up to you.

This revision is now accepted and ready to land.Dec 15 2020, 9:35 AM
njames93 updated this revision to Diff 311949.Dec 15 2020, 9:45 AM
njames93 marked 2 inline comments as done.

Last nits.

This revision was landed with ongoing or failed builds.Dec 15 2020, 10:16 AM
This revision was automatically updated to reflect the committed changes.