Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Replace FSComp invocations in VS tooling with an FCS API
  • Loading branch information
cartermp committed May 30, 2019
commit a9b4dd17113557f0d4f87d6153441c3e7fb73fb1
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@
<Compile Include="..\service\Reactor.fs">
<Link>Service/Reactor.fs</Link>
</Compile>
<Compile Include="..\service\ServiceCompilerDiagnostics.fsi">
<Link>Service/ServiceCompilerDiagnostics.fsi</Link>
</Compile>
<Compile Include="..\service\ServiceCompilerDiagnostics.fs">
<Link>Service/ServiceCompilerDiagnostics.fs</Link>
</Compile>
<Compile Include="..\service\ServiceConstants.fs">
<Link>Service/ServiceConstants.fs</Link>
</Compile>
Expand Down
14 changes: 14 additions & 0 deletions src/fsharp/service/ServiceCompilerDiagnostics.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.SourceCodeServices

type DiagnosticKind =
| AddIndexerDot
| ReplaceWithSuggestion of suggestion:string

[<RequireQualifiedAccess>]
module CompilerDiagnostics =
let getErrorMessage diagnosticKind =
match diagnosticKind with
| AddIndexerDot -> FSComp.SR.addIndexerDot()
| ReplaceWithSuggestion s -> FSComp.SR.replaceWithSuggestion(s)
13 changes: 13 additions & 0 deletions src/fsharp/service/ServiceCompilerDiagnostics.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.SourceCodeServices

/// Supported kinds of diagnostics by this service.
type DiagnosticKind =
Copy link
Contributor

Choose a reason for hiding this comment

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

@cartermp,
Are there other scenarios, where a developer wants to get a string from the compiler.private dll? or are they all diagnostic? Should the Api be named more generaly. Or will the non diagnostic scenarios, expose new modules?

Thanks

kevin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I imagine I'd have a new ServiceFoo file that services up the Foo stuff from the compiler of the need arises.

| AddIndexerDot
| ReplaceWithSuggestion of suggestion:string

/// Exposes compiler diagnostic error messages.
module CompilerDiagnostics =
/// Given a DiagnosticKind, returns the string representing the error message for that diagnostic.
val getErrorMessage: diagnosticKind: DiagnosticKind -> string
6 changes: 2 additions & 4 deletions vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Composition
open System.Collections.Immutable
open System.Threading.Tasks

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open SymbolHelpers
open FSharp.Compiler.SourceCodeServices

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System.Composition
open System.Threading.Tasks
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
open FSharp.Compiler.SourceCodeServices

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ProposeUpperCaseLabel"); Shared>]
type internal FSharpProposeUpperCaseLabelCodeFixProvider
Expand All @@ -24,7 +25,7 @@ type internal FSharpProposeUpperCaseLabelCodeFixProvider
asyncMaybe {
let textChanger (originalText: string) = originalText.[0].ToString().ToUpper() + originalText.Substring(1)
let! solutionChanger, originalText = SymbolHelpers.changeAllSymbolReferences(context.Document, context.Span, textChanger, projectInfoManager, checkerProvider.Checker, userOpName)
let title = FSComp.SR.replaceWithSuggestion (textChanger originalText)
let title = CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion <| textChanger originalText)
context.RegisterCodeFix(
CodeAction.Create(title, solutionChanger, title),
context.Diagnostics |> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id) |> Seq.toImmutableArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open System.Composition
open System.Threading
open System.Threading.Tasks

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Diagnostics
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Collections.Immutable
open System.Composition
open System.Threading.Tasks

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes

open FSharp.Compiler
open FSharp.Compiler.SourceCodeServices
open Microsoft.VisualStudio.FSharp.Editor.SymbolHelpers
open FSharp.Compiler.SourceCodeServices.Keywords
Expand Down Expand Up @@ -57,7 +54,7 @@ type internal FSharpRenameParamToMatchSignature
yield TextChange(textSpan, replacement) |]
return changes
}
let title = FSComp.SR.replaceWithSuggestion suggestion
let title = CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion suggestion)
let codefix = CodeFixHelpers.createTextChangeCodeFix(title, context, computeChanges)
context.RegisterCodeFix(codefix, diagnostics)
| _ -> ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type internal FSharpReplaceWithSuggestionCodeFixProvider

for suggestion in suggestions do
let replacement = Keywords.QuoteIdentifierIfNeeded suggestion
let codeFix =
let codeFix =
CodeFixHelpers.createTextChangeCodeFix(
FSComp.SR.replaceWithSuggestion suggestion,
CompilerDiagnostics.getErrorMessage (ReplaceWithSuggestion suggestion),
context,
(fun () -> asyncMaybe.Return [| TextChange(context.Span, replacement) |]))

Expand Down