This is an archive of the discontinued LLVM Phabricator instance.

[clangd] extend the publishDiagnostics response to send back fixits to the client directly as well (if requested)
ClosedPublic

Authored by arphaman on Aug 7 2018, 3:53 PM.

Details

Summary

This change extends the 'textDocument/publishDiagnostics' notification sent from Clangd to the client. The extension can be enabled using the '-fixit-usage=embed-in-diagnostic' argument. When it's enabled, Clangd sends out the fixits associated with the appropriate diagnostic in the body of the 'publicDiagnostics' notification.

Diff Detail

Event Timeline

arphaman created this revision.Aug 7 2018, 3:53 PM

Couple of thoughts. (Technically I'm out on leave so will let Jan/Ilya
review implementation and happy with whatever you decide)

Enabling

  • negotiating LSP extensions is probably better done in the "capabilities"

message exchange than as a command-line flag. Generally, we want this
extension on if the *client* is aware of it. Roughly, the client
capabilities are owned by the client, and the flags are owned by the *user*.

  • for simplicity, we could always enable this, unless we really think the

message size is a problem, or are worried about conflicts with future LSP
versions

Naming

  • elsewhere in clangd we settled on calling a "Fix" what clang calls a

"FixItHint". The latter is long/awkward/jargon, and often gets shortened to
"FixIt" which isn't obviously a noun. The former mostly has its plain
English meaning. I'd prefer "fix" in the protocol/flags, for the same
reasons.

  • obviously feel free to give these any name you prefer in your UI!

+1 Sam's suggestion of configuring this during initial LSP handshake, rather than as a command-line flag.
We could put it into ClientCapabilities or into initializationOptions. The latter has type 'any' in LSP, so it seems to be most in-line with the protocol to put clangd-specific config options there, but not opposed to having this in other structs as an extension either.

arphaman updated this revision to Diff 159760.Aug 8 2018, 11:39 AM
  • Client now can request the fixes using a 'clientCapabilities/textDocument/publishDiagnostics' extension.
  • Use 'Fixes' instead of 'Fixits' in code.
ilya-biryukov added inline comments.Aug 9 2018, 1:29 AM
clangd/ClangdLSPServer.cpp
441

Maybe remove this parameter now that we configure these via LSP?
We don't set it to anything other than the default anyway.

arphaman updated this revision to Diff 160007.Aug 9 2018, 2:21 PM
arphaman marked an inline comment as done.

remove parameter.

ilya-biryukov accepted this revision.Aug 10 2018, 5:11 AM

LGTM with a small NIT.

clangd/ClangdLSPServer.cpp
507

NIT: maybe avoid . and use something like clangd_fixes? having dots in the object keys might be awkward if someone tries to use those from javascript. (not that we have these use-cases now, but still)

This revision is now accepted and ready to land.Aug 10 2018, 5:11 AM
This revision was automatically updated to reflect the committed changes.
arphaman marked an inline comment as done.