Skip to content

Commit 9b1287c

Browse files
cartermpKevinRansom
authored andcommitted
Replace FSComp invocations in VS tooling with an FCS API (#6904)
1 parent 4702abb commit 9b1287c

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@
575575
<Compile Include="..\service\IncrementalBuild.fs">
576576
<Link>Service/IncrementalBuild.fs</Link>
577577
</Compile>
578+
<Compile Include="..\service\ServiceCompilerDiagnostics.fsi">
579+
<Link>Service/ServiceCompilerDiagnostics.fsi</Link>
580+
</Compile>
581+
<Compile Include="..\service\ServiceCompilerDiagnostics.fs">
582+
<Link>Service/ServiceCompilerDiagnostics.fs</Link>
583+
</Compile>
578584
<Compile Include="..\service\ServiceConstants.fs">
579585
<Link>Service/ServiceConstants.fs</Link>
580586
</Compile>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.SourceCodeServices
4+
5+
type DiagnosticKind =
6+
| AddIndexerDot
7+
| ReplaceWithSuggestion of suggestion:string
8+
9+
[<RequireQualifiedAccess>]
10+
module CompilerDiagnostics =
11+
let getErrorMessage diagnosticKind =
12+
match diagnosticKind with
13+
| AddIndexerDot -> FSComp.SR.addIndexerDot()
14+
| ReplaceWithSuggestion s -> FSComp.SR.replaceWithSuggestion(s)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.SourceCodeServices
4+
5+
/// Supported kinds of diagnostics by this service.
6+
type DiagnosticKind =
7+
| AddIndexerDot
8+
| ReplaceWithSuggestion of suggestion:string
9+
10+
/// Exposes compiler diagnostic error messages.
11+
module CompilerDiagnostics =
12+
/// Given a DiagnosticKind, returns the string representing the error message for that diagnostic.
13+
val getErrorMessage: diagnosticKind: DiagnosticKind -> string

vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

5-
open System
65
open System.Composition
76
open System.Collections.Immutable
87
open System.Threading.Tasks
98

10-
open Microsoft.CodeAnalysis
119
open Microsoft.CodeAnalysis.Text
1210
open Microsoft.CodeAnalysis.CodeFixes
13-
open SymbolHelpers
11+
open FSharp.Compiler.SourceCodeServices
1412

1513
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "FixIndexerAccess"); Shared>]
1614
type internal FSharpFixIndexerAccessCodeFixProvider() =
@@ -50,7 +48,7 @@ type internal FSharpFixIndexerAccessCodeFixProvider() =
5048

5149
let codefix =
5250
CodeFixHelpers.createTextChangeCodeFix(
53-
FSComp.SR.addIndexerDot(),
51+
CompilerDiagnostics.getErrorMessage AddIndexerDot,
5452
context,
5553
(fun () -> asyncMaybe.Return [| TextChange(span, replacement.TrimEnd() + ".") |]))
5654

vsintegration/src/FSharp.Editor/CodeFix/ProposeUppercaseLabel.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open System.Composition
66
open System.Threading.Tasks
77
open Microsoft.CodeAnalysis.CodeFixes
88
open Microsoft.CodeAnalysis.CodeActions
9+
open FSharp.Compiler.SourceCodeServices
910

1011
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ProposeUpperCaseLabel"); Shared>]
1112
type internal FSharpProposeUpperCaseLabelCodeFixProvider
@@ -24,7 +25,7 @@ type internal FSharpProposeUpperCaseLabelCodeFixProvider
2425
asyncMaybe {
2526
let textChanger (originalText: string) = originalText.[0].ToString().ToUpper() + originalText.Substring(1)
2627
let! solutionChanger, originalText = SymbolHelpers.changeAllSymbolReferences(context.Document, context.Span, textChanger, projectInfoManager, checkerProvider.Checker, userOpName)
27-
let title = FSComp.SR.replaceWithSuggestion (textChanger originalText)
28+
let title = CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion <| textChanger originalText)
2829
context.RegisterCodeFix(
2930
CodeAction.Create(title, solutionChanger, title),
3031
context.Diagnostics |> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id) |> Seq.toImmutableArray)

vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedOpens.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ open System.Composition
66
open System.Threading
77
open System.Threading.Tasks
88

9-
open Microsoft.CodeAnalysis
109
open Microsoft.CodeAnalysis.Diagnostics
1110
open Microsoft.CodeAnalysis.Text
1211
open Microsoft.CodeAnalysis.CodeFixes

vsintegration/src/FSharp.Editor/CodeFix/RenameParamToMatchSignature.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

5-
open System
65
open System.Collections.Immutable
76
open System.Composition
87
open System.Threading.Tasks
98

10-
open Microsoft.CodeAnalysis
119
open Microsoft.CodeAnalysis.Text
1210
open Microsoft.CodeAnalysis.CodeFixes
1311

14-
open FSharp.Compiler
1512
open FSharp.Compiler.SourceCodeServices
1613
open Microsoft.VisualStudio.FSharp.Editor.SymbolHelpers
1714
open FSharp.Compiler.SourceCodeServices.Keywords
@@ -57,7 +54,7 @@ type internal FSharpRenameParamToMatchSignature
5754
yield TextChange(textSpan, replacement) |]
5855
return changes
5956
}
60-
let title = FSComp.SR.replaceWithSuggestion suggestion
57+
let title = CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion suggestion)
6158
let codefix = CodeFixHelpers.createTextChangeCodeFix(title, context, computeChanges)
6259
context.RegisterCodeFix(codefix, diagnostics)
6360
| _ -> ()

vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ type internal FSharpReplaceWithSuggestionCodeFixProvider
5959

6060
for suggestion in suggestions do
6161
let replacement = Keywords.QuoteIdentifierIfNeeded suggestion
62-
let codeFix =
62+
let codeFix =
6363
CodeFixHelpers.createTextChangeCodeFix(
64-
FSComp.SR.replaceWithSuggestion suggestion,
64+
CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion suggestion),
6565
context,
6666
(fun () -> asyncMaybe.Return [| TextChange(context.Span, replacement) |]))
6767

0 commit comments

Comments
 (0)