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

Update FCS to 'Allow ParsedHashDirectives to take non string arguments' #3096

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Changed
* Update FCS to 'Allow ParsedHashDirectives to take non string arguments', commit 836d4e0603442d6053c8d439993a022501cae494 [#3096](https://github.com/fsprojects/fantomas/pull/3096)

## 6.3.9 - 2024-06-10

### Fixed
Expand Down
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ Some common use cases include:
<!-- https://www.gresearch.co.uk/blog/article/improve-nuget-restores-with-static-graph-evaluation/ -->
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<ServerGarbageCollection>true</ServerGarbageCollection>
<LangVersion>preview</LangVersion>
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking --test:ParallelOptimization --test:ParallelIlxGen --strict-indentation+</OtherFlags>
</PropertyGroup>

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>050271d631956a4e0d0484a583d38236b727a46d</FCSCommitHash>
<FCSCommitHash>836d4e0603442d6053c8d439993a022501cae494</FCSCommitHash>
</PropertyGroup>

<PropertyGroup>
Expand Down
42 changes: 42 additions & 0 deletions src/Fantomas.Core.Tests/HashDirectiveTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,45 @@ type FSharpTokenizerColorState =
| TripleQuoteStringInComment = 14
| InitialState = 0
"""

[<Test>]
let ``#help with string`` () =
formatSourceString
"""
#help "List.map"
"""
config
|> prepend newline
|> should
equal
"""
#help "List.map"
"""

[<Test>]
let ``#help without string`` () =
formatSourceString
"""
#help List.map
"""
config
|> prepend newline
|> should
equal
"""
#help List.map
"""

[<Test>]
let ``#nowarn with integer`` () =
formatSourceString
"""
#nowarn 1182
"""
config
|> prepend newline
|> should
equal
"""
#nowarn 1182
"""
9 changes: 7 additions & 2 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@
args
|> List.map (function
| ParsedHashDirectiveArgument.String(value, stringKind, range) ->
mkConstString creationAide stringKind value range
| ParsedHashDirectiveArgument.SourceIdentifier(identifier, _, range) -> stn identifier range)
mkConstString creationAide stringKind value range |> Choice1Of2
| ParsedHashDirectiveArgument.SourceIdentifier(identifier, _, range) -> stn identifier range |> Choice1Of2
| ParsedHashDirectiveArgument.Int32(value, range) ->
let text = creationAide.TextFromSource (fun () -> $"%A{value}") range
stn text range |> Choice1Of2
| ParsedHashDirectiveArgument.Ident(value = ident) -> mkIdent ident |> Choice1Of2
| ParsedHashDirectiveArgument.LongIdent(value = lid) -> mkSynLongIdent lid |> Choice2Of2)

ParsedHashDirectiveNode(ident, args, range)

Expand Down Expand Up @@ -381,7 +386,7 @@
skipGeneratedMatch skippedLambdas

let mkLambda creationAide pats mArrow body (StartRange 3 (mFun, m)) : ExprLambdaNode =
let body = getLambdaBodyExpr body

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'

Check warning on line 389 in src/Fantomas.Core/ASTTransformer.fs

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

Failed to inline the value 'getLambdaBodyExpr' marked 'inline', perhaps because a recursive value was marked 'inline'
ExprLambdaNode(stn "fun" mFun, List.map (mkPat creationAide) pats, stn "->" mArrow, mkExpr creationAide body, m)

let mkSynMatchClause creationAide (SynMatchClause(p, eo, e, range, _, trivia)) : MatchClauseNode =
Expand Down
8 changes: 6 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ let addSpaceBeforeParenInPattern (node: IdentListNode) (ctx: Context) =
| _ -> sepSpace ctx

let genParsedHashDirective (phd: ParsedHashDirectiveNode) =
!- "#" +> !-phd.Ident +> sepSpace +> col sepSpace phd.Args genSingleTextNode
|> genNode phd
let genArg =
function
| Choice1Of2(stn) -> genSingleTextNode stn
| Choice2Of2(idl) -> genIdentListNode idl

!- "#" +> !-phd.Ident +> sepSpace +> col sepSpace phd.Args genArg |> genNode phd

let genUnit (n: UnitNode) =
genSingleTextNode n.OpeningParen +> genSingleTextNode n.ClosingParen
Expand Down
9 changes: 7 additions & 2 deletions src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ type Oak(parsedHashDirectives: ParsedHashDirectiveNode list, modulesOrNamespaces

override val Children: Node array = [| yield! nodes parsedHashDirectives; yield! nodes modulesOrNamespaces |]

type ParsedHashDirectiveNode(ident: string, args: SingleTextNode list, range) =
type ParsedHashDirectiveNode(ident: string, args: Choice<SingleTextNode, IdentListNode> list, range) =
inherit NodeBase(range)
member val Ident = ident
member val Args = args
override val Children: Node array = [| yield! nodes args |]

override val Children: Node array =
[| for arg in args do
match arg with
| Choice1Of2(node) -> node
| Choice2Of2(node) -> node |]

type ModuleOrNamespaceHeaderNode
(
Expand Down
Loading