This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Bind outgoing calls through LSPBinder too. NFC
ClosedPublic

Authored by sammccall on Feb 15 2021, 8:36 AM.

Details

Summary

The redundancy around work-done-progress is annoying but ok for now.

There's a weirdness with context lifetimes around outgoing method calls, which
I've preserved to keep this NFC. We should probably fix it though.

Diff Detail

Event Timeline

sammccall created this revision.Feb 15 2021, 8:36 AM
sammccall requested review of this revision.Feb 15 2021, 8:36 AM

Remove fixedme

mostly LG. some comments around the way we set up outgoinmethod stubs though.

clang-tools-extra/clangd/LSPBinder.h
88

well this one filling an out-parameter definitely tripped me over while reading the code a couple times, and once more on the tests.

what about making this return the handler instead? E.g. Edit = Bind.outgoingMethod<EditParams, EditResult>("edit"), I know it is ugly that we duplicate template params on declaration + here now. Maybe we can get away by making OutgoingMethod a class with a call operator and a RawOutgoing *Out member that can be bound later on ? e.g:

template <StringLiteral Method, typename P, typename R>
class OutgoingMethod {
  RawOutgoing *Out = nullptr;
public:
  void operator()(const P& Params, Callback<R> CB) {
    assert(Out && "Method haven't bound");
    Out->callMethod(Method, JSON(Params), ....);
  }
};

then we either make LSPBinder a friend of OutgoingMethod and set Out through it, or the other way around and have a OutgoingMethod::bindOut(LSPBinder&) ?

not sure if it is any better though, as we still construct a somewhat invalid object :/

90

nit: maybe move bodies for these functions out-of-line too?

93

haha feels like confusing Context and WithContext issue i talked about yesterday :D

sammccall marked 2 inline comments as done.Feb 16 2021, 7:58 AM
sammccall added inline comments.
clang-tools-extra/clangd/LSPBinder.h
88

well this one filling an out-parameter definitely tripped me over while reading the code a couple times, and once more on the tests.

Yup. My feeling is the wins are:

  • avoid writing the types over and over (we can't really avoid it on the instance variable)
  • resembles syntax for binding incoming things

And the main loss is definitely that we're not using assignment syntax for assignment.

what about making this return the handler instead? E.g. Edit = Bind.outgoingMethod<EditParams, EditResult>("edit")

This is a reasonable alternative, as you say the duplication is the downside.

Maybe we can get away by making OutgoingMethod a class with a call operator

Yeah, I don't really understand what this achieves - the usage looks the same, just now the logical assignment doesn't use assignment syntax *or* assignment semantics :-)

Other ideas I had:

  • the object is untyped, and the call operator is templated/typed - no type-safety at callsite, yuck
  • outgoingMethod returns an untyped proxy object with a template conversion operator to unique_function<Req, Rsp>. This gives us assignment syntax... and horrible compiler errors on mismatch.

I'm going to try the latter out to see how bad it is.

93

Exactly. I'm fairly sure we need a WithContext here but don't want to risk changing it at the same time.

clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
236

whoops, after rebasing against 40cc63ea6eec7874d3a358f9fa549ef2f6543512 this uncovered a bug - we're testing the public API from the wrong thread (server thread != main thread).

So I've had to remove that test in this patch. We can test public APIs again in D96755.

sammccall updated this revision to Diff 324012.Feb 16 2021, 7:58 AM
sammccall marked an inline comment as done.

rebase & address comments (except bind out API, still to come)

sammccall updated this revision to Diff 324025.Feb 16 2021, 8:58 AM

OK, the awful proxy object thing works :-)
It requires a SFINAE fix to unique_function though, which i'll send separately.

kadircet accepted this revision.Feb 16 2021, 9:21 AM

thanks! can't wait for the unique_function sfinae fix :)

clang-tools-extra/clangd/LSPBinder.h
88

thanks! this looks a whole lot better!

185

maybe put inline at the start of the declaration ? :D

clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
236

yikes, i see what you mean now.. (i was searching for the failure in the previous commit you mentioned)

This revision is now accepted and ready to land.Feb 16 2021, 9:21 AM
sammccall marked 2 inline comments as done.Feb 16 2021, 1:51 PM
sammccall added inline comments.
clang-tools-extra/clangd/LSPBinder.h
88

Glad you like it... personally I felt a little ill after writing it :-)

kadircet accepted this revision.Feb 17 2021, 12:21 AM

still LG!

This revision was automatically updated to reflect the committed changes.