microsoft / typespec

https://typespec.io/
MIT License
4.36k stars 203 forks source link

Feedback on decorator collapsing #860

Open tjprescott opened 2 years ago

tjprescott commented 2 years ago

VSCode has tooling that lets you collapse the decorator block, but it compresses it does to a single decorator line. The architects expected to show no decorators.

uncollapsed

@A
@B(...)
@C
op myOp(...)

current collapsed

@A
op myOp(...)

expected collapsed

op myOp(...)
nguerrera commented 2 years ago

We wanted it to work this way and we tried to do this, but it seems that we can't control what is shown when a range is collapsed from language server and we end up seeing only the first decorator and not the op. So we made the decision to collapse decorators separately.

nguerrera commented 2 years ago

I think it's easier with some visual on what is collapsible and best shown with multiple lines of decorators and multiple lines of op declaration.

Uncollapsed

v @A
  @B
  @C
v op myOp(
      param: string): void;

Collapsed

> @A ...
> op myOp( ...

It's worth noting that the handling of decorators as their own collapsible region is the same as TS does for comments.

nguerrera commented 2 years ago

Ooh, the latest version of LSP supports setting the collapsed text!

https://github.com/microsoft/vscode-languageserver-node/blob/8b56a58d0a706bc0cc8e947b42ad135faf488fe3/types/src/main.ts#L532

I was about to link to this and show that it did not and that we'd have to ask for a feature, but looks like it's there now. Yay.

markcowl commented 2 years ago

pri: 2, est: 3

nguerrera commented 2 years ago

Unfortunately, collapsedText doesn't seem to be supported on the client side yet. I tried upgrading our packages and returning it but it didn't have an impact. :(

nguerrera commented 2 years ago

https://github.com/microsoft/vscode-languageserver-node/issues/1068

nguerrera commented 2 years ago

Marking this as blocked in the project for now until I get an answer on that.

nguerrera commented 2 years ago

Attempt here: https://github.com/microsoft/cadl/compare/nguerrera:collapse-decorators

nguerrera commented 2 years ago

Moving to backlog as this is not possible to implement for VS Code yet. I will continue to engage on linked issue and figure out how to request and track the dependency.

nguerrera commented 2 years ago

https://github.com/microsoft/vscode/issues/70794 is the tracking issue on vscode. Consider upvoting there. We're blocked on that.

cc @johanste

nguerrera commented 2 years ago

We could consider implementing this for editors that have the capability by checking the capability. This would include at least Visual Studio classic, it appears. Then in theory if the capability ever shows up in VS Code it would start working right away.