@@ -8,6 +8,7 @@ open System.Threading.Tasks
8
8
open FSharp.Compiler .CodeAnalysis
9
9
open JetBrains.Application
10
10
open JetBrains.Application .BuildScript .Application .Zones
11
+ open JetBrains.Application .Threading
11
12
open JetBrains.Diagnostics
12
13
open JetBrains.DocumentModel
13
14
open JetBrains.ProjectModel
@@ -17,6 +18,7 @@ open JetBrains.ProjectModel.ProjectsHost.MsBuild.Strategies
17
18
open JetBrains.ProjectModel .ProjectsHost .SolutionHost
18
19
open JetBrains.ProjectModel .Properties .Managed
19
20
open JetBrains.RdBackend .Common .Features .Documents
21
+ open JetBrains.ReSharper .Plugins .FSharp
20
22
open JetBrains.ReSharper .Plugins .FSharp .ProjectModel
21
23
open JetBrains.ReSharper .Plugins .FSharp .ProjectModel .Host .ProjectItems .ItemsContainer
22
24
open JetBrains.ReSharper .Plugins .FSharp .Shim .AssemblyReader
@@ -68,7 +70,7 @@ module FcsProjectBuilder =
68
70
[<SolutionComponent>]
69
71
[<ZoneMarker( typeof< ISinceClr4HostZone>) >]
70
72
type FcsProjectBuilder ( checkerService : FcsCheckerService , itemsContainer : IFSharpItemsContainer ,
71
- modulePathProvider: ModulePathProvider, logger: ILogger, psiModules: IPsiModules) =
73
+ modulePathProvider: ModulePathProvider, logger: ILogger, psiModules: IPsiModules, locks : IShellLocks ) =
72
74
73
75
let defaultOptions =
74
76
[| " --noframework"
@@ -209,16 +211,35 @@ type FcsProjectBuilder(checkerService: FcsCheckerService, itemsContainer: IFShar
209
211
)
210
212
|> Seq.map ( fun psiSourceFile ->
211
213
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
212
222
let version = string psiSourceFile.Document.LastModificationStamp.Value
213
223
214
224
let getSource () =
215
225
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
+ )
218
230
return FSharp.Compiler.Text.SourceTextNew.ofString text
219
231
}
220
232
221
233
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)
222
243
)
223
244
|> Seq.toList
224
245
0 commit comments