Skip to content
Closed
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
Added shims over document diagnostic analyzers
  • Loading branch information
TIHan committed May 7, 2019
commit 8a39f54709de1426122d03c36e537f86826f922b
2 changes: 1 addition & 1 deletion RoslynPackageVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0-beta3-19222-02
3.2.0
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
https://vside.myget.org/F/vs-impl/api/v3/index.json;
https://myget.org/F/roslyn_concord/api/v3/index.json;
https://vside.myget.org/F/devcore/api/v3/index.json;
C:\roslyn\artifacts\packages\Debug\Release;
</RestoreSources>
<!-- version numbers from files -->
<RoslynPackageVersion>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)..\RoslynPackageVersion.txt').Trim())</RoslynPackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion vsintegration/src/FSharp.Editor/Common/ContentType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor
module FSharpStaticTypeDefinitions =
[<Export>]
[<Name(FSharpConstants.FSharpContentTypeName)>]
[<BaseDefinition(ContentTypeNames.RoslynContentType)>]
[<BaseDefinition(FSharpContentTypeNames.RoslynContentType)>]
let FSharpContentTypeDefinition = ContentTypeDefinition()

[<Export>]
Expand Down
8 changes: 0 additions & 8 deletions vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ module internal RoslynHelpers =
let StartAsyncUnitAsTask cancellationToken (computation:Async<unit>) =
StartAsyncAsTask cancellationToken computation :> Task

let private TheSupportedDiagnostics =
// We are constructing our own descriptors at run-time. Compiler service is already doing error formatting and localization.
let dummyDescriptors =
[| for i in 0 .. 10000 -> DiagnosticDescriptor(sprintf "FS%04d" i, String.Empty, String.Empty, String.Empty, DiagnosticSeverity.Error, true, null, null) |]
ImmutableArray.Create<DiagnosticDescriptor>(dummyDescriptors)

let SupportedDiagnostics() = TheSupportedDiagnostics

let ConvertError(error: FSharpErrorInfo, location: Location) =
// Normalize the error message into the same format that we will receive it from the compiler.
// This ensures that IntelliSense and Compiler errors in the 'Error List' are de-duplicated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Composition
open System.Collections.Immutable
open System.Collections.Generic
open System.Threading
Expand All @@ -11,6 +12,7 @@ open System.Threading.Tasks
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Diagnostics
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

open FSharp.Compiler
Expand All @@ -22,9 +24,9 @@ type internal DiagnosticsType =
| Syntax
| Semantic

[<DiagnosticAnalyzer(FSharpConstants.FSharpLanguageName)>]
[<Shared>]
[<ExportLanguageService(typeof<IFSharpDocumentDiagnosticAnalyzer>, FSharpConstants.FSharpLanguageName)>]
type internal FSharpDocumentDiagnosticAnalyzer() =
inherit DocumentDiagnosticAnalyzer()

static let userOpName = "DocumentDiagnosticAnalyzer"
let getChecker(document: Document) =
Expand Down Expand Up @@ -106,40 +108,33 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
return results
}

override __.Priority = 10 // Default = 50
interface IFSharpDocumentDiagnosticAnalyzer with

override this.SupportedDiagnostics = RoslynHelpers.SupportedDiagnostics()

override this.AnalyzeSyntaxAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
return!
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Syntax)
|> liftAsync
}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
|> RoslynHelpers.StartAsyncAsTask cancellationToken

override this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! parsingOptions, _, projectOptions = projectInfoManager.TryGetOptionsForDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
if document.Project.Name <> FSharpConstants.FSharpMiscellaneousFilesName || isScriptFile document.FilePath then
member this.AnalyzeSyntaxAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
return!
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Semantic)
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Syntax)
|> liftAsync
else
return ImmutableArray<Diagnostic>.Empty
}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
|> RoslynHelpers.StartAsyncAsTask cancellationToken

interface IBuiltInAnalyzer with
member __.GetAnalyzerCategory() : DiagnosticAnalyzerCategory = DiagnosticAnalyzerCategory.SemanticDocumentAnalysis
member __.OpenFileOnly _ = true

}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
|> RoslynHelpers.StartAsyncAsTask cancellationToken

member this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! parsingOptions, _, projectOptions = projectInfoManager.TryGetOptionsForDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
if document.Project.Name <> FSharpConstants.FSharpMiscellaneousFilesName || isScriptFile document.FilePath then
return!
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Semantic)
|> liftAsync
else
return ImmutableArray<Diagnostic>.Empty
}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
|> RoslynHelpers.StartAsyncAsTask cancellationToken
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ open Microsoft.CodeAnalysis.Diagnostics
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.SolutionCrawler
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

open FSharp.Compiler
open FSharp.Compiler.SourceCodeServices
Expand All @@ -24,9 +25,9 @@ open FSharp.Compiler.Range
// saves to the file system. This is different to the versions of the files active in the editor. This results in out-of-sync error
// messages while files are being edited

[<DiagnosticAnalyzer(FSharpCommonConstants.FSharpLanguageName)>]
[<Shared>]
[<ExportLanguageService(typeof<IFSharpProjectDiagnosticAnalyzer>, FSharpConstants.FSharpLanguageName)>]
type internal FSharpProjectDiagnosticAnalyzer() =
inherit ProjectDiagnosticAnalyzer()

static member GetDiagnostics(options: FSharpProjectOptions) = async {
let! checkProjectResults = FSharpLanguageService.Checker.ParseAndCheckProject(options)
Expand All @@ -42,13 +43,13 @@ type internal FSharpProjectDiagnosticAnalyzer() =
|> Seq.toImmutableArray
return results
}
override this.SupportedDiagnostics = CommonRoslynHelpers.SupportedDiagnostics()

override this.AnalyzeProjectAsync(project: Project, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
async {
match FSharpLanguageService.GetOptionsForProject(project.Id) with
| Some options -> return! FSharpProjectDiagnosticAnalyzer.GetDiagnostics(options)
| None -> return ImmutableArray<Diagnostic>.Empty
} |> CommonRoslynHelpers.StartAsyncAsTask cancellationToken

interface IFSharpProjectDiagnosticAnalyzer with

member this.AnalyzeProjectAsync(project: Project, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
async {
match FSharpLanguageService.GetOptionsForProject(project.Id) with
| Some options -> return! FSharpProjectDiagnosticAnalyzer.GetDiagnostics(options)
| None -> return ImmutableArray<Diagnostic>.Empty
} |> CommonRoslynHelpers.StartAsyncAsTask cancellationToken
#endif
Loading