Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions vsintegration/src/FSharp.Editor/LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type internal SVsSettingsPersistenceManager = class end
[<ProvideEditorExtension(FSharpCommonConstants.editorFactoryGuidString, ".fsscript", 97)>]
[<ProvideEditorExtension(FSharpCommonConstants.editorFactoryGuidString, ".ml", 97)>]
[<ProvideEditorExtension(FSharpCommonConstants.editorFactoryGuidString, ".mli", 97)>]
type internal FSharpLanguageService(package : FSharpPackage) =
type internal FSharpLanguageService(package : FSharpPackage) =
inherit AbstractLanguageService<FSharpPackage, FSharpLanguageService>(package)

static let optionsCache = Dictionary<ProjectId, FSharpProjectOptions>()
Expand All @@ -55,12 +55,28 @@ type internal FSharpLanguageService(package : FSharpPackage) =
else
None

static member UpdateOptions(projectId: ProjectId, options: FSharpProjectOptions) =
optionsCache.[projectId] <- options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are source file paths, should we be using an OrdinalIgnoreCase comparer for the HashSets?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, adding that now.


member this.SyncProject(project: AbstractProject, projectContext: IWorkspaceProjectContext, site: IProjectSite) =
let updatedFiles = site.SourceFilesOnDisk()
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath)

for file in updatedFiles do if not(workspaceFiles.Contains(file)) then projectContext.AddSourceFile(file)
for file in workspaceFiles do if not(updatedFiles.Contains(file)) then projectContext.RemoveSourceFile(file)
let hashSetIgnoreCase x = new HashSet<string>(x, StringComparer.OrdinalIgnoreCase)
let updatedFiles = site.SourceFilesOnDisk() |> hashSetIgnoreCase
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath) |> hashSetIgnoreCase

let mutable updated = false
for file in updatedFiles do
if not(workspaceFiles.Contains(file)) then
projectContext.AddSourceFile(file)
updated <- true
for file in workspaceFiles do
if not(updatedFiles.Contains(file)) then
projectContext.RemoveSourceFile(file)
updated <- true

// update the cached options
if updated then
let checkOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, "")
FSharpLanguageService.UpdateOptions(project.Id, checkOptions)

override this.ContentTypeName = FSharpCommonConstants.FSharpContentTypeName
override this.LanguageName = FSharpCommonConstants.FSharpLanguageName
Expand Down Expand Up @@ -101,8 +117,7 @@ type internal FSharpLanguageService(package : FSharpPackage) =
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(projectFileName, projectFileName)

let options = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, site.ProjectFileName())
if not (optionsCache.ContainsKey(projectId)) then
optionsCache.Add(projectId, options)
FSharpLanguageService.UpdateOptions(projectId, options)

match workspace.ProjectTracker.GetProject(projectId) with
| null ->
Expand All @@ -121,8 +136,7 @@ type internal FSharpLanguageService(package : FSharpPackage) =
let options = FSharpChecker.Instance.GetProjectOptionsFromScript(fileName, fileContents, DateTime.Now, [| |]) |> Async.RunSynchronously
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(options.ProjectFileName, options.ProjectFileName)

if not(optionsCache.ContainsKey(projectId)) then
optionsCache.Add(projectId, options)
FSharpLanguageService.UpdateOptions(projectId, options)

if obj.ReferenceEquals(workspace.ProjectTracker.GetProject(projectId), null) then
let projectContextFactory = this.Package.ComponentModel.GetService<IWorkspaceProjectContextFactory>();
Expand Down Expand Up @@ -155,11 +169,11 @@ and [<Guid(FSharpCommonConstants.packageGuidString)>]
CodeSenseDelay = 100)>]
internal FSharpPackage() =
inherit AbstractPackage<FSharpPackage, FSharpLanguageService>()

override this.RoslynLanguageName = FSharpCommonConstants.FSharpLanguageName

override this.CreateWorkspace() = this.ComponentModel.GetService<VisualStudioWorkspaceImpl>()

override this.CreateLanguageService() = new FSharpLanguageService(this)

override this.CreateEditorFactories() = Seq.empty<IVsEditorFactory>
Expand Down