Skip to content

add code fix for wildcard _ in pattern match for fs43 on |->#1157

Closed
jkone27 wants to merge 5 commits intoionide:mainfrom
jkone27:fix-dotnet-fsharp-15748-amplifying-fsharp
Closed

add code fix for wildcard _ in pattern match for fs43 on |->#1157
jkone27 wants to merge 5 commits intoionide:mainfrom
jkone27:fix-dotnet-fsharp-15748-amplifying-fsharp

Conversation

@jkone27
Copy link
Contributor

@jkone27 jkone27 commented Sep 1, 2023

Suggest | _ -> for match mistaken with infix operator |->

add code fix for wildcard operator suggestion in pattern match for fs43, targets:
dotnet/fsharp#15748

as worked in amplifying fsharp session:
https://amplifying-fsharp.github.io/sessions/2023/09/01/

WHY

the operator |-> is not defined, so this is usually just a user forgetting to complete the match

HOW

🤖 Generated by Copilot at df83900

  • Add a new code fix for adding a missing wildcard operator to a match expression (link, link)
    • Define a new module FsAutoComplete.CodeFix.AddMissingWildcardOperator in src/FsAutoComplete/CodeFixes/AddMissingWildcardOperator.fs and its signature file in src/FsAutoComplete/CodeFixes/AddMissingWildcardOperator.fsi (link, link)
    • Export a title, a function to try to find the pattern that needs the fix, and a function to apply the fix using the CodeFix type and the SyntaxVisitorBase and SyntaxTraversal utilities (link, link)
  • Register the new code fix function in the language server implementations (link, link)
    • Add the function to the list of code fixes supported by the AdaptiveFSharpLspServer type in src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs (link)
    • Add the function to the list of code fixes supported by the FSharpLspServer type in src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs (link)
  • Add a test case for the new code fix using the test helpers (link, link)
    • Define a new test module FsAutoComplete.Tests.CodeFixTests.AddMissingWildcardOperatorTests in test/FsAutoComplete.Tests.Lsp/CodeFixTests/AddMissingWildcardOperatorTests.fs (link)
    • Check that the code fix can suggest a wildcard pattern for a missing match case in a simple example using the CodeFix and Diagnostics utilities (link)
    • Add the new test module to the list of test modules in the tests function in test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs (link)

Copy link
Member

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

@dawedawe mentioned some good fixes

jkone27 and others added 2 commits September 6, 2023 10:52
@baronfel
Copy link
Contributor

baronfel commented Sep 6, 2023

Needs a format but otherwise LGTM.

@jkone27
Copy link
Contributor Author

jkone27 commented Sep 13, 2023

fixed the suggestions, not clear how i run format, can it be added as a git hook at commit phase on master? i am not very familiar with fantomas, would be good if it could be hooked onto dotnet format or .editorconfig i guess most .net devs are familiar with those concepts. formatted the changed files individually with
dotnet fantomas filename.fs

@nojaf
Copy link
Contributor

nojaf commented Sep 14, 2023

Hi,

Running this target sets up the git hook:
https://github.com/fsharp/FsAutoComplete/blob/e3353360771969be51ab3c84a57a432cf41816cf/build/Program.fs#L107-L110

dotnet run --project ./build/build.fsproj -- -t EnsureRepoConfig

And I think it would be nice to see a message when
https://github.com/fsharp/FsAutoComplete/blob/e3353360771969be51ab3c84a57a432cf41816cf/Directory.Solution.targets#L10-L12

fails.

Something like Please run "dotnet fantomas src" to format your files.
I'm not sure how to do that one with msbuild trickery.

@edgarfgp
Copy link
Contributor

edgarfgp commented Sep 27, 2023

@jkone27 Could you have a look at the conflicts. Seems that this almost ready :)

@Krzysztof-Cieslak
Copy link
Member

/repo-assist can you rebase this PR

@github-actions
Copy link
Contributor

🤖 This is an automated response from Repo Assist.

Hi @jkone27! I've completed the rebase analysis for this PR. Unfortunately I'm unable to force-push the rebased branch directly (rebasing rewrites commit history which requires a force push), but I've worked through all the conflicts and can share exactly what needs to change.

Rebase Summary

The PR has 5 commits that cherry-pick cleanly onto current main with the following conflict resolutions:

Key changes needed to bring this PR up to date:

1. src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs — deleted
This file was removed from the codebase. The change to this file in the original PR should be dropped.

2. src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs — no change needed
The forceGetProjectOptions/forceGetFSharpProjectOptions helper functions that conflicted are already in the current file (added by a later commit). No action needed.

3. src/FsAutoComplete/LspServers/AdaptiveServerState.fs — add registration
Code fixes are now registered here instead of AdaptiveFSharpLspServer.fs. Add one line:

         AddMissingFunKeyword.fix forceFindSourceText getLineText
+        AddMissingWildcardOperator.fix tryGetParseAndCheckResultsForFile
         MakeOuterBindingRecursive.fix tryGetParseAndCheckResultsForFile getLineText

4. test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs — add test entry

-      ExprTypeMismatchTests.tests state ]
+      ExprTypeMismatchTests.tests state
+      AddMissingWildcardOperatorTests.tests state ]

5. test/FsAutoComplete.Tests.Lsp/CodeFixTests/AddMissingWildcardOperatorTests.fs — fix focused test
Change ftestCaseAsynctestCaseAsync (focused test markers cause CI failures).

Quick rebase commands

git fetch upstream main
git rebase upstream/main
# Resolve conflicts as described above, then:
git push --force-with-lease origin fix-dotnet-fsharp-15748-amplifying-fsharp

The new files (AddMissingWildcardOperator.fs, AddMissingWildcardOperator.fsi, AddMissingWildcardOperatorTests.fs) should apply cleanly — the only manual work is the 3 small changes above.

Let me know if you'd like any help! 🙂

Generated by Repo Assist for issue #1157

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@f2c5cf1e4af58e09a93ba0703c6bf084711b265f. View source at https://github.com/githubnext/agentics/tree/f2c5cf1e4af58e09a93ba0703c6bf084711b265f/workflows/repo-assist.md.

@Krzysztof-Cieslak
Copy link
Member

/repo-assist rebase changes from this PR and push them as new PR

github-actions bot added a commit that referenced this pull request Feb 25, 2026
Rebased changes from PR #1157 by @jkone27 onto current main.

Adds a code fix that suggests replacing the invalid infix operator '|->'
with the correct wildcard pattern '| _ ->' in a match expression when
the F# compiler diagnostic FS0043 is raised.

Closes #1157

Co-authored-by: jkone27 <10419217+jkone27@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

Pull request created: #1472

Generated by Repo Assist

@github-actions
Copy link
Contributor

🤖 This is an automated response from Repo Assist.

Done! I've rebased the changes from this PR onto current main and created a new PR with the rebased changes.

The following adaptations were made:

  • FsAutoComplete.Lsp.fs was removed from the codebase — that change was dropped
  • Code fix registration moved from AdaptiveFSharpLspServer.fs to AdaptiveServerState.fs
  • ftestCaseAsynctestCaseAsync (focused test markers cause CI failures)
  • Fixed unused variable lineStr_lineStr

The build succeeds ✅. The new PR is ready for review.

Generated by Repo Assist for issue #1157

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@f2c5cf1e4af58e09a93ba0703c6bf084711b265f. View source at https://github.com/githubnext/agentics/tree/f2c5cf1e4af58e09a93ba0703c6bf084711b265f/workflows/repo-assist.md.

@Krzysztof-Cieslak
Copy link
Member

Thanks a lot for this, and sorry it took us so long to merge it

Krzysztof-Cieslak pushed a commit that referenced this pull request Feb 26, 2026
… for FS0043 (#1472)

* feat: add code fix for wildcard _ in pattern match for FS0043

Rebased changes from PR #1157 by @jkone27 onto current main.

Adds a code fix that suggests replacing the invalid infix operator '|->'
with the correct wildcard pattern '| _ ->' in a match expression when
the F# compiler diagnostic FS0043 is raised.

Closes #1157

Co-authored-by: jkone27 <10419217+jkone27@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* ci: trigger CI checks

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: jkone27 <10419217+jkone27@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants