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

Parens: more fixes #16901

Merged
merged 16 commits into from
Mar 21, 2024
Merged

Parens: more fixes #16901

merged 16 commits into from
Mar 21, 2024

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Mar 19, 2024

Another followup to #16079.

Description

  • Keep parens around match-like exprs and let exprs in if exprs, while exprs, and for exprs.
  • Keep parens around nested, dangling as patterns.
  • Keep parens around outlaw match exprs, i.e., where the first | is leftward of the m in match.
  • Don't be led astray by single-line comments // /// when determining offsides lines. (Multiline comments (*…*) technically pose the same problem, but handling them (and multiline strings, ifdefs, etc.) would require a different approach.)
  • Keep double parens around tuples in more places, since sometimes their necessity cannot be determined from syntax alone.
  • Keep parens around multiline tuple patterns in let bindings when removing them would parse differently.
  • Handle typed pats in getters and setters.
  • Keep parens for parenthesized app preceded by high-precedence prefix op.
  • Keep parens around tuples in interpolated strings.
  • Keep parens around nested match-like constructs in more places.
  • Don't add a space when removing parens when doing so would result in reparsing an infix op as a prefix op.
  • Keep parens around a dot-get on another parenthesized expression that would be reinterpreted as an "atomic" arg of the outer function application due to its adjacency.

Good news: I can now successfully apply "fix all" to the entire FSharp.Compiler.Service project — with ~6,600 lines updated in 155 files — and it still builds successfully after:

Screenshot 2024-03-19 125050

Checklist

  • Test cases added
  • Release notes entry updated

* Match-like exprs in `if` exprs, `while` exprs, and `for` exprs. Also
  `let` exprs.

* Nested, dangling `as` patterns.

* Outlaw `match` exprs (where the first `|` is leftward of the `m` in
  `match)

* Single-line comments (`//`, `///`). Multiline comments (`(*…*)`)
  would be… rather more difficult to handle.

* Double-parenthesized tuples in method applications, since we can't
  tell purely syntactically whether the tuple might be the first
  parameter of a method whose next parameter is an implied outref
  parameter:
	  `x.TryGetValue ((y, z))`
	  i.e.,
	  `x.TryGetValue ((y, z), &value)`

* Multiline tuple patterns in `let`-bindings. These need parens if the
  bound expression starts on the same column.
* Sometimes we can't tell just by looking at the untyped AST whether we
  need parens, since their necessity may be dictated by type information
  located elsewhere. Compare, e.g., dotnet#16254,
  which probably has a similar underlying cause.
Copy link
Contributor

github-actions bot commented Mar 19, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
vsintegration/src docs/release-notes/.VisualStudio/17.10.md

@brianrourkeboll brianrourkeboll marked this pull request as ready for review March 19, 2024 17:17
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner March 19, 2024 17:17
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

* E.g., removing parens in place from

  ```fsharp
  Debug.Assert((xT.DeclaringType :?> ProvidedTypeDefinition).BelongsToTargetModel)
  ```

  would result in the the argument to `Assert` becoming
  `(xT.DeclaringType :?> ProvidedTypeDefinition)`. The
  `.BelongsToTargetModel` would then be parsed as a get on the return
  value of _that_ call.
@psfinaki
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki psfinaki merged commit c7fcbf6 into dotnet:main Mar 21, 2024
32 checks passed
@brianrourkeboll brianrourkeboll deleted the parens-again branch March 21, 2024 19:58
brianrourkeboll added a commit to brianrourkeboll/FsAutoComplete that referenced this pull request May 7, 2024
See dotnet/fsharp#16901

* Keep parens around outlaw `match` exprs (where the first `|` is
  leftward of the start of the `match` keyword).

* Ignore single-line comments when determining offsides lines.

* Don't add a space when removing parens when doing so would result in
  reparsing an infix op as a prefix op.
TheAngryByrd pushed a commit to ionide/FsAutoComplete that referenced this pull request May 8, 2024
See dotnet/fsharp#16901

* Keep parens around outlaw `match` exprs (where the first `|` is
  leftward of the start of the `match` keyword).

* Ignore single-line comments when determining offsides lines.

* Don't add a space when removing parens when doing so would result in
  reparsing an infix op as a prefix op.
TheAngryByrd added a commit to ionide/FsAutoComplete that referenced this pull request May 9, 2024
* Shift multiline paren contents less aggressively (#1242)

* Shift multiline paren contents less aggressively

* Make it actually work

* Disambiguate AsSpan overload

* Add some code fixes for type mismatch. (#1250)

* Migrate FAKE to Fun.Build (#1256)

* Migrate FAKE to Fun.Build

* Add default Build pipeline.

* Purge it with fire (#1255)

* Bump analyzers and Fantomas (#1257)

* Add empty, disabled tests for go-to-def on C# symbol scenario

* fix unicode characters in F# compiler diagnostic messages (#1265)

* fix unicode chars in F# compiler diagnostic messages

* fix typo in ShadowedTimeouts focused tests

* fixup! fix unicode chars in F# compiler diagnostic messages

* remove focused tests...

* remove debug prints

Co-authored-by: Jimmy Byrd <[email protected]>

---------

Co-authored-by: Jimmy Byrd <[email protected]>

* - remove an ignored call to protocolRangeToRange (#1266)

- remove an ignored instance of StreamJsonRpcTracingStrategy

* Place XML doc lines before any attribute lists (#1267)

* Don't generate params for explicit getters/setters as they are flagged invalid by the compiler (#1268)

* bump ProjInfo to the next version to get support for loading broken projects and loading traversal projects (#1270)

* only allow one GetProjectOptionsFromScript at a time (#1275)

ionide/ionide-vscode-fsharp#2005

* changelog for v0.72.0

* changelog for v0.72.1

* Use actualRootPath instead of p.RootPath when peeking workspaces. (#1278)

This fix the issue where rootUri was ignored when using AutomaticWorkspaceInit.

* changelog for v0.72.2

* Add support for Cancel a Work Done Progress  (#1274)

* Add support for Cancel WorkDoneProgress

* Fix up saving cancellation

* package the tool for .NET 8 as well (#1281)

* update changelogs

* Adds basic OTel Metric support to fsautocomplete (#1283)

* Some parens fixes (#1286)

See dotnet/fsharp#16901

* Keep parens around outlaw `match` exprs (where the first `|` is
  leftward of the start of the `match` keyword).

* Ignore single-line comments when determining offsides lines.

* Don't add a space when removing parens when doing so would result in
  reparsing an infix op as a prefix op.

* Run LSP tests sequenced (#1287)

I'm tired of all the weird failures because of parallelism

---------

Co-authored-by: Brian Rourke Boll <[email protected]>
Co-authored-by: Florian Verdonck <[email protected]>
Co-authored-by: Krzysztof Cieślak <[email protected]>
Co-authored-by: MrLuje <[email protected]>
Co-authored-by: dawe <[email protected]>
Co-authored-by: Chet Husk <[email protected]>
Co-authored-by: oupson <[email protected]>
Co-authored-by: Chet Husk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants