Skip to content

Commit b573128

Browse files
author
Omar Tawfik
committed
Added Document/Project analyzers
1 parent a4e411f commit b573128

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespace Microsoft.VisualStudio.FSharp.Editor
4+
5+
open System
6+
open System.Composition
7+
open System.Collections.Immutable
8+
open System.Threading
9+
open System.Threading.Tasks
10+
11+
open Microsoft.CodeAnalysis
12+
open Microsoft.CodeAnalysis.Diagnostics
13+
open Microsoft.CodeAnalysis.Host.Mef
14+
open Microsoft.CodeAnalysis.Text
15+
open Microsoft.CodeAnalysis.SolutionCrawler
16+
17+
open Microsoft.FSharp.Compiler
18+
open Microsoft.FSharp.Compiler.SourceCodeServices
19+
20+
open Microsoft.VisualStudio.FSharp.LanguageService
21+
22+
[<DiagnosticAnalyzer(FSharpCommonConstants.FSharpLanguageName)>]
23+
type internal FSharpDocumentDiagnosticAnalyzer() =
24+
inherit DocumentDiagnosticAnalyzer()
25+
26+
override this.SupportedDiagnostics with get() = ImmutableArray<DiagnosticDescriptor>.Empty
27+
28+
override this.AnalyzeSyntaxAsync(document: Document, addDiagnostic: Action<Diagnostic>, cancellationToken: CancellationToken): Task =
29+
let computation = async {
30+
let! sourceText = document.GetTextAsync(cancellationToken) |> Async.AwaitTask
31+
let options = CommonRoslynHelpers.GetFSharpProjectOptionsForRoslynProject(document.Project)
32+
let! parseResults = FSharpChecker.Instance.ParseFileInProject(document.Name, sourceText.ToString(), options)
33+
34+
parseResults.Errors |> Seq.iter(fun (error) -> printf "%A" error) |> ignore
35+
36+
return List<Diagnostic>.Empty
37+
}
38+
39+
let action() = computation |> Async.RunSynchronously |> Seq.iter(fun diagnostic -> addDiagnostic.Invoke(diagnostic))
40+
Task.Run(action, cancellationToken)
41+
42+
override this.AnalyzeSemanticsAsync(_: Document, _: Action<Diagnostic>, _: CancellationToken): Task =
43+
Task.CompletedTask

vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@
3131
<ItemGroup>
3232
<Compile Include="AssemblyInfo.fs" />
3333
<Compile Include="ColorizationService.fs">
34-
<Link>Classification\ColorizationService.fs</Link>
34+
<Link>Classification\ColorizationService.fs</Link>
3535
</Compile>
3636
<Compile Include="BraceMatchingService.fs">
37-
<Link>Utilities\BraceMatchingService.fs</Link>
37+
<Link>Utilities\BraceMatchingService.fs</Link>
3838
</Compile>
3939
<Compile Include="IndentationService.fs">
40-
<Link>Utilities\IndentationService.fs</Link>
40+
<Link>Utilities\IndentationService.fs</Link>
4141
</Compile>
4242
<Compile Include="BreakpointResolutionService.fs">
43-
<Link>Debugging\BreakpointResolutionService.fs</Link>
43+
<Link>Debugging\BreakpointResolutionService.fs</Link>
4444
</Compile>
4545
<Compile Include="LanguageDebugInfoService.fs">
46-
<Link>Debugging\LanguageDebugInfoService.fs</Link>
46+
<Link>Debugging\LanguageDebugInfoService.fs</Link>
47+
</Compile>
48+
<Compile Include="DocumentDiagnosticAnalyzer.fs">
49+
<Link>Diagnostics\DocumentDiagnosticAnalyzer.fs</Link>
4750
</Compile>
4851
<Compile Include="ProjectSiteService.fs" />
4952
<Compile Include="ContentType.fs" />

vsintegration/src/FSharp.LanguageService/FSharp.LanguageService.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0.dll" />
8787
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0.dll" />
8888
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0.dll" />
89+
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0.dll" />
8990
<Reference Include="Microsoft.VisualStudio.Shell.Interop.dll" />
9091
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0.dll" />
9192
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.11.0.dll" />

vsintegration/src/FSharp.LanguageService/ProjectSite.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type internal FSharpProjectSite(hierarchy: IVsHierarchy, serviceProvider: System
5959
| (VSConstants.S_OK, id) -> id
6060
| _ -> uint32 VSConstants.VSITEMID.Nil
6161

62-
let document = this.ProjectTracker.DocumentProvider.TryGetDocumentForFile(this, itemid, file, SourceCodeKind.Regular, fun x -> true)
62+
let document = this.ProjectTracker.DocumentProvider.TryGetDocumentForFile(this, itemid, file, SourceCodeKind.Regular, false, fun x -> true)
6363
this.AddDocument(document, true)
6464

6565
member internal this.OnProjectSettingsChanged(hier: IVsHierarchy, site : IProjectSite) =

0 commit comments

Comments
 (0)