Skip to content

Commit

Permalink
Merge branch 'upstream_master2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed May 26, 2019
2 parents 3ad4f8c + fd55433 commit 7cbfa1d
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 12 deletions.
12 changes: 12 additions & 0 deletions sample/CustomObjPath/CustomObjPath.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions sample/CustomObjPath/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>foo/bar/obj</BaseIntermediateOutputPath>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions sample/CustomObjPath/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// issue #58: project.assets.json not found when a custom IntermediateOutputPath is used.

open System

[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
13 changes: 13 additions & 0 deletions sample/CustomOutputPath/CustomOutputPath.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputPath>foo/bar</OutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions sample/CustomOutputPath/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// issue #58
// Project cracking succeeds, but target dll path is not extracted from the msbuild project.

open System

[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
4 changes: 3 additions & 1 deletion scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dotnet restore sample/ReferenceCSharp/ReferenceCSharp.fsproj
dotnet restore sample/Signature/Signature.fsproj
dotnet restore sample/SlnReferences/ReferencedProject.fsproj
dotnet restore sample/TemplateParams/TemplateParams.fsproj
dotnet restore sample/CustomObjPath/CustomObjPath.fsproj
dotnet restore sample/CustomOutputPath/CustomOutputPath.fsproj
# These need to be built, not restored
dotnet build sample/CSharpProject/CSharpProject.csproj
dotnet build sample/CSharpProject.AssemblyName/CSharpProject.AssemblyName.csproj
dotnet build sample/CSharpProject.AssemblyName/CSharpProject.AssemblyName.csproj
17 changes: 10 additions & 7 deletions src/FSharpLanguageServer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type Server(client: ILanguageClient) =
/// Get a file from docs, or read it from disk
let getOrRead(file: FileInfo): string option =
match docs.GetText(file) with
| Some text -> Some(text)
| Some(text) -> Some(text)
| None when file.Exists -> Some(File.ReadAllText(file.FullName))
| None -> None

Expand Down Expand Up @@ -391,21 +391,21 @@ type Server(client: ILanguageClient) =
let maybeMatchesQuery(query: string, file: FileInfo): string option =
match getOrRead(file) with
| None -> None
| Some text ->
| Some(text) ->
let matches = symbolPattern.Matches(text)
let test(m: Match) = matchesQuery(query, m.Value)
if Seq.exists test matches then
Some text
Some(text)
else
None
let exactlyMatches(findSymbol: string, file: FileInfo): string option =
match getOrRead(file) with
| None -> None
| Some text ->
| Some(text) ->
let matches = symbolPattern.Matches(text)
let test(m: Match) = m.Value = findSymbol
if Seq.exists test matches then
Some text
Some(text)
else
None

Expand Down Expand Up @@ -741,18 +741,21 @@ type Server(client: ILanguageClient) =
}
member this.WorkspaceSymbols(p: WorkspaceSymbolParams): Async<SymbolInformation list> =
async {
let projectNames = String.concat ", " [for p in projects.OpenProjects do yield p.ProjectFileName]
dprintfn "Looking for symbols matching %s in %s" p.query projectNames
dprintfn "Looking for symbols matching `%s`" p.query
// Read open projects until we find at least 50 symbols that match query
let all = System.Collections.Generic.List<SymbolInformation>()
// TODO instead of checking open projects, check all .fs files, using default parsing options
for projectOptions in projects.OpenProjects do
dprintfn "...check project %s" projectOptions.ProjectFileName
for sourceFileName in projectOptions.SourceFiles do
let sourceFile = FileInfo(sourceFileName)
if all.Count < 50 then
dprintfn "...scan %s" sourceFile.Name
match maybeMatchesQuery(p.query, sourceFile) with
| None -> ()
| Some sourceText ->
try
dprintfn "...parse %s" sourceFile.Name
let parsingOptions = getParsingOptions(projectOptions)
let! parse = checker.ParseFile(sourceFile.FullName, sourceText, parsingOptions)
for declaration, container in findDeclarations(parse) do
Expand Down
3 changes: 2 additions & 1 deletion src/FSharpLanguageServer/ProjectManager.fs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ type ProjectManager(checker: FSharpChecker) as this =
result.Add(options)
for f in knownProjects do
let project = cache.Get(FileInfo(f), analyzeLater)
walk(project.resolved.Value.options)
if project.resolved.IsValueCreated then
walk(project.resolved.Value.options)
List.ofSeq(result)
/// All transitive dependencies of `projectFile`, in dependency order
member __.TransitiveDeps(projectFile: FileInfo): FSharpProjectOptions list =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.6.2" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion tests/ProjectCracker.Tests/ProjectCracker.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.6.2" />
</ItemGroup>
</Project>
</Project>
20 changes: 19 additions & 1 deletion tests/ProjectCracker.Tests/ProjectCrackerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,22 @@ let ``build unbuilt project``() =
let cracked = ProjectCracker.crack(fsproj)
if cracked.error.IsSome then Assert.Fail(cracked.error.Value)
CollectionAssert.AreEquivalent(["NotBuilt.fs"], [for f in cracked.sources do yield f.Name])
CollectionAssert.IsNotEmpty(cracked.packageReferences)
CollectionAssert.IsNotEmpty(cracked.packageReferences)

[<Test>]
let ``crack a project file with custom IntermediateOutputPath`` () =
let fsproj = Path.Combine [|projectRoot.FullName; "sample"; "CustomObjPath"; "CustomObjPath.fsproj" |] |> FileInfo
let cracked = ProjectCracker.crack(fsproj)
Assert.True(cracked.error.IsNone)

[<Test>]
let ``crack a project file with custom OutputPath`` () =
let fsproj = Path.Combine [|projectRoot.FullName; "sample"; "CustomOutputPath"; "CustomOutputPath.fsproj" |] |> FileInfo
let cracked = ProjectCracker.crack(fsproj)
let dir = cracked.target.Directory
Assert.AreEqual("netcoreapp2.1", dir.Name)
let dir = dir.Parent
Assert.AreEqual("bar", dir.Name)
let dir = dir.Parent
Assert.AreEqual("foo", dir.Name)

0 comments on commit 7cbfa1d

Please sign in to comment.