Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fold regions for lambda without block #38597

Closed
5 tasks done
xiaoxiangmoe opened this issue May 15, 2020 · 11 comments · Fixed by #39109
Closed
5 tasks done

Support fold regions for lambda without block #38597

xiaoxiangmoe opened this issue May 15, 2020 · 11 comments · Fixed by #39109
Labels
Domain: Outlining Relates to multi-line regions that editors can collapse Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this

Comments

@xiaoxiangmoe
Copy link
Contributor

xiaoxiangmoe commented May 15, 2020

Search Terms

VSCode, Language Service

Suggestion

Support fold regions for lambda without block

const fooBar$ = pageList$.pipe(
  map(pageList =>
    pageList.map(
      page =>
        page.pageConfig.find(
          config =>
            config.key.orgId === KeyOrgId.MyOrg &&
            config.key.Id === KeytId.MyKey,
        ).data ?? {},
    ),
  ),
  shareReplay(1),
)

This TypeScript code can't fold unless we change all x=>y to x=>{ return y; }

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Related issue

microsoft/vscode#97415

@ahejlsberg
Copy link
Member

Please post a complete example. Several functions/methods have no declaration so it's impossible to know what they do.

@ahejlsberg ahejlsberg added the Needs More Info The issue still hasn't been fully clarified label May 15, 2020
@xiaoxiangmoe
Copy link
Contributor Author

@ahejlsberg

If we write arrow function without braces block, no fold regions:
image

If we refactor it with braces block, it will support fold regions:
image
image

@xiaoxiangmoe
Copy link
Contributor Author

image

When we use rxjs with arrow functions, we cannot collapse most of the code.

@DanielRosenwasser DanielRosenwasser added Domain: Outlining Relates to multi-line regions that editors can collapse Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this and removed Needs More Info The issue still hasn't been fully clarified labels Jun 12, 2020
@DanielRosenwasser DanielRosenwasser added this to the Backlog milestone Jun 12, 2020
@DanielRosenwasser
Copy link
Member

@jessetrinity do we have any sort of heuristics where things that aren't blocks but are multi-line still get an outlining span?

@DanielRosenwasser
Copy link
Member

Also, in this case the declarations aren't really necessary, outlining spans don't currently need semantic information.

@jessetrinity
Copy link
Contributor

jessetrinity commented Jun 12, 2020

In most cases we collapse to the bounds defined by the open/close tokens. One example is JSX elements for which we collapse about < and >.

In the arrow functions case, we could probably just collapse the arrow function body?

foldArrowFunction

@xiaoxiangmoe
Copy link
Contributor Author

xiaoxiangmoe commented Jun 14, 2020

@jessetrinity Great Job!

Also, can we fold long parameters list?

For example:

const bar$ = foo$.pipe(
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  map(x => x),
  shareReplay(1)
);

It would be great if we can fold in .pipe()

@DanielRosenwasser
Copy link
Member

I would say arrow function body provided it spans 3 lines at least.

@Kingwl
Copy link
Contributor

Kingwl commented Jun 16, 2020

Happy to work on this if @jessetrinity did not start the work.

@jessetrinity
Copy link
Contributor

Go for it, I just added a case for arrow functions to the switch statement here:

It looked like there was more tweaking to do to to correctly fold the body when the function call is on the same line as the arrow e.g.

a => map(
    ...
)

@DanielRosenwasser
Copy link
Member

Thanks @Kingwl!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Outlining Relates to multi-line regions that editors can collapse Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants