Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@
<!-- System.* packages -->
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>
<SystemConsoleVersion>4.3.0</SystemConsoleVersion>
<SystemDataSqlClientPackageVersion>4.3.0</SystemDataSqlClientPackageVersion>
<SystemDesignVersion>4.0.0</SystemDesignVersion>
<SystemDiagnosticsProcessVersion>4.3.0</SystemDiagnosticsProcessVersion>
<SystemDiagnosticsTraceSourceVersion>4.3.0</SystemDiagnosticsTraceSourceVersion>
<SystemIoCompressionVersion>4.3.0</SystemIoCompressionVersion>
<SystemLinqExpressionsVersion>4.3.0</SystemLinqExpressionsVersion>
<SystemLinqQueryableVersion>4.3.0</SystemLinqQueryableVersion>
<SystemMemoryVersion>4.5.2</SystemMemoryVersion>
<SystemMemoryVersion>4.5.3</SystemMemoryVersion>
<SystemNetRequestsVersion>4.3.0</SystemNetRequestsVersion>
<SystemNetSecurityVersion>4.3.0</SystemNetSecurityVersion>
<SystemReflectionEmitVersion>4.3.0</SystemReflectionEmitVersion>
Expand All @@ -88,7 +89,9 @@
<SystemSecurityClaimsVersion>4.3.0</SystemSecurityClaimsVersion>
<SystemSecurityCryptographyAlgorithmsVersion>4.3.0</SystemSecurityCryptographyAlgorithmsVersion>
<SystemSecurityPrincipalVersion>4.3.0</SystemSecurityPrincipalVersion>
<SystemThreadingTasksDataflowPackageVersion>4.6.0</SystemThreadingTasksDataflowPackageVersion>
<SystemThreadingTasksParallelVersion>4.3.0</SystemThreadingTasksParallelVersion>
<SystemThreadingTasksDataflow>4.11.0</SystemThreadingTasksDataflow>
<SystemThreadingThreadVersion>4.3.0</SystemThreadingThreadVersion>
<SystemThreadingThreadPoolVersion>4.3.0</SystemThreadingThreadPoolVersion>
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
Expand All @@ -102,7 +105,7 @@
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.17</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftVisualStudioLanguageServicesVersion>$(RoslynVersion)</MicrosoftVisualStudioLanguageServicesVersion>
<!-- Microsoft Build packages -->
<MicrosoftBuildOverallPackagesVersion>16.0.461</MicrosoftBuildOverallPackagesVersion>
<MicrosoftBuildOverallPackagesVersion>16.4</MicrosoftBuildOverallPackagesVersion>
<MicrosoftBuildVersion>$(MicrosoftBuildOverallPackagesVersion)</MicrosoftBuildVersion>
<MicrosoftBuildFrameworkVersion>$(MicrosoftBuildOverallPackagesVersion)</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildTasksCoreVersion>$(MicrosoftBuildOverallPackagesVersion)</MicrosoftBuildTasksCoreVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
<Reference Include="UIAutomationTypes" />
<ProjectReference Include="CSharp_Analysis\CSharp_Analysis.csproj" />
<ProjectReference Include="..\FSharp.Compiler.Service.ProjectCracker\FSharp.Compiler.Service.ProjectCracker.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,7 @@ type TcConfigBuilder =
isInvalidationSupported = isInvalidationSupported
copyFSharpCore = defaultCopyFSharpCore
tryGetMetadataSnapshot = tryGetMetadataSnapshot
useFsiAuxLib = isInteractive
}

member tcConfigB.ResolveSourceFile(m, nm, pathLoadedFrom) =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Build/Microsoft.FSharp.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ this file.

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<FSharpBuildAssemblyFile Condition=" '$(FSharpBuildAssemblyFile)' =='' ">FSharp.Build.dll</FSharpBuildAssemblyFile>
<FSharpBuildAssemblyFile Condition=" '$(FSharpBuildAssemblyFile)' =='' ">$(MSBuildThisFileDirectory)FSharp.Build.dll</FSharpBuildAssemblyFile>
</PropertyGroup>

<UsingTask TaskName="Fsc" AssemblyFile="$(FSharpBuildAssemblyFile)" />
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module internal FSharpCheckerResultsSettings =
| s -> int64 s

// Look for DLLs in the location of the service DLL first.
let defaultFSharpBinariesDir = FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(Some(typeof<IncrementalBuilder>.Assembly.Location)).Value
let defaultFSharpBinariesDir = FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(Some(Path.GetDirectoryName(typeof<IncrementalBuilder>.Assembly.Location))).Value

[<RequireQualifiedAccess>]
type FSharpFindDeclFailureReason =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ type IncrementalBuilder(tcGlobals, frameworkTcImports, nonFrameworkAssemblyInput
defaultFSharpBinariesDir,
implicitIncludeDir=projectDirectory,
reduceMemoryUsage=ReduceMemoryFlag.Yes,
isInteractive=false,
isInteractive=useScriptResolutionRules,
isInvalidationSupported=true,
defaultCopyFSharpCore=CopyFSharpCoreFlag.No,
tryGetMetadataSnapshot=tryGetMetadataSnapshot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="$(MicrosoftVisualStudioShellInterop110Version)" PrivateAssets="all" ExcludeAssets="contentFiles;build;analyzers;native" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="VSSDK.VSLangProj.8" Version="$(VSSDKVSLangProj8Version)" PrivateAssets="all" ExcludeAssets="contentFiles;build;analyzers;native" />
<PackageReference Include="StreamJsonRpc" Version="$(StreamJsonRpcVersion)" />
<PackageReference Include="StreamJsonRpc" Version="$(StreamJsonRpcVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflow)" />
</ItemGroup>

<ItemGroup>
Expand Down
161 changes: 161 additions & 0 deletions vsintegration/tests/UnitTests/FsxCompletionProviderTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// To run the tests in this file:
//
// Technique 1: Compile VisualFSharp.UnitTests.dll and run it as a set of unit tests
//
// Technique 2:
//
// Enable some tests in the #if EXE section at the end of the file,
// then compile this file as an EXE that has InternalsVisibleTo access into the
// appropriate DLLs. This can be the quickest way to get turnaround on updating the tests
// and capturing large amounts of structured output.
(*
cd Debug\net40\bin
.\fsc.exe --define:EXE -r:.\Microsoft.Build.Utilities.Core.dll -o VisualFSharp.UnitTests.exe -g --optimize- -r .\FSharp.Compiler.Private.dll -r .\FSharp.Editor.dll -r nunit.framework.dll ..\..\..\tests\service\FsUnit.fs ..\..\..\tests\service\Common.fs /delaysign /keyfile:..\..\..\src\fsharp\msft.pubkey ..\..\..\vsintegration\tests\UnitTests\FsxCompletionProviderTests.fs
.\VisualFSharp.UnitTests.exe
*)
// Technique 3:
//
// Use F# Interactive. This only works for FSharp.Compiler.Service.dll which has a public API

// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn

open System
open System.Collections.Generic
open System.IO
open System.Linq
open System.Reflection

open NUnit.Framework

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.FSharp.Editor

open FSharp.Compiler.SourceCodeServices
open UnitTests.TestLib.LanguageService

// AppDomain helper
type Worker () =
inherit MarshalByRefObject()

let filePath = "C:\\test.fsx"
let projectOptions = {
ProjectFileName = "C:\\test.fsproj"
ProjectId = None
SourceFiles = [| filePath |]
ReferencedProjects = [| |]
OtherOptions = [| |]
IsIncompleteTypeCheckEnvironment = true
UseScriptResolutionRules = true
LoadTime = DateTime.MaxValue
OriginalLoadReferences = []
UnresolvedReferences = None
ExtraProjectInfo = None
Stamp = None
}

let formatCompletions(completions : string seq) =
"\n\t" + String.Join("\n\t", completions)

let VerifyCompletionList(fileContents: string, marker: string, expected: string list, unexpected: string list) =
let caretPosition = fileContents.IndexOf(marker) + marker.Length
let results =
FSharpCompletionProvider.ProvideCompletionsAsyncAux(checker, SourceText.From(fileContents), caretPosition, projectOptions, filePath, 0, (fun _ -> []), LanguageServicePerformanceOptions.Default, IntelliSenseOptions.Default)
|> Async.RunSynchronously
|> Option.defaultValue (ResizeArray())
|> Seq.map(fun result -> result.DisplayText)

let expectedFound =
expected
|> Seq.filter results.Contains

let expectedNotFound =
expected
|> Seq.filter (expectedFound.Contains >> not)

let unexpectedNotFound =
unexpected
|> Seq.filter (results.Contains >> not)

let unexpectedFound =
unexpected
|> Seq.filter (unexpectedNotFound.Contains >> not)

// If either of these are true, then the test fails.
let hasExpectedNotFound = not (Seq.isEmpty expectedNotFound)
let hasUnexpectedFound = not (Seq.isEmpty unexpectedFound)

if hasExpectedNotFound || hasUnexpectedFound then
let expectedNotFoundMsg =
if hasExpectedNotFound then
sprintf "\nExpected completions not found:%s\n" (formatCompletions expectedNotFound)
else
String.Empty

let unexpectedFoundMsg =
if hasUnexpectedFound then
sprintf "\nUnexpected completions found:%s\n" (formatCompletions unexpectedFound)
else
String.Empty

let completionsMsg = sprintf "\nin Completions:%s" (formatCompletions results)

let msg = sprintf "%s%s%s" expectedNotFoundMsg unexpectedFoundMsg completionsMsg

Assert.Fail(msg)

member __.VerifyCompletionListExactly(fileContents: string, marker: string, expected: List<string>) =

let caretPosition = fileContents.IndexOf(marker) + marker.Length
let expected = expected |> Seq.toList
let actual =
let x = FSharpCompletionProvider.ProvideCompletionsAsyncAux(checker, SourceText.From(fileContents), caretPosition, projectOptions, filePath, 0, (fun _ -> []), LanguageServicePerformanceOptions.Default, IntelliSenseOptions.Default)
|> Async.RunSynchronously
x |> Option.defaultValue (ResizeArray())
|> Seq.toList
// sort items as Roslyn do - by `SortText`
|> List.sortBy (fun x -> x.SortText)

let actualNames = actual |> List.map (fun x -> x.DisplayText)

if actualNames <> expected then
Assert.Fail(sprintf "Expected:\n%s,\nbut was:\n%s\nactual with sort text:\n%s"
(String.Join("; ", expected |> List.map (sprintf "\"%s\"")))
(String.Join("; ", actualNames |> List.map (sprintf "\"%s\"")))
(String.Join("\n", actual |> List.map (fun x -> sprintf "%s => %s" x.DisplayText x.SortText))))

module FsxCompletionProviderTests =

let pathToThisDll = Assembly.GetExecutingAssembly().CodeBase

let getWorker () =

let adSetup =
let setup = new System.AppDomainSetup ()
setup.PrivateBinPath <- pathToThisDll
setup.ApplicationBase <- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SomeNonExistentDirectory")
setup

let ad = AppDomain.CreateDomain((Guid()).ToString(), null, adSetup)
(ad.CreateInstanceFromAndUnwrap(pathToThisDll, typeof<Worker>.FullName)) :?> Worker

[<Test>]
let fsiShouldTriggerCompletionInFsxFile() =

let fileContents = """
fsi.
"""
let expected = List<string>([
"CommandLineArgs"; "EventLoop"; "FloatingPointFormat"; "FormatProvider"; "PrintDepth";
"PrintLength"; "PrintSize"; "PrintWidth"; "ShowDeclarationValues"; "ShowIEnumerable";
"ShowProperties"; "AddPrinter"; "AddPrintTransformer"; "Equals"; "GetHashCode";
"GetType"; "ToString"; ])

// We execute in a seperate appdomain so that we can set BaseDirectory to a non-existent location
getWorker().VerifyCompletionListExactly(fileContents, "fsi.", expected)

#if EXE
ShouldTriggerCompletionInFsxFile()
#endif
3 changes: 3 additions & 0 deletions vsintegration/tests/UnitTests/VisualFSharp.UnitTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
<Compile Include="CompletionProviderTests.fs">
<Link>Roslyn\CompletionProviderTests.fs</Link>
</Compile>
<Compile Include="FsxCompletionProviderTests.fs">
<Link>Roslyn\FsxCompletionProviderTests.fs</Link>
</Compile>
<Compile Include="SignatureHelpProviderTests.fs">
<Link>Roslyn\SignatureHelpProviderTests.fs</Link>
</Compile>
Expand Down