This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Enable completions with fixes in VSCode
Changes PlannedPublic

Authored by ilya-biryukov on Sep 5 2019, 6:58 AM.

Details

Reviewers
None
Summary

When we run completion in VSCode, the following things happen:

  • Get get a completion request for a.f^
  • clangd returns a completion item with the range a[[.f]], insert text ->foo and filter text foo
  • VSCode extracts the word against which we should filter from a range and gets .f
  • VSCode tries to match our filter text foo against the word .f and findsno match

As a result, the item we returned gets filtered out and not shown in the UI.

This revision changes the filter text to be .foo and VSCode stops filtering it out.

Event Timeline

ilya-biryukov created this revision.Sep 5 2019, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 6:58 AM
ilya-biryukov planned changes to this revision.Sep 5 2019, 8:04 AM
ilya-biryukov edited the summary of this revision. (Show Details)
ilya-biryukov edited the summary of this revision. (Show Details)

Changing behavior of clangd might affect other clients.
It would be nice to find alternative ways to fix this.

Nevertheless, posting this here as an example of a potential workaround for the problem.

ilya-biryukov edited the summary of this revision. (Show Details)Jan 2 2020, 6:14 AM
ilya-biryukov edited the summary of this revision. (Show Details)Jan 2 2020, 6:15 AM
nridge added a subscriber: nridge.Jan 4 2020, 7:13 PM

Just throwing a wild idea out there: what if we used textDocument/onTypeFormatting to replace the . with -> as soon as it's typed?

Just throwing a wild idea out there: what if we used textDocument/onTypeFormatting to replace the . with -> as soon as it's typed?

There is no way we can do this with proper latency. onTypeFormatting can't wait for the parsing to complete and we need the parsing to complete in order to determine the type of expression to the left of . or ->.
Moreover, in cases like unique_ptr<T>(). we can't know whether the user wants . or -> before we pick the completion item. Both . and -> are allowed in this context.