zed icon indicating copy to clipboard operation
zed copied to clipboard

Add Solidity language

Open tomholford opened this issue 1 year ago • 4 comments

Context

This adds support for Solidity to zed

Resolves #4872

Preview

image

tomholford avatar Jan 31 '24 15:01 tomholford

We require contributors to sign our Contributor License Agreement, and we don't have @tomholford on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

cla-bot[bot] avatar Jan 31 '24 15:01 cla-bot[bot]

@cla-bot check

tomholford avatar Jan 31 '24 17:01 tomholford

The cla-bot has been summoned, and re-checked this pull request!

cla-bot[bot] avatar Jan 31 '24 17:01 cla-bot[bot]

When this feature release?

lutfi-haslab avatar Feb 02 '24 02:02 lutfi-haslab

@SomeoneToIgnore: Thanks for marking as draft. Quick update: Had to focus on other priorities, but will be able to pivot back to this soon.

At this point I have some of the LSP features working: go to definition, basic type tooltips, auto-formatting, syntax highlighting. I'm going to try to take another crack at getting the advanced features mentioned in the solidity-language-server docs working.

I have pushed a wip commit with my progress so far. I am new to this project (and Rust) and could use help if you have a moment. Do you happen to know why the print_completion_item closure is not printing any output when I run the binary in dev mode?

tomholford avatar Feb 06 '24 16:02 tomholford

Great news! I'm afraid I have no idea why print_completion_item does not print, but do you say that non-dev mode works just fine?

SomeoneToIgnore avatar Feb 07 '24 06:02 SomeoneToIgnore

Great news! I'm afraid I have no idea why print_completion_item does not print, but do you say that non-dev mode works just fine?

@SomeoneToIgnore I have rebased on main, run in both dev and non-dev modes, and the features highlighted in the PR description are working as expected. I think this is a good first cut for Solidity integration with zed. A future iteration could add the advanced features / deeper integration with the Solidity LSP. So, going to re-open this for review.

tomholford avatar Feb 07 '24 17:02 tomholford

This is going to have some conflicts with zed-industries/zed#7467, so we're going to land that first.

maxdeviant avatar Feb 07 '24 18:02 maxdeviant

This is going to have some conflicts with zed-industries/zed#7467, so we're going to land that first.

@maxdeviant Thanks for the heads up. Now that zed-industries/zed#7467 is merged, I rebased this branch on main and made the appropriate changes to this diff. Tested locally with both cargo run and cargo run --release and still working as expected. So, requesting a re-review.

edit: cc @SomeoneToIgnore

tomholford avatar Feb 07 '24 22:02 tomholford

I have not noticed any QOL improvements in the project I linked above since the last review:

  • zero rename, tooltips or go to definition capabilities still
  • while the completion list got bigger, it seems that now it just tries to add every possible thing to the completion list? E.g. here it allows me to autocomplete every "struct" after the . which does not seem right at all: image

Is there a public project that I can try where something from above works?

do you mean a different solidity repo or a different editor with autocomplete? if the latter, i use vscode which doesnt really support great autocomplete (if any at all). i think that even having syntax highlighting and error indication would satisfy most people, although full support is def better

koloz193 avatar Feb 08 '24 13:02 koloz193

Great point about VSCode, I've tried to use https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity extension and found its functionality quite morbid too.

Speaking of

error indication

I've noticed that VSCode's plugin is able to show those, yet Zed's does not at all? image

Also notice that there's hovers shown too, but those seem quite useless information-wise.


I would still want get down to the bottom of https://github.com/zed-industries/zed/pull/7152#issuecomment-1932588676 comment:

and the features highlighted in the PR description are working as expected

I see no "go to definition" and hovers for https://github.com/SunWeb3Sec/DeFiHackLabs but see those in the PR description. What is wrong here? The project in question? Me trying the wrong definitions for those features? Before merging this, I would love to experience myself that the features declared in the PR description work.

SomeoneToIgnore avatar Feb 08 '24 14:02 SomeoneToIgnore

Great point about VSCode, I've tried to use https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity extension and found its functionality quite morbid too.

Speaking of

error indication

I've noticed that VSCode's plugin is able to show those, yet Zed's does not at all? image

Also notice that there's hovers shown too, but those seem quite useless information-wise.

I would still want get down to the bottom of #7152 (comment) comment:

and the features highlighted in the PR description are working as expected

I see no "go to definition" and hovers for https://github.com/SunWeb3Sec/DeFiHackLabs but see those in the PR description. What is wrong here? The project in question? Me trying the wrong definitions for those features? Before merging this, I would love to experience myself that the features declared in the PR description work.

For feature parity I would compare with this which uses the same LSP under the hood

stevennevins avatar Feb 08 '24 14:02 stevennevins

Thank you, that makes things more comparable indeed! At least, the formatting functionality and zero error highlights behavior matches now.

Yet, that plugin shows hovers and allows to go to definition in the project I use: image

and current PR's version does not, so my questions in the previous message hold.

SomeoneToIgnore avatar Feb 08 '24 15:02 SomeoneToIgnore

Thank you, that makes things more comparable indeed! At least, the formatting functionality and zero error highlights behavior matches now.

Yet, that plugin shows hovers and allows to go to definition in the project I use: image

and current PR's version does not, so my questions in the previous message hold.

Thanks for the feedback. Any suggestions on how to proceed from here? Tried to print debug output to the console, but no luck with that.

tomholford avatar Feb 10 '24 01:02 tomholford

Just a heads up - we are very soon going to be moving most of Zed's built-in languages into installable extensions (https://github.com/zed-industries/zed/issues/7096). Solidity is a major enough language that I'm ok with merging this in the meantime. But once the extension system lands, we will probably remove this code and put it into a new solidity repository under the new zed-extensions GitHub org. We'll probably add you as a collaborator on that repo when we do it, if you're interested in helping maintain it.

It would be good to understand why some of the LSP features aren't working for @SomeoneToIgnore . @tomholford so just to confirm - the LSP works for you reliably? What Solidity projects are you testing against?

maxbrunsfeld avatar Feb 10 '24 21:02 maxbrunsfeld

Just a heads up - we are very soon going to be moving most of Zed's built-in languages into installable extensions (#7096). Solidity is a major enough language that I'm ok with merging this in the meantime. But once the extension system lands, we will probably remove this code and put it into a new solidity repository under the new zed-extensions GitHub org. We'll probably add you as a collaborator on that repo when we do it, if you're interested in helping maintain it.

Thanks for the heads up. And that sounds good, I'm happy to help any way that I can.

It would be good to understand why some of the LSP features aren't working for @SomeoneToIgnore . @tomholford so just to confirm - the LSP works for you reliably? What Solidity projects are you testing against?

Confirming that the features described in the PR's Preview section above WOMM. I have been using my fork (with periodic rebases on main) for other projexts. As a test project to record the gifs above, I have been using this:

https://github.com/PopPunkLLC/gaslite-core

tomholford avatar Feb 12 '24 18:02 tomholford

I see that things like Java are being added as Zed extensions: https://github.com/zed-industries/extensions/pull/57 There seems to be slightly less nitpicking in reviews for such PRs (at least, I'm not reviewing anything there, so won't complain about anything 🙂 ) as those are considered "standalone" from Zed code.

Maybe, it's worth converting this into the extension and submitting a PR there.

SomeoneToIgnore avatar Feb 18 '24 15:02 SomeoneToIgnore

I see that things like Java are being added as Zed extensions: zed-industries/extensions#57 There seems to be slightly less nitpicking in reviews for such PRs (at least, I'm not reviewing anything there, so won't complain about anything 🙂 ) as those are considered "standalone" from Zed code.

Maybe, it's worth converting this into the extension and submitting a PR there.

Good call, going to close this and reopen as an extension.

tomholford avatar Feb 23 '24 02:02 tomholford