Skip to content

Commit e111b2b

Browse files
authored
Merge pull request #15590 from dotnet/merges/main-to-release/dev17.8
2 parents 0b3c293 + e9cc2a0 commit e111b2b

19 files changed

+461
-120
lines changed

INTERNAL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Update the `insertTargetBranch` value at the bottom of `azure-pipelines.yml` in
8484
9. Change needed subscriptions for arcade and SDK:
8585
1. `darc get-subscriptions --target-repo fsharp`, and then use `darc update-subscription --id <subscription id>` for corresponding channels (e.g. target new VS channel to specific SDK channel, or set up arcade auto-merges to release/* or main branch, depending on the timeline of release/upgrade cycle).
8686
2. If new subscription needs to be added, the following command should be used `darc add-subscription --source-repo https://github.com/dotnet/arcade --target-repo https://github.com/dotnet/fsharp --target-branch <target_branch> --channel "<target_channel>" --update-frequency everyDay --standard-automerge
87+
10. Update mibc and other dependencies if needed, refer to https://github.com/dotnet/arcade/blob/main/Documentation/Darc.md#updating-dependencies-in-your-local-repository for more information
8788
`
8889

8990
## Labeling issues on GitHub

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<Sha>4234ffac87e305da80597cb46dc0d4a87fc4f7c2</Sha>
77
<SourceBuild RepoName="xliff-tasks" ManagedOnly="true" />
88
</Dependency>
9-
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="8.0.0-alpha.1.23330.2">
9+
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="8.0.0-alpha.1.23356.4">
1010
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
11-
<Sha>c7e229b7e8cd71c8479e236ae1efff3ad1d740f9</Sha>
11+
<Sha>81a9aad6994047fc0e589a82597d1d8c179f22bd</Sha>
1212
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
1313
</Dependency>
1414
<Dependency Name="Microsoft.SourceBuild.Intermediate.msbuild" Version="17.7.0-preview-23217-02">

src/Compiler/Service/FSharpParseFileResults.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
170170
let result = SyntaxTraversal.Traverse(pos, input, visitor)
171171
result.IsSome
172172

173+
member _.IsTypeName(range: range) =
174+
let visitor =
175+
{ new SyntaxVisitorBase<_>() with
176+
member _.VisitModuleDecl(_, _, synModuleDecl) =
177+
match synModuleDecl with
178+
| SynModuleDecl.Types (typeDefns, _) ->
179+
typeDefns
180+
|> Seq.exists (fun (SynTypeDefn (typeInfo, _, _, _, _, _)) -> typeInfo.Range = range)
181+
|> Some
182+
| _ -> None
183+
}
184+
185+
let result = SyntaxTraversal.Traverse(range.Start, input, visitor)
186+
result |> Option.contains true
187+
173188
member _.TryRangeOfFunctionOrMethodBeingApplied pos =
174189
let rec getIdentRangeForFuncExprInApp traverseSynExpr expr pos =
175190
match expr with

src/Compiler/Service/FSharpParseFileResults.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type public FSharpParseFileResults =
3636
/// Determines if the given position is inside a function or method application.
3737
member IsPosContainedInApplication: pos: pos -> bool
3838

39+
/// Determines if the range points to a type name in the type definition.
40+
member IsTypeName: range: range -> bool
41+
3942
/// Attempts to find the range of a function or method that is being applied. Also accounts for functions in pipelines.
4043
member TryRangeOfFunctionOrMethodBeingApplied: pos: pos -> range option
4144

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp.
20802080
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position)
20812081
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position)
20822082
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position)
2083+
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range)
20832084
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeAnnotationGivenAtPosition(FSharp.Compiler.Text.Position)
20842085
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean ParseHadErrors
20852086
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean get_ParseHadErrors()

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp.
20802080
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position)
20812081
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position)
20822082
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position)
2083+
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range)
20832084
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeAnnotationGivenAtPosition(FSharp.Compiler.Text.Position)
20842085
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean ParseHadErrors
20852086
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean get_ParseHadErrors()

vsintegration/src/FSharp.Editor/CodeFixes/AddMissingEqualsToTypeDefinition.fs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,40 @@
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

5-
open System
65
open System.Composition
7-
open System.Threading.Tasks
86
open System.Collections.Immutable
97

108
open Microsoft.CodeAnalysis.Text
119
open Microsoft.CodeAnalysis.CodeFixes
1210

11+
open CancellableTasks
12+
1313
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.AddMissingEqualsToTypeDefinition); Shared>]
1414
type internal AddMissingEqualsToTypeDefinitionCodeFixProvider() =
1515
inherit CodeFixProvider()
1616

1717
static let title = SR.AddMissingEqualsToTypeDefinition()
18-
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3360")
19-
20-
override _.RegisterCodeFixesAsync context : Task =
21-
asyncMaybe {
2218

23-
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
19+
override _.FixableDiagnosticIds = ImmutableArray.Create "FS3360"
2420

25-
let mutable pos = context.Span.Start - 1
21+
override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this
2622

27-
// This won't ever actually happen, but eh why not
28-
do! Option.guard (pos > 0)
23+
interface IFSharpCodeFixProvider with
24+
member _.GetCodeFixIfAppliesAsync context =
25+
cancellableTask {
26+
let! range = context.GetErrorRangeAsync()
2927

30-
let mutable ch = sourceText.[pos]
28+
let! parseResults = context.Document.GetFSharpParseResultsAsync(nameof AddMissingEqualsToTypeDefinitionCodeFixProvider)
3129

32-
while pos > 0 && Char.IsWhiteSpace(ch) do
33-
pos <- pos - 1
34-
ch <- sourceText.[pos]
30+
if parseResults.IsTypeName range then
31+
return None
3532

36-
do
37-
context.RegisterFsharpFix(
38-
CodeFix.AddMissingEqualsToTypeDefinition,
39-
title,
40-
// 'pos + 1' is here because 'pos' is now the position of the first non-whitespace character.
41-
// Using just 'pos' will creat uncompilable code.
42-
[| TextChange(TextSpan(pos + 1, 0), " =") |]
43-
)
44-
}
45-
|> Async.Ignore
46-
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
33+
else
34+
return
35+
Some
36+
{
37+
Name = CodeFix.AddMissingEqualsToTypeDefinition
38+
Message = title
39+
Changes = [ TextChange(TextSpan(context.Span.Start, 0), "= ") ]
40+
}
41+
}

vsintegration/src/FSharp.Editor/CodeFixes/ChangePrefixNegationToInfixSubtraction.fs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,45 @@
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

5-
open System
65
open System.Composition
7-
open System.Threading.Tasks
86
open System.Collections.Immutable
7+
open System.Text.RegularExpressions
98

109
open Microsoft.CodeAnalysis.Text
1110
open Microsoft.CodeAnalysis.CodeFixes
1211

12+
open CancellableTasks
13+
1314
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.ChangePrefixNegationToInfixSubtraction); Shared>]
14-
type internal ChangePrefixNegationToInfixSubtractionodeFixProvider() =
15+
type internal ChangePrefixNegationToInfixSubtractionCodeFixProvider() =
1516
inherit CodeFixProvider()
1617

1718
static let title = SR.ChangePrefixNegationToInfixSubtraction()
1819

19-
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0003")
20-
21-
override _.RegisterCodeFixesAsync context : Task =
22-
asyncMaybe {
23-
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
24-
25-
let mutable pos = context.Span.End + 1
26-
27-
// This won't ever actually happen, but eh why not
28-
do! Option.guard (pos < sourceText.Length)
29-
30-
let mutable ch = sourceText.[pos]
31-
32-
while pos < sourceText.Length && Char.IsWhiteSpace(ch) do
33-
pos <- pos + 1
34-
ch <- sourceText.[pos]
35-
36-
// Bail if this isn't a negation
37-
do! Option.guard (ch = '-')
38-
do context.RegisterFsharpFix(CodeFix.ChangePrefixNegationToInfixSubtraction, title, [| TextChange(TextSpan(pos, 1), "- ") |])
39-
}
40-
|> Async.Ignore
41-
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
20+
override _.FixableDiagnosticIds = ImmutableArray.Create "FS0003"
21+
22+
override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this
23+
24+
interface IFSharpCodeFixProvider with
25+
member _.GetCodeFixIfAppliesAsync context =
26+
cancellableTask {
27+
let! sourceText = context.GetSourceTextAsync()
28+
29+
// in a line like "... x -1 ...",
30+
// squiggly goes for "x", not for "-", hence we search for "-"
31+
let remainingText = $"{sourceText.GetSubText(context.Span.End)}"
32+
let pattern = @"^\s+(-)"
33+
34+
match Regex.Match(remainingText, pattern) with
35+
| m when m.Success ->
36+
let spacePlace = context.Span.End + m.Groups[1].Index + 1
37+
38+
return
39+
Some
40+
{
41+
Name = CodeFix.ChangePrefixNegationToInfixSubtraction
42+
Message = title
43+
Changes = [ TextChange(TextSpan(spacePlace, 0), " ") ]
44+
}
45+
| _ -> return None
46+
}

vsintegration/src/FSharp.Editor/CodeFixes/ChangeRefCellDerefToNotExpression.fs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,38 @@
33
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System.Composition
6-
open System.Threading.Tasks
76
open System.Collections.Immutable
87

98
open Microsoft.CodeAnalysis.Text
109
open Microsoft.CodeAnalysis.CodeFixes
1110

11+
open CancellableTasks
12+
1213
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.ChangeRefCellDerefToNotExpression); Shared>]
1314
type internal ChangeRefCellDerefToNotExpressionCodeFixProvider [<ImportingConstructor>] () =
1415
inherit CodeFixProvider()
1516

1617
static let title = SR.UseNotForNegation()
1718

18-
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0001")
19-
20-
override this.RegisterCodeFixesAsync context : Task =
21-
asyncMaybe {
22-
let document = context.Document
23-
24-
let! parseResults =
25-
document.GetFSharpParseResultsAsync(nameof (ChangeRefCellDerefToNotExpressionCodeFixProvider))
26-
|> liftAsync
19+
override _.FixableDiagnosticIds = ImmutableArray.Create "FS0001"
2720

28-
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
21+
override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this
2922

30-
let errorRange =
31-
RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText)
23+
interface IFSharpCodeFixProvider with
24+
member _.GetCodeFixIfAppliesAsync context =
25+
cancellableTask {
26+
let! parseResults = context.Document.GetFSharpParseResultsAsync(nameof ChangeRefCellDerefToNotExpressionCodeFixProvider)
3227

33-
let! derefRange = parseResults.TryRangeOfRefCellDereferenceContainingPos errorRange.Start
34-
let! derefSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, derefRange)
28+
let! sourceText = context.GetSourceTextAsync()
29+
let! errorRange = context.GetErrorRangeAsync()
3530

36-
do context.RegisterFsharpFix(CodeFix.ChangeRefCellDerefToNotExpression, title, [| TextChange(derefSpan, "not ") |])
37-
}
38-
|> Async.Ignore
39-
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
31+
return
32+
parseResults.TryRangeOfRefCellDereferenceContainingPos errorRange.Start
33+
|> Option.bind (fun range -> RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, range))
34+
|> Option.map (fun span ->
35+
{
36+
Name = CodeFix.ChangeRefCellDerefToNotExpression
37+
Message = title
38+
Changes = [ TextChange(span, "not ") ]
39+
})
40+
}

vsintegration/src/FSharp.Editor/CodeFixes/ConvertToNotEqualsEqualityExpression.fs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,36 @@
33
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System.Composition
6-
open System.Threading.Tasks
76
open System.Collections.Immutable
87

98
open Microsoft.CodeAnalysis.Text
109
open Microsoft.CodeAnalysis.CodeFixes
1110

11+
open CancellableTasks
12+
1213
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.ConvertToNotEqualsEqualityExpression); Shared>]
1314
type internal ConvertToNotEqualsEqualityExpressionCodeFixProvider() =
1415
inherit CodeFixProvider()
1516

1617
static let title = SR.ConvertToNotEqualsEqualityExpression()
1718

18-
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0043")
19-
20-
override this.RegisterCodeFixesAsync context : Task =
21-
asyncMaybe {
22-
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
23-
let text = sourceText.GetSubText(context.Span).ToString()
24-
25-
// We're converting '!=' into '<>', a common new user mistake.
26-
// If this is an FS00043 that is anything other than that, bail out
27-
do! Option.guard (text = "!=")
28-
do context.RegisterFsharpFix(CodeFix.ConvertToNotEqualsEqualityExpression, title, [| TextChange(context.Span, "<>") |])
29-
}
30-
|> Async.Ignore
31-
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
19+
override _.FixableDiagnosticIds = ImmutableArray.Create "FS0043"
20+
21+
override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this
22+
23+
interface IFSharpCodeFixProvider with
24+
member _.GetCodeFixIfAppliesAsync context =
25+
cancellableTask {
26+
let! text = context.GetSquigglyTextAsync()
27+
28+
if text <> "!=" then
29+
return None
30+
else
31+
return
32+
Some
33+
{
34+
Name = CodeFix.ConvertToNotEqualsEqualityExpression
35+
Message = title
36+
Changes = [ TextChange(context.Span, "<>") ]
37+
}
38+
}

0 commit comments

Comments
 (0)