This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Move DraftStore from ClangdLSPServer into ClangdServer.
ClosedPublic

Authored by sammccall on Mar 1 2021, 3:19 PM.

Details

Summary

ClangdServer already gets notified of every change, so it makes sense for it to
be the source of truth.
This is a step towards having ClangdServer expose a FS that includes dirty
buffers: D94554

Related changes:

  • version is now optional for ClangdServer, to preserve our existing fuzziness in this area (missing version ==> autoincrement)
  • ClangdServer::format{File,Range} are now more regular ClangdServer functions that don't need the code passed in. While here, combine into one function.
  • incremental content update logic is moved from DraftStore to ClangdLSPServer, with most of the implementation in SourceCode.cpp. DraftStore is now fairly trivial, and will probably ultimately be *replaced* by the dirty FS stuff.

Diff Detail

Event Timeline

sammccall created this revision.Mar 1 2021, 3:19 PM
sammccall requested review of this revision.Mar 1 2021, 3:19 PM

as discussed offline, i am hesitant about validateEdits layering at the moment. but i suppose the best thing to do is move it into clangdserver and expose a structrual api, as you proposed, which can be done independently.

clang-tools-extra/clangd/ClangdServer.h
266

nit: Optional<Range> instead of a pointer?

clang-tools-extra/clangd/DraftStore.cpp
50

nit: s/return/break/ same below

57

nit: i'd drop the assert

65–67

why not a not_equals instead? we are going to override the version anyway

clang-tools-extra/clangd/SourceCode.h
208

i was going to complain about sourcecode depending on protocol, but apparently it already does...

sammccall updated this revision to Diff 327481.Mar 2 2021, 9:08 AM
sammccall marked 3 inline comments as done.

address comments
remove one more redundant getDraft() check

as discussed offline, i am hesitant about validateEdits layering at the moment. but i suppose the best thing to do is move it into clangdserver and expose a structrual api, as you proposed, which can be done independently.

Yup. It's not great, but it doesn't seem terrible or dangerous or anything. (We're not opening any new interfaces to support this, getDraft() is called in lots of places)
In the same bucket I think is sorting out TextEdits vs Replacements in a few interfaces etc.

clang-tools-extra/clangd/ClangdServer.h
266

Haha, I had this, then thought "but we pass things in by reference anyway".
Except... we don't, in ClangdServer. And I'm not sure why.

Anyway, done.

clang-tools-extra/clangd/DraftStore.cpp
65–67

I don't really understand the suggestion.

The purpose here is to notice and log when client-specified versions go backwards.
This is a protocol violation, which won't cause problems for clangd but may indicate something broken going on.

We don't want to log when versions go forwards!

kadircet accepted this revision.Mar 2 2021, 10:59 AM

thanks, lgtm!

clang-tools-extra/clangd/DraftStore.cpp
65–67

ah nvm, i was reading this wrong. i thought it was logging when versions go "forward"

This revision is now accepted and ready to land.Mar 2 2021, 10:59 AM
This revision was landed with ongoing or failed builds.Mar 2 2021, 1:59 PM
This revision was automatically updated to reflect the committed changes.