This is an archive of the discontinued LLVM Phabricator instance.

[clangd][vscode] Enable dot-to-arrow fixes in clangd completion.
ClosedPublic

Authored by hokein on Mar 6 2020, 6:16 AM.

Details

Summary

The previous issue is that the item was filtered out by vscode, because
the prefix (which contains ".") are not matched against the filterText.

This patch works around it by adjusting the item filterText, inspired by
https://reviews.llvm.org/D75623.

Diff Detail

Event Timeline

hokein created this revision.Mar 6 2020, 6:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2020, 6:16 AM
sammccall accepted this revision.Mar 6 2020, 7:25 AM

So the core of this is a better version of my patch, thanks!
It does work around the problem with dot-to-arrow, which is useful and we should definitely enable that.

However I actually think the dot-to-arrow problem is our bug at this point. LSP is vague but the discussion on language-server-protocol#898 very sensibly links filterText to textEdit.range. If we're sending filterText = "foo", textEdit.range = ".f" then I don't think that *is* a match.
We get into this mess because we merge two edits together, I think to avoid LSP's vague prohibition about edits related to the cursor. My vote would be:

  1. check this patch in, but without claiming it as the correct and carefully architected fix for dot-to-arrow
  2. try turning off range-merging, and test it in a couple of clients (including vscode *without* this patch)
  3. if it works, make that change in clangd
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
118–121

"This also prevents VSCode from filtering out any results due to differences in how fuzzy filtering is applied."

129

While the detailed examples/debugging instructions are nice for me, I don't think keeping them in the code here is worthwhile - I'd suggest just adding the one line to the comment above and removing this block.

For the dot-to-arrow example specifically it might be worth filing a clangd bug and linking to it in the comment above.

This revision is now accepted and ready to land.Mar 6 2020, 7:25 AM

How does this handle cases where an object overloads the -> operator or worse still overloads the operator and has conflicting names when accessed with . or ->.

hokein updated this revision to Diff 249046.Mar 9 2020, 2:23 AM

address comments.

hokein marked 2 inline comments as done.Mar 9 2020, 2:24 AM

So the core of this is a better version of my patch, thanks!
It does work around the problem with dot-to-arrow, which is useful and we should definitely enable that.

We get into this mess because we merge two edits together, I think to avoid LSP's vague prohibition about edits related to the cursor. My vote would be:

  1. check this patch in, but without claiming it as the correct and carefully architected fix for dot-to-arrow
  2. try turning off range-merging, and test it in a couple of clients (including vscode *without* this patch)
  3. if it works, make that change in clangd

I think if we do that, we are likely to go back to the issue that sending additionalEdit related to the cursor, and LSP clearly states it is not supported -- Additional text edits should be used to change text unrelated to the current cursor position, and it would not work in VSCode.

However I actually think the dot-to-arrow problem is our bug at this point. LSP is vague but the discussion on language-server-protocol#898 very sensibly links filterText to textEdit.range. If we're sending filterText = "foo", textEdit.range = ".f" then I don't think that *is* a match.

Regarding the mismatch between filterText and textEdit.range, there is another way to make them matched -- sending filterText=".foo" (rather than foo) from clangd, vscode should work without this patch, but it looks like a hack in clangd to me...

How does this handle cases where an object overloads the -> operator or worse still overloads the operator and has conflicting names when accessed with . or ->.

This patch shouldn't affect the existing behavior for the mentioned case, it is handled by Sema. VSCode will show both candidates (one of them will correct the . while the other will not).

This revision was automatically updated to reflect the committed changes.

So the core of this is a better version of my patch, thanks!
It does work around the problem with dot-to-arrow, which is useful and we should definitely enable that.

We get into this mess because we merge two edits together, I think to avoid LSP's vague prohibition about edits related to the cursor. My vote would be:

  1. check this patch in, but without claiming it as the correct and carefully architected fix for dot-to-arrow
  2. try turning off range-merging, and test it in a couple of clients (including vscode *without* this patch)
  3. if it works, make that change in clangd

I think if we do that, we are likely to go back to the issue that sending additionalEdit related to the cursor, and LSP clearly states it is not supported -- Additional text edits should be used to change text unrelated to the current cursor position, and it would not work in VSCode.

Sure, well if it doesn't work, then we should keep this hack instead.

However I actually think the dot-to-arrow problem is our bug at this point. LSP is vague but the discussion on language-server-protocol#898 very sensibly links filterText to textEdit.range. If we're sending filterText = "foo", textEdit.range = ".f" then I don't think that *is* a match.

Regarding the mismatch between filterText and textEdit.range, there is another way to make them matched -- sending filterText=".foo" (rather than foo) from clangd, vscode should work without this patch, but it looks like a hack in clangd to me...

Yes. And worse, it's a hack that's pretty hard to implement :-)