Skip to content

Commit a2ed82b

Browse files
committed
Thanks Alex!
1 parent 1731578 commit a2ed82b

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsProjectBuilder.fs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open System.Threading.Tasks
88
open FSharp.Compiler.CodeAnalysis
99
open JetBrains.Application
1010
open JetBrains.Application.BuildScript.Application.Zones
11+
open JetBrains.Application.Threading
1112
open JetBrains.Diagnostics
1213
open JetBrains.DocumentModel
1314
open JetBrains.ProjectModel
@@ -17,6 +18,7 @@ open JetBrains.ProjectModel.ProjectsHost.MsBuild.Strategies
1718
open JetBrains.ProjectModel.ProjectsHost.SolutionHost
1819
open JetBrains.ProjectModel.Properties.Managed
1920
open JetBrains.RdBackend.Common.Features.Documents
21+
open JetBrains.ReSharper.Plugins.FSharp
2022
open JetBrains.ReSharper.Plugins.FSharp.ProjectModel
2123
open JetBrains.ReSharper.Plugins.FSharp.ProjectModel.Host.ProjectItems.ItemsContainer
2224
open JetBrains.ReSharper.Plugins.FSharp.Shim.AssemblyReader
@@ -68,7 +70,7 @@ module FcsProjectBuilder =
6870
[<SolutionComponent>]
6971
[<ZoneMarker(typeof<ISinceClr4HostZone>)>]
7072
type 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

ReSharper.FSharp/test/src/FSharp.Tests.Common/src/Common.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ type TestFSharpResolvedSymbolsCache(lifetime, checkerService, psiModules, fcsPro
209209

210210
[<SolutionComponent>]
211211
[<ZoneMarker(typeof<ITestFSharpPluginZone>)>]
212-
type TestFcsProjectBuilder(checkerService, modulePathProvider, logger, psiModules) =
213-
inherit FcsProjectBuilder(checkerService, Mock<_>().Object, modulePathProvider, logger, psiModules)
212+
type TestFcsProjectBuilder(checkerService, modulePathProvider, logger, psiModules, locks) =
213+
inherit FcsProjectBuilder(checkerService, Mock<_>().Object, modulePathProvider, logger, psiModules, locks)
214214

215215
override x.GetProjectItemsPaths(project, targetFrameworkId) =
216216
project.GetAllProjectFiles()

0 commit comments

Comments
 (0)