@@ -8,6 +8,7 @@ open System.Threading.Tasks
88open FSharp.Compiler .CodeAnalysis
99open JetBrains.Application
1010open JetBrains.Application .BuildScript .Application .Zones
11+ open JetBrains.Application .Threading
1112open JetBrains.Diagnostics
1213open JetBrains.DocumentModel
1314open JetBrains.ProjectModel
@@ -17,6 +18,7 @@ open JetBrains.ProjectModel.ProjectsHost.MsBuild.Strategies
1718open JetBrains.ProjectModel .ProjectsHost .SolutionHost
1819open JetBrains.ProjectModel .Properties .Managed
1920open JetBrains.RdBackend .Common .Features .Documents
21+ open JetBrains.ReSharper .Plugins .FSharp
2022open JetBrains.ReSharper .Plugins .FSharp .ProjectModel
2123open JetBrains.ReSharper .Plugins .FSharp .ProjectModel .Host .ProjectItems .ItemsContainer
2224open JetBrains.ReSharper .Plugins .FSharp .Shim .AssemblyReader
@@ -68,7 +70,7 @@ module FcsProjectBuilder =
6870[<SolutionComponent>]
6971[<ZoneMarker( typeof< ISinceClr4HostZone>) >]
7072type FcsProjectBuilder ( checkerService : FcsCheckerService , itemsContainer : IFSharpItemsContainer ,
71- modulePathProvider: ModulePathProvider, logger: ILogger, psiModules: IPsiModules) =
73+ modulePathProvider: ModulePathProvider, logger: ILogger, psiModules: IPsiModules, locks : IShellLocks ) =
7274
7375 let defaultOptions =
7476 [| " --noframework"
@@ -209,16 +211,35 @@ type FcsProjectBuilder(checkerService: FcsCheckerService, itemsContainer: IFShar
209211 )
210212 |> Seq.map ( fun psiSourceFile ->
211213 let name = psiSourceFile.GetLocation() .FullPath
214+ (*
215+
216+ In order to create the snapshot, we need to ensure that Resharper read lock rules are respected when getting the source.
217+ Today, this happens in DelegatingFileSystemShim.cs.
218+ So we can rely on the file system (that is shimmed) and use FSharpFileSnapshot.CreateFromFileSystem.
219+
220+ Alternatively we can construct the snapshot via getSource:
221+ ```fsharp
212222 let version = string psiSourceFile.Document.LastModificationStamp.Value
213223
214224 let getSource () =
215225 task {
216- use cookie = ReadLockCookie.Create()
217- let text = psiSourceFile.Document.GetText()
226+ let mutable text = ""
227+ FSharpAsyncUtil.UsingReadLockInsideFcs(locks, fun () ->
228+ text <- psiSourceFile.Document.GetText()
229+ )
218230 return FSharp.Compiler.Text.SourceTextNew.ofString text
219231 }
220232
221233 ProjectSnapshot.FSharpFileSnapshot.Create(name, version, getSource)
234+ ```
235+
236+ This also worked but for now going with the FileSystemShim seems better?
237+ I favour the getSource option (or a better version of it) over the FileSystemShim
238+ as it makes it more explicit where the source is really coming from.
239+ However, I don't have enough understanding about the plugin to really make this judgement call.
240+
241+ *)
242+ ProjectSnapshot.FSharpFileSnapshot.CreateFromFileSystem( name)
222243 )
223244 |> Seq.toList
224245
0 commit comments