@@ -203,43 +203,59 @@ type FcsProjectBuilder(checkerService: FcsCheckerService, itemsContainer: IFShar
203203
204204 let psiModule = psiModules.GetPrimaryPsiModule( project, targetFrameworkId)
205205
206- let sourceFiles =
206+ let projectItems : ( VirtualFileSystemPath * BuildAction ) array = x.GetProjectItemsPaths( project, targetFrameworkId)
207+
208+ let tryFindPsiSourceFile name =
207209 psiModule.SourceFiles
208- |> Seq.filter( fun psiSourceFile ->
209- isNotNull psiSourceFile.PrimaryPsiLanguage
210- && psiSourceFile.PrimaryPsiLanguage.Name = " F#"
211- )
212- |> Seq.map ( fun psiSourceFile ->
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
222- let version = string psiSourceFile.Document.LastModificationStamp.Value
223-
224- let getSource () =
225- task {
226- let mutable text = ""
227- FSharpAsyncUtil.UsingReadLockInsideFcs(locks, fun () ->
228- text <- psiSourceFile.Document.GetText()
229- )
230- return FSharp.Compiler.Text.SourceTextNew.ofString text
231- }
232-
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)
210+ |> Seq.tryFind ( fun sf -> sf.GetLocation() .FullPath = name)
211+
212+ let sourceFiles =
213+ projectItems
214+ |> Seq.choose ( fun ( virtualFileSystemPath , buildAction ) ->
215+ match buildAction, tryFindPsiSourceFile virtualFileSystemPath.FullPath with
216+ | SourceFile, Some psiSourceFile ->
217+ let name = virtualFileSystemPath.FullPath
218+ (*
219+
220+ In order to create the snapshot, we need to ensure that Resharper read lock rules are respected when getting the source.
221+ Today, this happens in DelegatingFileSystemShim.cs.
222+ So we can rely on the file system (that is shimmed) and use FSharpFileSnapshot.CreateFromFileSystem.
223+
224+ Alternatively we can construct the snapshot via getSource:
225+ ```fsharp
226+ let version = string psiSourceFile.Document.LastModificationStamp.Value
227+
228+ let getSource () =
229+ task {
230+ let mutable text = ""
231+ FSharpAsyncUtil.UsingReadLockInsideFcs(locks, fun () ->
232+ text <- psiSourceFile.Document.GetText()
233+ )
234+ return FSharp.Compiler.Text.SourceTextNew.ofString text
235+ }
236+
237+ ProjectSnapshot.FSharpFileSnapshot.Create(name, version, getSource)
238+ ```
239+
240+ This also worked but for now going with the FileSystemShim seems better?
241+ I favour the getSource option (or a better version of it) over the FileSystemShim
242+ as it makes it more explicit where the source is really coming from.
243+ However, I don't have enough understanding about the plugin to really make this judgement call.
244+
245+ *)
246+ let getSource () =
247+ task {
248+ let mutable text = " "
249+ FSharpAsyncUtil.UsingReadLockInsideFcs( locks, fun () ->
250+ text <- psiSourceFile.Document.GetText()
251+ )
252+ return FSharp.Compiler.Text.SourceTextNew.ofString text
253+ }
254+
255+ let hash = string ( psiSourceFile.Document.GetText() .GetHashCode())
256+ // let sf = ProjectSnapshot.FSharpFileSnapshot.CreateFromFileSystem(name)
257+ Some( ProjectSnapshot.FSharpFileSnapshot( name, hash, getSource))
258+ | _ -> None
243259 )
244260 |> Seq.toList
245261
@@ -277,7 +293,7 @@ type FcsProjectBuilder(checkerService: FcsCheckerService, itemsContainer: IFShar
277293 originalLoadReferences = List.empty,
278294 stamp = None
279295 )
280-
296+
281297 let parsingOptions , errors =
282298 checkerService.Checker.GetParsingOptionsFromCommandLineArgs( otherOptions)
283299
0 commit comments