From 84ff2d5b8ea22469f771192d37b30c636c67d024 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 22 Feb 2024 09:39:50 +0100 Subject: [PATCH] Buildable solution --- ReSharper.FSharp/Directory.Build.props | 4 ++-- ReSharper.FSharp/TypeProviders.Host.targets | 2 +- .../FSharp.TypeProviders.Host.csproj | 1 - .../src/Checker/FcsCheckerService.fs | 5 +++-- .../src/Checker/FcsProjectProvider.fs | 4 ++-- .../src/Stages/ScriptLoadPathsStage.fs | 4 +++- .../src/Search/FSharpPathReference.fs | 8 +++++--- .../FSharp.Tests.Host/FSharpTestHost.fs | 12 ++++++----- .../src/FSharp.Tests.Common/src/Common.fs | 20 ++++++++++--------- 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/ReSharper.FSharp/Directory.Build.props b/ReSharper.FSharp/Directory.Build.props index d3485b9485..17598c2dfd 100644 --- a/ReSharper.FSharp/Directory.Build.props +++ b/ReSharper.FSharp/Directory.Build.props @@ -33,8 +33,8 @@ $(Subplatform).Psi.Features_test_Framework.Props $(Subplatform).Rider_RdBackend.Common.Props $(Subplatform).Rider_Rider.Backend.Props - true - $(MSBuildThisFileDirectory)../../fsharp/src/Compiler/FSharp.Compiler.Service.fsproj + true + $(MSBuildThisFileDirectory)../../fsharp/src/Compiler/FSharp.Compiler.Service.fsproj diff --git a/ReSharper.FSharp/TypeProviders.Host.targets b/ReSharper.FSharp/TypeProviders.Host.targets index 0ab3216525..b5db342ab0 100644 --- a/ReSharper.FSharp/TypeProviders.Host.targets +++ b/ReSharper.FSharp/TypeProviders.Host.targets @@ -14,7 +14,7 @@ - + diff --git a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host.csproj b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host.csproj index 400ee2cd7b..fe58864288 100644 --- a/ReSharper.FSharp/src/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host.csproj +++ b/ReSharper.FSharp/src/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host/FSharp.TypeProviders.Host.csproj @@ -26,7 +26,6 @@ - diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsCheckerService.fs b/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsCheckerService.fs index 358b51ae98..0742b1c263 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsCheckerService.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsCheckerService.fs @@ -201,7 +201,7 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif new PinTypeCheckResultsCookie(sourceFile, parseAndCheckResults.ParseResults, parseAndCheckResults.CheckResults, prohibitTypeCheck) :> IDisposable | _ -> { new IDisposable with member this.Dispose() = () } - member x.TryGetStaleCheckResults([] file: IPsiSourceFile, opName) = + member x.TryGetStaleCheckResults([] file: IPsiSourceFile, opName) : FSharpCheckFileResults option = match x.FcsProjectProvider.GetProjectSnapshot(file) with | None -> None | Some snapshot -> @@ -210,7 +210,8 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif logger.Trace("TryGetStaleCheckResults: start {0}, {1}", path, opName) // TODO: TryGetRecentCheckResultsForFile for Snapshot - Unchecked.defaultof + // https://github.com/dotnet/fsharp/pull/16720 + None // match x.Checker.TryGetRecentCheckResultsForFile(path, snapshot) with // | Some (_, checkResults, _) -> // logger.Trace("TryGetStaleCheckResults: finish {0}, {1}", path, opName) diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsProjectProvider.fs b/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsProjectProvider.fs index f1bfc1c0ec..7a11477221 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsProjectProvider.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsProjectProvider.fs @@ -510,7 +510,7 @@ type FcsProjectProvider(lifetime: Lifetime, solution: ISolution, changeManager: dirtyProjects.Clear() interface IFcsProjectProvider with - member x.GetProjectOptions(sourceFile: IPsiSourceFile) = + member x.GetProjectSnapshot(sourceFile: IPsiSourceFile) = locks.AssertReadAccessAllowed() processInvalidatedFcsProjects () @@ -531,7 +531,7 @@ type FcsProjectProvider(lifetime: Lifetime, solution: ISolution, changeManager: | Some fcsProject when fcsProject.IsKnownFile(sourceFile) -> Some fcsProject.ProjectSnapshot | _ -> None - member x.GetProjectOptions(psiModule: IPsiModule) = + member x.GetProjectSnapshot(psiModule: IPsiModule) = locks.AssertReadAccessAllowed() processInvalidatedFcsProjects () diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/ScriptLoadPathsStage.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/ScriptLoadPathsStage.fs index 14ebb0c84b..807a695e49 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/ScriptLoadPathsStage.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/ScriptLoadPathsStage.fs @@ -1,5 +1,7 @@ namespace rec JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Stages +#nowarn "57" + open System.Collections.Generic open JetBrains.Application open JetBrains.ReSharper.Daemon.Stages @@ -51,7 +53,7 @@ type ScriptLoadPathsStageProcess(fsFile, daemonProcess) = fsFile.Accept(visitor) if allDirectives.IsEmpty() then () else - match fsFile.CheckerService.FcsProjectProvider.GetProjectOptions(daemonProcess.SourceFile) with + match fsFile.CheckerService.FcsProjectProvider.GetProjectSnapshot(daemonProcess.SourceFile) with | Some options when not options.OriginalLoadReferences.IsEmpty -> let document = daemonProcess.Document let linesCount = document.GetLineCount() |> int diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Features/src/Search/FSharpPathReference.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Features/src/Search/FSharpPathReference.fs index 0dcad8d42c..c94321177d 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Features/src/Search/FSharpPathReference.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Features/src/Search/FSharpPathReference.fs @@ -1,5 +1,7 @@ namespace rec JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Searching +#nowarn "57" + open JetBrains.DataFlow open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree open JetBrains.ReSharper.Plugins.FSharp.Util @@ -48,9 +50,9 @@ type FSharpPathReference(owner, sourceFile) = let fsFile = owner.GetContainingFile() :?> IFSharpFile let document = sourceFile.Document let tokenStartOffset = owner.Parent.GetTreeStartOffset() - fsFile.CheckerService.FcsProjectProvider.GetProjectOptions(sourceFile) - |> Option.bind (fun options -> - options.OriginalLoadReferences + fsFile.CheckerService.FcsProjectProvider.GetProjectSnapshot(sourceFile) + |> Option.bind (fun snapshot -> + snapshot.OriginalLoadReferences |> List.tryFind (fun (range, _, _) -> getTreeStartOffset document range = tokenStartOffset) |> Option.bind (fun (_, _, path) -> let path = VirtualFileSystemPath.TryParse(path, InteractionContext.SolutionContext) diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Tests.Host/FSharpTestHost.fs b/ReSharper.FSharp/src/FSharp/FSharp.Tests.Host/FSharpTestHost.fs index c6873e8e55..dd2e9eebd2 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Tests.Host/FSharpTestHost.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Tests.Host/FSharpTestHost.fs @@ -1,5 +1,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Tests.Host +#nowarn "57" + open System.Collections.Generic open System.Globalization open System.Linq @@ -55,10 +57,10 @@ type FSharpTestHost(solution: ISolution, sourceCache: FSharpSourceCache, itemsCo projectProvider.GetProjectSnapshot(sourceFile) |> Option.map (fun options -> options.OtherOptions - |> Array.choose (fun o -> if o.StartsWith("-r:") then Some (o.Substring("-r:".Length)) else None) - |> Array.map (fun p -> VirtualFileSystemPath.TryParse(p, InteractionContext.SolutionContext)) - |> Array.filter (fun p -> not p.IsEmpty && directory.IsPrefixOf(p)) - |> Array.map (fun p -> p.Name) + |> List.choose (fun o -> if o.StartsWith("-r:") then Some (o.Substring("-r:".Length)) else None) + |> List.map (fun p -> VirtualFileSystemPath.TryParse(p, InteractionContext.SolutionContext)) + |> List.filter (fun p -> not p.IsEmpty && directory.IsPrefixOf(p)) + |> List.map (fun p -> p.Name) |> List) |> Option.defaultWith (fun _ -> List()) @@ -76,7 +78,7 @@ type FSharpTestHost(solution: ISolution, sourceCache: FSharpSourceCache, itemsCo let dumpFcsProjectReferences (projectModelId: int) = let projectOptions = getProjectOptions projectModelId projectOptions.ReferencedProjects - |> Array.map (fun project -> + |> List.map (fun project -> let outputPath = VirtualFileSystemPath.Parse(project.OutputFile, InteractionContext.SolutionContext) outputPath.NameWithoutExtension) |> List diff --git a/ReSharper.FSharp/test/src/FSharp.Tests.Common/src/Common.fs b/ReSharper.FSharp/test/src/FSharp.Tests.Common/src/Common.fs index e3a81d27fd..7163d4094b 100644 --- a/ReSharper.FSharp/test/src/FSharp.Tests.Common/src/Common.fs +++ b/ReSharper.FSharp/test/src/FSharp.Tests.Common/src/Common.fs @@ -1,5 +1,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Tests +#nowarn "57" + open System open System.Collections.Generic open System.IO @@ -236,11 +238,11 @@ type TestFcsProjectProvider(lifetime: Lifetime, checkerService: FcsCheckerServic // todo: referenced projects // todo: unify with FcsProjectProvider check let areSameForChecking (newProject: FcsProject) (oldProject: FcsProject) = - let getReferencedProjectOutputs (options: FSharpProjectOptions) = - options.ReferencedProjects |> Array.map (fun project -> project.OutputFile) + let getReferencedProjectOutputs (options: FSharpProjectSnapshot) = + options.ReferencedProjects |> List.map (fun project -> project.OutputFile) - let newOptions = newProject.ProjectOptions - let oldOptions = oldProject.ProjectOptions + let newOptions = newProject.ProjectSnapshot + let oldOptions = oldProject.ProjectSnapshot newOptions.ProjectFileName = oldOptions.ProjectFileName && newOptions.SourceFiles = oldOptions.SourceFiles && @@ -258,9 +260,9 @@ type TestFcsProjectProvider(lifetime: Lifetime, checkerService: FcsCheckerServic newFcsProject ) - let getProjectOptions (sourceFile: IPsiSourceFile) = + let getProjectSnapshot (sourceFile: IPsiSourceFile) = let fcsProject = getFcsProject sourceFile.PsiModule - Some fcsProject.ProjectOptions + Some fcsProject.ProjectSnapshot interface IHideImplementation @@ -269,11 +271,11 @@ type TestFcsProjectProvider(lifetime: Lifetime, checkerService: FcsCheckerServic let fcsProject = getFcsProject sourceFile.PsiModule fcsProject.ImplementationFilesWithSignatures.Contains(sourceFile.GetLocation()) - member x.GetProjectOptions(sourceFile: IPsiSourceFile) = + member x.GetProjectSnapshot(sourceFile: IPsiSourceFile) = if sourceFile.LanguageType.Is() then scriptFcsProjectProvider.GetScriptSnapshot(sourceFile) else - getProjectOptions sourceFile + getProjectSnapshot sourceFile member x.GetParsingOptions(sourceFile) = if isNull sourceFile then sandboxParsingOptions else @@ -328,7 +330,7 @@ type TestFcsProjectProvider(lifetime: Lifetime, checkerService: FcsCheckerServic member x.HasFcsProjects = false member this.GetAllFcsProjects() = [] - member this.GetProjectOptions(_: IPsiModule): FSharpProjectOptions option = failwith "todo" + member this.GetProjectSnapshot(_: IPsiModule): FSharpProjectSnapshot option = failwith "todo" member this.GetFcsProject(psiModule) = Some (getFcsProject psiModule) member this.PrepareAssemblyShim _ = () member this.GetReferencedModule _ = None