diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index 471abbfb98..04f5ea6ef7 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -15,6 +15,7 @@ * Fix FS3356 false positive for instance extension members with same name on different types, introduced by [#18821](https://github.com/dotnet/fsharp/pull/18821). ([PR #19260](https://github.com/dotnet/fsharp/pull/19260)) ### Added +* FSharpType: add ImportILType ([PR #19300](https://github.com/dotnet/fsharp/pull/19300)) ### Changed diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index b215075fb0..05eae26a38 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -11,7 +11,9 @@ open System.Diagnostics open System.IO open System.Threading open FSharp.Compiler.IO +open FSharp.Compiler.Import.Nullness open FSharp.Compiler.NicePrint +open FSharp.Compiler.TypeHierarchy open Internal.Utilities.Library open Internal.Utilities.Library.Extras open Internal.Utilities.TypeHashing @@ -2108,6 +2110,16 @@ type internal TypeCheckInfo |> Seq.tryFindBack (fun (_, _, _, m) -> equals m range) |> Option.map (fun (_, q, _, _) -> FSharpDisplayContext(fun _ -> q.DisplayEnv)) + member scope.ImportILType(ty: ILType) : FSharpType = + let amap = tcImports.GetImportMap() + let assemblyRef = ILAssemblyRef.Create("", None, None, false, None, None) + let scopeRef = ILScopeRef.Assembly assemblyRef + + let typ = + ImportILTypeFromMetadata amap range0 scopeRef [] [] NullableAttributesSource.Empty ty + + FSharpType(cenv, typ) + /// Get the auto-complete items at a location member _.GetDeclarations(parseResultsOpt, line, lineStr, partialName, completionContextAtPos, getAllEntities, options) = let isSigFile = SourceFileImpl.IsSignatureFile mainInputFileName @@ -3522,6 +3534,9 @@ type FSharpCheckFileResults | None -> None | Some(scope, _) -> scope.TryGetCapturedDisplayContext(range) + member _.ImportILType(ty: ILType) = + scopeOptX |> Option.map _.ImportILType(ty) + member _.GetAllUsesOfAllSymbolsInFile(?cancellationToken: CancellationToken) = match details with | None -> Seq.empty diff --git a/src/Compiler/Service/FSharpCheckerResults.fsi b/src/Compiler/Service/FSharpCheckerResults.fsi index 25c38a49d5..d602c7ab1d 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fsi +++ b/src/Compiler/Service/FSharpCheckerResults.fsi @@ -274,6 +274,9 @@ type public FSharpCheckFileResults = member TryGetCapturedType: range -> FSharpType option member TryGetCapturedDisplayContext: range -> FSharpDisplayContext option + /// Imports a compiled type for subsequent Symbols API use + member ImportILType: ILType -> FSharpType option + /// Get the items for a declaration list /// /// diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl index 1954ef2367..0743081221 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl @@ -2085,6 +2085,7 @@ FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FShar FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpDisplayContext] TryGetCapturedDisplayContext(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpImplementationFileContents] ImplementationFile FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpImplementationFileContents] get_ImplementationFile() +FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpType] ImportILType(ILType) FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Symbols.FSharpType] TryGetCapturedType(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.ISourceText] GenerateSignature(Microsoft.FSharp.Core.FSharpOption`1[System.Int32]) FSharp.Compiler.CodeAnalysis.FSharpCheckFileResults: Microsoft.FSharp.Core.FSharpOption`1[Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.CodeAnalysis.FSharpSymbolUse]] GetMethodsAsSymbols(Int32, Int32, System.String, Microsoft.FSharp.Collections.FSharpList`1[System.String])