Skip to content

Commit 4e69865

Browse files
author
Omar Tawfik
committed
Fix random bugs
1 parent fb6b6f7 commit 4e69865

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

vsintegration/src/FSharp.Editor/DocumentDiagnosticAnalyzer.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
3131
let severity = if error.Severity = FSharpErrorSeverity.Error then DiagnosticSeverity.Error else DiagnosticSeverity.Warning
3232
let descriptor = new DiagnosticDescriptor(id, emptyString, description, error.Subcategory, severity, true, emptyString, String.Empty, null)
3333

34-
let linePositionSpan = LinePositionSpan(LinePosition(error.StartLineAlternate - 1, error.StartColumn), LinePosition(error.EndLineAlternate - 1, error.EndColumn))
34+
// F# compiler report errors at start/end of file if parsing fails. It should be corrected to match Roslyn boundaries
35+
let linePositionSpan = LinePositionSpan(
36+
LinePosition(Math.Max(0, error.StartLineAlternate - 1), error.StartColumn),
37+
LinePosition(Math.Max(0, error.EndLineAlternate - 1), error.EndColumn))
3538
let textSpan = sourceText.Lines.GetTextSpan(linePositionSpan)
36-
37-
// F# compiler report errors at end of file if parsing fails. It should be corrected to match Roslyn boundaries
3839
let correctedTextSpan = if textSpan.End < sourceText.Length then textSpan else TextSpan.FromBounds(sourceText.Length - 1, sourceText.Length)
3940

4041
Diagnostic.Create(descriptor, Location.Create(filePath, correctedTextSpan , linePositionSpan))

vsintegration/src/FSharp.Editor/LanguageService.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ type internal FSharpLanguageService(package : FSharpPackage) =
4040
else
4141
None
4242

43-
member this.SyncProject(projectContext: IWorkspaceProjectContext, site: IProjectSite) =
43+
member this.SyncProject(project: AbstractProject, projectContext: IWorkspaceProjectContext, site: IProjectSite) =
4444
let updatedFiles = site.SourceFilesOnDisk()
45-
let workspaceFiles = (projectContext :?> AbstractProject).GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath)
45+
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath)
4646

4747
for file in updatedFiles do if not(workspaceFiles.Contains(file)) then projectContext.AddSourceFile(file)
4848
for file in workspaceFiles do if not(updatedFiles.Contains(file)) then projectContext.RemoveSourceFile(file)
@@ -82,8 +82,11 @@ type internal FSharpLanguageService(package : FSharpPackage) =
8282
let outputPath = if Path.IsPathRooted(outputFlag) then outputFlag else Path.Combine(Path.GetDirectoryName(projectFileName), outputFlag)
8383

8484
let projectContext = projectContextFactory.CreateProjectContext(FSharpCommonConstants.FSharpLanguageName, projectFileName, projectFileName, projectGuid, hier, outputPath, errorReporter)
85-
this.SyncProject(projectContext, site)
86-
site.AdviseProjectSiteChanges(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> this.SyncProject(projectContext, site)))
85+
let project = projectContext :?> AbstractProject
86+
87+
this.SyncProject(project, projectContext, site)
88+
site.AdviseProjectSiteChanges(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> this.SyncProject(project, projectContext, site)))
89+
site.AdviseProjectSiteClosed(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> project.Disconnect()))
8790
| _ -> ()
8891
| _ -> ()
8992

0 commit comments

Comments
 (0)