This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add 'Switch header/source' command in clangd-vscode
ClosedPublic

Authored by malaperle on Nov 20 2018, 8:25 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

malaperle created this revision.Nov 20 2018, 8:25 PM
malaperle updated this revision to Diff 174866.Nov 20 2018, 8:28 PM

Fix a bad change

ioeric accepted this revision.Nov 22 2018, 1:41 AM

lgtm

Could you run clang-format on the changed lines?

clangd/clients/clangd-vscode/package.json
81 ↗(On Diff #174866)

and objc?

clangd/clients/clangd-vscode/src/extension.ts
55 ↗(On Diff #174866)

We might want to share the logic for converting protocol URI to vscode URI.

This revision is now accepted and ready to land.Nov 22 2018, 1:41 AM

Overall LG, merely stylistic NITs.

clangd/clients/clangd-vscode/src/extension.ts
69 ↗(On Diff #174866)

Maybe use async/await to improve readabiity? I.e.

/*...*/push(registerCommand('...', async() => {
        // ...
        const sourceUri = await clangdClient.sendRequest(SwitchSourceHeaderRequest.type, docIdentifier);
        if (!sourceUri) {
           return;
        }
        const doc = await // ....
}
70 ↗(On Diff #174866)

Maybe do if (!sourceUri) to use consistent style with the first check in the lambda (i.e. if (!uri))

And many thanks for the change! I've tried it out, will definitely be one of the most-used clangd features for me :-)

hokein added inline comments.Nov 22 2018, 2:15 AM
clangd/clients/clangd-vscode/src/extension.ts
4 ↗(On Diff #174866)

We have imported the whole module as vscodelc, maybe just use vscodelc.RequestType, vscodelc.TextDocumentIdentifier?

16 ↗(On Diff #174866)

Do we want to export this SwitchSourceHeaderRequest? it seems that we only use it in this module.

17 ↗(On Diff #174866)

Is textDocument/switchSourceHeader a built-in support in vscode? Is it documented somewhere? I couldn't find any official document at https://code.visualstudio.com. Am I missing anything here?

hokein added inline comments.Nov 22 2018, 3:27 AM
clangd/clients/clangd-vscode/src/extension.ts
17 ↗(On Diff #174866)

nvm, just realize that this is an LSP extension implemented inside clangd.

malaperle updated this revision to Diff 175078.Nov 22 2018, 7:31 PM
malaperle marked 5 inline comments as done.

Address comments.

Could you run clang-format on the changed lines?

I didn't know clang-format could be used for Typescript. I ran it and it's a bit inconsistent with the rest of the file but I don't want to format the whole file.

clangd/clients/clangd-vscode/package.json
81 ↗(On Diff #174866)

I just removed the languages. It's a bit much to have all of them.

clangd/clients/clangd-vscode/src/extension.ts
55 ↗(On Diff #174866)

What do you have in mind? I'm not sure there is much to share since I'm not sure we should be using readpathSync for the toggle header/source. If the source is opened as a symlink and the header also exists as a symlink then I think it's OK to open the symlink.

This is great!

I'm slightly nervous - the way we've extended the protocol with textDocument/switchSourceHeader is pretty hard to extend, itself (since the response is a string directly).
This is only tangentially related to this patch, the same issue exists with Theia (I thought it was version locked to clangd, but it seems not to be).

I think this is fine. We may want to revise the protocol to wrap the URI in a struct (which should be soon!). Since VSCode plugin can be assumed to be newer than clangd, we can make it accept both versions.

This is great!

I'm slightly nervous - the way we've extended the protocol with textDocument/switchSourceHeader is pretty hard to extend, itself (since the response is a string directly).
This is only tangentially related to this patch, the same issue exists with Theia (I thought it was version locked to clangd, but it seems not to be).

I think this is fine. We may want to revise the protocol to wrap the URI in a struct (which should be soon!). Since VSCode plugin can be assumed to be newer than clangd, we can make it accept both versions.

I think it does make the to revise it. I don't think anything outside Theia and this vscode extension uses it. This might be a good opportunity to make it a proper protocol extension as explained here: https://github.com/Microsoft/language-server-protocol/blob/master/contributing.md#how-to-create-a-protocol-extension

This revision was automatically updated to reflect the committed changes.

@malaperle, do you want a new release of vscode-clangd extension for this?

@malaperle, do you want a new release of vscode-clangd extension for this?

I don't plan on doing changes for a little while in vscode-clangd so it would be good indeed to have a new release. Unless you know of some upcoming change that could also piggy back a new release? Thanks!

+1 to the new release D52311 (documentSymbol) needs a bump of the dependencies' versions.

Just made a new release v0.0.7, please try to use it (it works on my machine).

Just made a new release v0.0.7, please try to use it (it works on my machine).

Many thanks! Works for me

Just made a new release v0.0.7, please try to use it (it works on my machine).

Works great! Thanks a lot!