This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Use new URI with scheme support in place of the existing LSP URI
ClosedPublic

Authored by ioeric on Jan 23 2018, 6:18 AM.

Diff Detail

Event Timeline

ioeric created this revision.Jan 23 2018, 6:18 AM
ioeric added inline comments.Jan 23 2018, 6:23 AM
clangd/ClangdLSPServer.cpp
377

not sure if this is the right thing to do. idea?

clangd/URI.h
32

same here. There are many default constructions of structures that contain URIs in ClangdLSPServer.cpp...

sammccall added inline comments.Jan 25 2018, 9:24 AM
clangd/ClangdLSPServer.cpp
283

hmm, I think you want to replyerror for unexpected cases.
maybe:

if (ResultUri) {
  if (auto U = URI::create(*Result))
     reply(C, U->toString());
  else
    replyError(C, ErrorCode::InternalError, llvm::toString(U.takeError()));
} else
  reply(C, "");
284

But basically I think this shows that the API is awkward. We should have a way to create a file URI from an absolute path that asserts rather than returning expected.
I'd suggest removing the default "file" scheme from create(), and adding createFile(abspath) that returns URI

clangd/Protocol.h
51

URIForFile? "withfile" doesn't really capture that they're related

51

Hmm actually, what about just struct URIForFile { std:string AbsPath; }
fromJSON and toJSON would do the marshalling to URI, but internally we just want the path, right?

This also gives us the usual easy null state.

clangd/URI.h
32

Does the struct-with-just-an-abspath idea address this?

43

oh, sorry I missed this in the first code review...
It's really confusing to have create(str, str, str) do simple initialization that can't really fail, and create(str,str) do complicated plugin logic that can fail in lots of ways.

Can you change the first to be a constructor and just assert on the needed invariants?
(Or failing that createFromComponents, but I can't imagine a use case where you have components but don't know they're correct)

ioeric updated this revision to Diff 131576.Jan 26 2018, 4:56 AM
ioeric marked 8 inline comments as done.
  • Address review comments

Thanks for the comments!

clangd/ClangdLSPServer.cpp
284

That makes a lot of sense. Thanks for the suggestion!

clangd/Protocol.h
51

Good idea!

clangd/URI.h
32

Yes!

ioeric updated this revision to Diff 131775.Jan 29 2018, 5:09 AM
  • Merge remote-tracking branch 'origin/master' into uri
sammccall accepted this revision.Jan 29 2018, 7:05 AM

Can you also remove the URI-encoding hack from the VSCode client?

clangd/Protocol.cpp
35

I think you can just check that the scheme is file and pull out the path?
we don't want to expose custom URI schemes in LSP, I think

This revision is now accepted and ready to land.Jan 29 2018, 7:05 AM
ioeric updated this revision to Diff 131802.Jan 29 2018, 7:34 AM
ioeric marked an inline comment as done.
  • addressed review comments; removed URI hack in vscode extenstion.
This revision was automatically updated to reflect the committed changes.