Skip to content

Commit

Permalink
add comments, fix formatting, cleanup flag (#4891)
Browse files Browse the repository at this point in the history
* add docs

* cleanup flag that's always true

* correct comment
  • Loading branch information
dsyme authored May 12, 2018
1 parent 0fd7cdf commit a3d131e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
61 changes: 43 additions & 18 deletions vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ type internal FSharpProjectOptionsManager
// compiled and #r will refer to files on disk
let referencedProjectFileNames = [| |]
let site = ProjectSitesAndFiles.CreateProjectSiteForScript(fileName, referencedProjectFileNames, options)
let deps, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId fileName), fileName, options.ExtraProjectInfo, Some projectOptionsTable, true)
let deps, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId fileName), fileName, options.ExtraProjectInfo, Some projectOptionsTable)
let parsingOptions, _ = checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
return (deps, parsingOptions, projectOptions)
else
let site = ProjectSitesAndFiles.ProjectSiteOfSingleFile(fileName)
let deps, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId fileName), fileName, extraProjectInfo, Some projectOptionsTable, true)
let deps, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId fileName), fileName, extraProjectInfo, Some projectOptionsTable)
let parsingOptions, _ = checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
return (deps, parsingOptions, projectOptions)
}
Expand All @@ -175,7 +175,7 @@ type internal FSharpProjectOptionsManager
projectOptionsTable.AddOrUpdateProject(projectId, (fun isRefresh ->
let extraProjectInfo = Some(box workspace)
let tryGetOptionsForReferencedProject f = f |> tryGetOrCreateProjectId |> Option.bind this.TryGetOptionsForProject |> Option.map(fun (_, _, projectOptions) -> projectOptions)
let referencedProjects, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId (site.ProjectFileName)), site.ProjectFileName, extraProjectInfo, Some projectOptionsTable, true)
let referencedProjects, projectOptions = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider, (tryGetOrCreateProjectId (site.ProjectFileName)), site.ProjectFileName, extraProjectInfo, Some projectOptionsTable)
if invalidateConfig then checkerProvider.Checker.InvalidateConfiguration(projectOptions, startBackgroundCompileIfAlreadySeen = not isRefresh, userOpName = userOpName + ".UpdateProjectInfo")
let referencedProjectIds = referencedProjects |> Array.choose tryGetOrCreateProjectId
let parsingOptions, _ = checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
Expand Down Expand Up @@ -206,18 +206,18 @@ type internal FSharpProjectOptionsManager
match singleFileProjectTable.TryGetValue(projectId) with
| true, (loadTime, _, _) ->
try
let fileName = document.FilePath
let! cancellationToken = Async.CancellationToken
let! sourceText = document.GetTextAsync(cancellationToken) |> Async.AwaitTask
// NOTE: we don't use FCS cross-project references from scripts to projects. The projects must have been
// compiled and #r will refer to files on disk.
let tryGetOrCreateProjectId _ = None
let! _referencedProjectFileNames, parsingOptions, projectOptions = this.ComputeSingleFileOptions (tryGetOrCreateProjectId, fileName, loadTime, sourceText.ToString())
this.AddOrUpdateSingleFileProject(projectId, (loadTime, parsingOptions, projectOptions))
return Some (parsingOptions, None, projectOptions)
let fileName = document.FilePath
let! cancellationToken = Async.CancellationToken
let! sourceText = document.GetTextAsync(cancellationToken) |> Async.AwaitTask
// NOTE: we don't use FCS cross-project references from scripts to projects. The projects must have been
// compiled and #r will refer to files on disk.
let tryGetOrCreateProjectId _ = None
let! _referencedProjectFileNames, parsingOptions, projectOptions = this.ComputeSingleFileOptions (tryGetOrCreateProjectId, fileName, loadTime, sourceText.ToString())
this.AddOrUpdateSingleFileProject(projectId, (loadTime, parsingOptions, projectOptions))
return Some (parsingOptions, None, projectOptions)
with ex ->
Assert.Exception(ex)
return None
Assert.Exception(ex)
return None
| _ -> return this.TryGetOptionsForProject(projectId)
}

Expand Down Expand Up @@ -658,26 +658,51 @@ type internal FSharpLanguageService(package : FSharpPackage) =
| (VSConstants.S_OK, textLines) ->
let filename = VsTextLines.GetFilename textLines

// CPS projects don't implement IProvideProjectSite and IVSProjectHierarchy
// Simple explanation:
// Legacy projects have IVSHierarchy and IPRojectSite
// CPS Projects and loose script files don't
match VsRunningDocumentTable.FindDocumentWithoutLocking(package.RunningDocumentTable,filename) with
| Some (hier, _) ->


// Check if the file is in a CPS project or not.
// CPS projects don't implement IProvideProjectSite and IVSProjectHierarchy
// Simple explanation:
// Legacy projects have IVSHierarchy and IProjectSite
// CPS Projects, out-of-project file and script files don't

match hier with
| :? IProvideProjectSite as siteProvider when not (IsScript(filename)) ->

// This is the path for .fs/.fsi files in legacy projects

this.SetupProjectFile(siteProvider, this.Workspace, "SetupNewTextView")

| h when not (IsScript(filename)) ->

let docId = this.Workspace.CurrentSolution.GetDocumentIdsWithFilePath(filename).FirstOrDefault()
match docId with
| null ->
if not (h.IsCapabilityMatch("CPS")) then

// This is the path when opening out-of-project .fs/.fsi files in CPS projects

let fileContents = VsTextLines.GetFileContents(textLines, textViewAdapter)
this.SetupStandAloneFile(filename, fileContents, this.Workspace, hier)
| id ->

// This is the path when opening in-project .fs/.fsi files in CPS projects when
// there is already an existing DocumentId for that document in the solution (which
// will normally be the case)
//
// However, it is not clear this call to UpdateProjectInfoWithProjectId is needed, and it seems
// harmful as it will cause a complete recheck of the project every time a view for a file in the
// project is freshly opened.

projectInfoManager.UpdateProjectInfoWithProjectId(id.ProjectId, "SetupNewTextView", invalidateConfig=true)
| _ ->

// This is the path for both in-project and out-of-project .fsx files

let fileContents = VsTextLines.GetFileContents(textLines, textViewAdapter)
this.SetupStandAloneFile(filename, fileContents, this.Workspace, hier)

| _ -> ()
| _ -> ()
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,20 @@ type internal ProjectSitesAndFiles() =
| None -> ()
}

static let rec referencedProjectsOf(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, extraProjectInfo, projectOptionsTable, useUniqueStamp) =
static let rec referencedProjectsOf(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, extraProjectInfo, projectOptionsTable) =
[| for (projectId, projectFileName, outputPath, projectSiteProvider) in referencedProvideProjectSites (projectSite, serviceProvider, extraProjectInfo, projectOptionsTable) do
let referencedProjectOptions =
// Lookup may not succeed if the project has not been established yet
// In this case we go and compute the options recursively.
match tryGetOptionsForReferencedProject projectFileName with
| None -> getProjectOptionsForProjectSite (enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSiteProvider.GetProjectSite(), serviceProvider, projectId, projectFileName, extraProjectInfo, projectOptionsTable, useUniqueStamp) |> snd
| None -> getProjectOptionsForProjectSite (enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSiteProvider.GetProjectSite(), serviceProvider, projectId, projectFileName, extraProjectInfo, projectOptionsTable) |> snd
| Some options -> options
yield projectFileName, (outputPath, referencedProjectOptions) |]

and getProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, projectId, fileName, extraProjectInfo, projectOptionsTable, useUniqueStamp) =
and getProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, projectId, fileName, extraProjectInfo, projectOptionsTable) =
let referencedProjectFileNames, referencedProjectOptions =
if enableInMemoryCrossProjectReferences then
referencedProjectsOf(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, extraProjectInfo, projectOptionsTable, useUniqueStamp)
referencedProjectsOf(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, extraProjectInfo, projectOptionsTable)
|> Array.unzip
else [| |], [| |]
let option =
Expand All @@ -283,7 +283,7 @@ type internal ProjectSitesAndFiles() =
UnresolvedReferences = None
OriginalLoadReferences = []
ExtraProjectInfo=extraProjectInfo
Stamp = if useUniqueStamp then (stamp <- stamp + 1L; Some stamp) else None
Stamp = (stamp <- stamp + 1L; Some stamp)
}
match projectId, projectOptionsTable with
| Some id, Some optionsTable ->
Expand Down Expand Up @@ -313,10 +313,10 @@ type internal ProjectSitesAndFiles() =
|> Seq.toArray

/// Create project options for this project site.
static member GetProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite:IProjectSite, serviceProvider, projectId, filename, extraProjectInfo, projectOptionsTable, useUniqueStamp) =
static member GetProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite:IProjectSite, serviceProvider, projectId, filename, extraProjectInfo, projectOptionsTable) =
match projectSite with
| :? IHaveCheckOptions as hco -> hco.OriginalCheckOptions()
| _ -> getProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, projectId, filename, extraProjectInfo, projectOptionsTable, useUniqueStamp)
| _ -> getProjectOptionsForProjectSite(enableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, projectSite, serviceProvider, projectId, filename, extraProjectInfo, projectOptionsTable)

/// Create project site for these project options
static member CreateProjectSiteForScript (filename, referencedProjectFileNames, checkOptions) =
Expand Down

0 comments on commit a3d131e

Please sign in to comment.