-
Notifications
You must be signed in to change notification settings - Fork 161
add code fix for wildcard _ in pattern match for fs43 on |-> #1157
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
Open
jkone27
wants to merge
5
commits into
ionide:main
Choose a base branch
from
jkone27:fix-dotnet-fsharp-15748-amplifying-fsharp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
df83900
add code fix for wildcard operator suggestion in pattern match for fs43
jkone27 a0e0cd5
Update src/FsAutoComplete/CodeFixes/AddMissingWildcardOperator.fsi
jkone27 543e242
remove-commented-code
jkone27 55294bc
Update AddMissingWildcardOperator.fsi
jkone27 d3d6f8d
applied formatting with dotnet fantomas
jkone27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/FsAutoComplete/CodeFixes/AddMissingWildcardOperator.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| module FsAutoComplete.CodeFix.AddMissingWildcardOperator | ||
|
|
||
| open FsToolkit.ErrorHandling | ||
| open FsAutoComplete.CodeFix.Navigation | ||
| open FsAutoComplete.CodeFix.Types | ||
| open Ionide.LanguageServerProtocol.Types | ||
| open FsAutoComplete | ||
| open FsAutoComplete.LspHelpers | ||
| open FSharp.Compiler.Syntax | ||
| open FSharp.Compiler.Text | ||
| open FSharp.Compiler.SyntaxTrivia | ||
|
|
||
| let title = "Add missing wildcard operator" | ||
|
|
||
|
|
||
| let tryFindPattern pos input = | ||
|
|
||
| let visitor = | ||
| { new SyntaxVisitorBase<range>() with | ||
|
|
||
| member _.VisitExpr(path, traverseSynExpr, defaultTraverse, expr) = | ||
| match expr with | ||
| | SynExpr.LongIdent( | ||
| longDotId = SynLongIdent.SynLongIdent(trivia = [ Some(IdentTrivia.OriginalNotation("|->")) ]) | ||
| range = range) when FSharp.Compiler.Text.Range.rangeContainsPos range pos -> | ||
|
|
||
| Some(range) | ||
|
|
||
| | _ -> defaultTraverse expr } | ||
|
|
||
| SyntaxTraversal.Traverse(pos, input, visitor) | ||
|
|
||
|
|
||
|
|
||
| /// a codefix that adds a missing 'fun' keyword to a lambda | ||
| let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix = | ||
| Run.ifDiagnosticByCode (Set.ofList [ "43" ]) (fun diagnostic codeActionParams -> | ||
| asyncResult { | ||
|
|
||
| let filePath = codeActionParams.TextDocument.GetFilePath() |> Utils.normalizePath | ||
| let fcsPos = protocolPosToPos codeActionParams.Range.Start | ||
| let! (parseAndCheck, lineStr, _sourceText) = getParseResultsForFile filePath fcsPos | ||
|
|
||
| match tryFindPattern fcsPos parseAndCheck.GetAST with | ||
| | None -> return [] | ||
| | Some operatorRange -> | ||
|
|
||
| let lspRange = fcsRangeToLsp operatorRange | ||
|
|
||
| return | ||
| [ { Title = title | ||
| File = codeActionParams.TextDocument | ||
| SourceDiagnostic = Some diagnostic | ||
| Edits = [| { Range = lspRange; NewText = "| _ ->" } |] | ||
| Kind = FixKind.Fix } ] | ||
| }) | ||
12 changes: 12 additions & 0 deletions
12
src/FsAutoComplete/CodeFixes/AddMissingWildcardOperator.fsi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| module FsAutoComplete.CodeFix.AddMissingWildcardOperator | ||
|
|
||
| open FsToolkit.ErrorHandling | ||
| open FsAutoComplete.CodeFix.Navigation | ||
| open FsAutoComplete.CodeFix.Types | ||
| open Ionide.LanguageServerProtocol.Types | ||
| open FsAutoComplete | ||
| open FsAutoComplete.LspHelpers | ||
|
|
||
| val title: string | ||
| /// a codefix that adds a missing wildcard pattern to a match case | ||
| val fix: getParseResultsForFile: GetParseResultsForFile -> CodeFix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/FsAutoComplete.Tests.Lsp/CodeFixTests/AddMissingWildcardOperatorTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| module private FsAutoComplete.Tests.CodeFixTests.AddMissingWildcardOperatorTests | ||
|
|
||
| open Expecto | ||
| open Helpers | ||
| open Utils.ServerTests | ||
| open Utils.CursorbasedTests | ||
| open FsAutoComplete.CodeFix | ||
|
|
||
| let tests state = | ||
| serverTestList (nameof AddMissingWildcardOperator) state defaultConfigDto None (fun server -> | ||
| [ let selectCodeFix = CodeFix.withTitle AddMissingWildcardOperator.title | ||
|
|
||
| ftestCaseAsync "can suggest wildcard pattern for missing match case" | ||
| <| CodeFix.check | ||
| server | ||
| """ | ||
| type SomeUnion = | ||
| | First | ||
| | Second | ||
|
|
||
| let testMatch su = | ||
| match su with | ||
| | First -> "hey" | ||
| $0|-> "hello" | ||
| """ | ||
| (Diagnostics.expectCode "43") | ||
| selectCodeFix | ||
| """ | ||
| type SomeUnion = | ||
| | First | ||
| | Second | ||
|
|
||
| let testMatch su = | ||
| match su with | ||
| | First -> "hey" | ||
| | _ -> "hello" | ||
| """ ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.