Skip to content

Commit

Permalink
switching to fcs project cracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 8, 2019
1 parent 344961b commit 80b1955
Show file tree
Hide file tree
Showing 11 changed files with 646 additions and 924 deletions.
19 changes: 2 additions & 17 deletions fsharp-language-server.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C12C1289-6B1C-44FA-A500-F70B9530EA27}"
EndProject
Expand All @@ -17,8 +17,6 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharpLanguageServer.Tests"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "LSP.Tests", "tests\LSP.Tests\LSP.Tests.fsproj", "{1D0BB852-97FA-4933-8595-A2B579B3768F}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ProjectCracker.Tests", "tests\ProjectCracker.Tests\ProjectCracker.Tests.fsproj", "{12BD685B-EFDB-4991-A9FE-2CBB28944383}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectInfo", "tests\ProjectInfo\ProjectInfo.csproj", "{EB22E80A-4C8C-4B5D-B114-BC0CDA57207F}"
EndProject
Global
Expand Down Expand Up @@ -91,18 +89,6 @@ Global
{1D0BB852-97FA-4933-8595-A2B579B3768F}.Release|x64.Build.0 = Release|Any CPU
{1D0BB852-97FA-4933-8595-A2B579B3768F}.Release|x86.ActiveCfg = Release|Any CPU
{1D0BB852-97FA-4933-8595-A2B579B3768F}.Release|x86.Build.0 = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|x64.ActiveCfg = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|x64.Build.0 = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|x86.ActiveCfg = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Debug|x86.Build.0 = Debug|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|Any CPU.Build.0 = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|x64.ActiveCfg = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|x64.Build.0 = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|x86.ActiveCfg = Release|Any CPU
{12BD685B-EFDB-4991-A9FE-2CBB28944383}.Release|x86.Build.0 = Release|Any CPU
{EB22E80A-4C8C-4B5D-B114-BC0CDA57207F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB22E80A-4C8C-4B5D-B114-BC0CDA57207F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB22E80A-4C8C-4B5D-B114-BC0CDA57207F}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -125,7 +111,6 @@ Global
{CAE67C77-88CA-4E1D-AB56-BA24C63A9521} = {C12C1289-6B1C-44FA-A500-F70B9530EA27}
{7C5994F9-641C-4A79-ADB6-6A0412EB885B} = {6A478F23-67F9-4F5B-9159-589A05EBBFB5}
{1D0BB852-97FA-4933-8595-A2B579B3768F} = {6A478F23-67F9-4F5B-9159-589A05EBBFB5}
{12BD685B-EFDB-4991-A9FE-2CBB28944383} = {6A478F23-67F9-4F5B-9159-589A05EBBFB5}
{EB22E80A-4C8C-4B5D-B114-BC0CDA57207F} = {6A478F23-67F9-4F5B-9159-589A05EBBFB5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
1 change: 0 additions & 1 deletion src/FSharpLanguageServer/FSharpLanguageServer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Compiler.Service" Version="29.0.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.8.4" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/FSharpLanguageServer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ let private testFunctions(parse: FSharpParseFileResults): (string list * Ast.Syn
| _ -> false
let isTestFunction(binding: Ast.SynBinding): bool =
let attrs = match binding with Ast.Binding(_, _, _, _, attrs, _, _, _, _, _, _, _) -> attrs
List.exists isTestAttribute attrs
let pred (xs: Ast.SynAttributeList) = List.exists isTestAttribute xs.Attributes
List.exists pred attrs
let name(binding: Ast.SynBinding): string list =
match binding with
| Ast.Binding(_, _, _, _, _, _, _, Ast.SynPat.LongIdent(Ast.LongIdentWithDots(ids, _), _, _, _, _, _), _, _, _, _) ->
Expand Down Expand Up @@ -596,7 +597,8 @@ type Server(client: ILanguageClient) =
projects.ConditionalCompilationDefines <- List.ofArray fsconfig.Project.Define
projects.OtherCompilerFlags <- List.ofArray fsconfig.Project.OtherFlags
codelensShowReferences <- fsconfig.Codelens.References
ProjectCracker.includeCompileBeforeItems <- fsconfig.Project.IncludeCompileBefore

ProjectCracker.SetIncludeCompileBefore fsconfig.Project.IncludeCompileBefore
dprintfn "New configuration %O" (fsconfig.JsonValue)

}
Expand Down Expand Up @@ -660,8 +662,6 @@ type Server(client: ILanguageClient) =
projects.UpdateSlnFile(file)
| FileChangeType.Deleted ->
projects.DeleteSlnFile(file)
elif file.Name = "project.assets.json" then
projects.UpdateAssetsJson(file)
// Re-check all open files
// In theory we could optimize this by only re-checking descendents of changed projects,
// but in practice that will make little difference
Expand Down
116 changes: 25 additions & 91 deletions src/FSharpLanguageServer/ProjectManager.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ open FSharp.Data
open FSharp.Data.JsonExtensions
open LSP.Types
open FSharp.Compiler.SourceCodeServices
open ProjectCracker
open FSharp.Compiler.Text

type private ResolvedProject = {
sources: FileInfo list
options: FSharpProjectOptions
target: FileInfo
errors: Diagnostic list
}

Expand All @@ -31,7 +29,7 @@ type private ProjectCache() =

member __.Invalidate(fsprojOrFsx: FileInfo) =
knownProjects.Remove(fsprojOrFsx.FullName) |> ignore
ProjectCracker.invalidateProjectAssets fsprojOrFsx
//ProjectCracker.invalidateProjectAssets fsprojOrFsx
member __.Get(fsprojOrFsx: FileInfo, analyzeLater: FileInfo -> LazyProject): LazyProject =
if not(knownProjects.ContainsKey(fsprojOrFsx.FullName)) then
knownProjects.Add(fsprojOrFsx.FullName, analyzeLater(fsprojOrFsx))
Expand Down Expand Up @@ -67,11 +65,7 @@ type ProjectManager(checker: FSharpChecker) as this =
/// When was this .fsx, .fsproj or corresponding project.assets.json file modified?
// TODO use checksum instead of time
let lastModified(fsprojOrFsx: FileInfo) =
let assets = ProjectCracker.getAssets fsprojOrFsx
if assets.Exists then
max fsprojOrFsx.LastWriteTime assets.LastWriteTime
else
fsprojOrFsx.LastWriteTime
fsprojOrFsx.LastWriteTime

/// Find base dlls
/// Workaround of https://github.com/fsharp/FSharp.Compiler.Service/issues/847
Expand Down Expand Up @@ -252,98 +246,40 @@ type ProjectManager(checker: FSharpChecker) as this =
{
sources=[for f in inferred.SourceFiles do yield FileInfo(f)]
options=options
target=FileInfo("NoOutputForFsx")
errors=Conversions.asDiagnostics(errors)
}
/// Analyze a project
let analyzeFsproj(fsproj: FileInfo) =
dprintfn "Analyzing %s" fsproj.Name
let cracked = ProjectCracker.crack(fsproj)
let cracked, logs = ProjectCracker.GetProjectOptionsFromProjectFileLogged(fsproj.FullName)
// Convert to FSharpProjectOptions
let options = {
ExtraProjectInfo = None
IsIncompleteTypeCheckEnvironment = false
LoadTime = lastModified(fsproj)
OriginalLoadReferences = []
OtherOptions =
[|
// Dotnet framework should be specified explicitly
yield "--noframework"

dprintfn "--------- Project references -----------------"

// Reference output of other projects
for r in cracked.projectReferences do
let options = cache.Get(r, analyzeLater)
yield "-r:" + options.resolved.Value.target.FullName
dprintfn "%s" options.resolved.Value.target.FullName

dprintfn "---------- otherProjectReferences ----------------"

// Reference target .dll for .csproj proejcts
for r in cracked.otherProjectReferences do
yield "-r:" + r.FullName
dprintfn "%s" r.FullName

dprintfn "----------- packageReferences ---------------"

// Reference packages
for r in cracked.packageReferences do
yield "-r:" + r.FullName
dprintfn "%s" r.FullName

dprintfn "----------- directReferences ---------------"

// Direct dll references
for r in cracked.directReferences do
yield "-r:" + r.FullName
dprintfn "%s" r.FullName

dprintfn "----------- systemReferences ---------------"

// System references
for r in cracked.systemReferences do
yield "-r:" + r
dprintfn "%s" r

dprintfn "----------- ConditionalCompilationDefines ---------------"

for d in this.ConditionalCompilationDefines do
yield "-d:" + d
dprintfn "%s" d

dprintfn "----------- OtherCompilerFlags ---------------"

for flag in this.OtherCompilerFlags do
yield flag
dprintfn "%s" flag

dprintfn "--------------------------"
|]
ProjectFileName = fsproj.FullName
ProjectId = None // This is apparently relevant to multi-targeting builds https://github.com/Microsoft/visualfsharp/pull/4918
ReferencedProjects =
[|
for r in cracked.projectReferences do
let options = cache.Get(r, analyzeLater)
yield options.resolved.Value.target.FullName, options.resolved.Value.options
|]
SourceFiles =
[|
for f in cracked.sources do
yield f.FullName
|]
Stamp = None
UnresolvedReferences = None
UseScriptResolutionRules = false
let options = {
cracked
with OtherOptions =
Array.append cracked.OtherOptions [|
dprintfn "----------- ConditionalCompilationDefines ---------------"
for d in this.ConditionalCompilationDefines do
yield "-d:" + d
dprintfn "%s" d
dprintfn "----------- OtherCompilerFlags ---------------"
for flag in this.OtherCompilerFlags do
yield flag
dprintfn "%s" flag
dprintfn "--------------------------"
|]
}
// Log what we inferred
printOptions(options)
{
sources=cracked.sources
sources=options.SourceFiles |> Seq.map FileInfo |> List.ofSeq
options=options
target=cracked.target
errors=match cracked.error with None -> [] | Some(e) -> [Conversions.errorAtTop(e)]
errors= logs |> Map.toList |> List.map (fun (proj, log) -> {
range={start = {line=0; character=0}; ``end`` = {line=0; character=1}}
severity=Some DiagnosticSeverity.Information
code=None
source=Some proj
message=log
})
}
// Direct to analyzeFsx or analyzeFsproj, depending on type
try
Expand Down Expand Up @@ -441,8 +377,6 @@ type ProjectManager(checker: FSharpChecker) as this =
knownSolutions.Remove(sln.FullName) |> ignore
member __.UpdateSlnFile(sln: FileInfo) =
knownSolutions.[sln.FullName] <- slnProjectReferences(sln)
member __.UpdateAssetsJson(assets: FileInfo) =
for fsproj in ProjectCracker.getProject(assets) do invalidateDescendents(fsproj)
member __.FindProjectOptions(sourceFile: FileInfo): Result<FSharpProjectOptions, Diagnostic list> =
let isSourceFile(f: FileInfo) = f.FullName = sourceFile.FullName
// Does `p` contain a reference to `sourceFile`?
Expand Down
Loading

0 comments on commit 80b1955

Please sign in to comment.