diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md index 7256a47504c..6d84886e0ed 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -18,6 +18,7 @@ * Fix active pattern typechecking regression. ([Issue #18638](https://github.com/dotnet/fsharp/issues/18638), [PR #18642](https://github.com/dotnet/fsharp/pull/18642)) * Fix nullness warnings when casting non-nullable values to `IEquatable` to match C# behavior. ([Issue #18759](https://github.com/dotnet/fsharp/issues/18759)) * Fix IsByRefLikeAttribute types being incorrectly suppressed in completion lists. Types like `Span` and `ReadOnlySpan` now appear correctly in IntelliSense. +* Fix Show XML doc for enum fields in external metadata ([Issue #17939](https://github.com/dotnet/fsharp/issues/17939#issuecomment-3137410105), [PR #18800](https://github.com/dotnet/fsharp/pull/18800)) ### Changed * Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645)) diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 7dca2705946..66b26e43a91 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -305,7 +305,7 @@ module internal PrintUtilities = let layoutXmlDocOfILFieldInfo (denv: DisplayEnv) (infoReader: InfoReader) (finfo: ILFieldInfo) restL = if denv.showDocumentation then GetXmlDocSigOfILFieldInfo infoReader Range.range0 finfo - |> layoutXmlDocFromSig denv infoReader true XmlDoc.Empty restL + |> layoutXmlDocFromSig denv infoReader true XmlDoc.Empty restL else restL @@ -465,9 +465,11 @@ module PrintIL = | None -> WordL.equals ^^ (comment "value unavailable") | Some s -> WordL.equals ^^ wordL s - let layoutILEnumCase nm litVal = + let layoutILEnumCase nm litVal xmlDocOpt = let nameL = ConvertLogicalNameToDisplayLayout (tagEnum >> wordL) nm - WordL.bar ^^ nameL ^^ layoutILFieldInit litVal + match xmlDocOpt with + | Some layout -> layout @@ (WordL.bar ^^ nameL ^^ layoutILFieldInit litVal) + | None -> WordL.bar ^^ nameL ^^ layoutILFieldInit litVal module PrintTypes = // Note: We need nice printing of constants in order to print literals and attributes @@ -2108,9 +2110,8 @@ module TastDefinitionPrinting = let ilFieldsL = ilFields - |> List.map (fun x -> (true, x.IsStatic, x.FieldName, 0, 0), layoutILFieldInfo denv infoReader m x) - |> List.sortBy fst - |> List.map snd + |> List.sortBy (fun x -> x.IsStatic, x.FieldName) + |> List.map (fun x -> layoutILFieldInfo denv infoReader m x) let staticVals = if isRecdTy g ty then @@ -2225,6 +2226,14 @@ module TastDefinitionPrinting = else (lhsL ^^ WordL.equals) -* rhsL + let tryGetFieldXml (layoutList: Layout list) idxOpt = + match idxOpt with + | Some i when i >= 0 && i < layoutList.Length -> + match layoutList[i] with + | Node (Node (_, right, _), _, _) -> Some right + | _ -> None + | _ -> None + let typeDeclL = match repr with @@ -2327,9 +2336,14 @@ module TastDefinitionPrinting = |> addLhs | TILObjectRepr _ when tycon.ILTyconRawMetadata.IsEnum -> - infoReader.GetILFieldInfosOfType (None, ad, m, ty) - |> List.filter (fun x -> x.FieldName <> "value__") - |> List.map (fun x -> PrintIL.layoutILEnumCase x.FieldName x.LiteralValue) + let ilFieldsSorted = + ilFields + |> List.sortBy (fun x -> x.IsStatic, x.FieldName) + infoReader.GetILFieldInfosOfType (None, ad, m, ty) + |> List.filter (fun (x: ILFieldInfo) -> x.FieldName <> "value__") + |> List.map (fun (x: ILFieldInfo) -> + let xmlDocOpt = List.tryFindIndex (fun (e: ILFieldInfo) -> e.FieldName = x.FieldName) ilFieldsSorted |> tryGetFieldXml ilFieldsL + PrintIL.layoutILEnumCase x.FieldName x.LiteralValue xmlDocOpt) |> applyMaxMembers denv.maxMembers |> aboveListL |> addLhs diff --git a/tests/FSharp.Compiler.Service.Tests/Symbols.fs b/tests/FSharp.Compiler.Service.Tests/Symbols.fs index 72df8fa58cc..44dc501458d 100644 --- a/tests/FSharp.Compiler.Service.Tests/Symbols.fs +++ b/tests/FSharp.Compiler.Service.Tests/Symbols.fs @@ -1249,3 +1249,19 @@ module Delegates = symbols["EventHandler"].IsDelegate |> shouldEqual true symbols["Action"].IsDelegate |> shouldEqual true + +module MetadataAsText = + [] + let ``TryGetMetadataAsText returns metadata for external enum field`` () = + let _, checkResults = getParseAndCheckResults """ +let test = System.DateTimeKind.Utc +""" + let symbolUse = checkResults |> findSymbolUseByName "DateTimeKind" + match symbolUse.Symbol with + | :? FSharpEntity as symbol -> + match symbol.TryGetMetadataText() with + | Some metadataText -> + metadataText.ToString() |> shouldContain "The time represented is UTC" + | None -> + failwith "Expected metadata text, got None" + | _ -> failwith "Expected FSharpEntity symbol" \ No newline at end of file diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl index 616742054b4..b80ab919a7a 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl @@ -60,7 +60,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CompilerConfig+TcConfig::.ctor([FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, bool)][offset 0x00000634][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.PatternMatchCompilation::isProblematicClause([FSharp.Compiler.Service]FSharp.Compiler.PatternMatchCompilation+MatchClause)][offset 0x00000065][found Byte] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.PatternMatchCompilation::.cctor()][offset 0x00000015][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2070-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000BE][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2072-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000BE][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+PrintUtilities::layoutXmlDoc([FSharp.Compiler.Service]FSharp.Compiler.TypedTreeOps+DisplayEnv, bool, [FSharp.Compiler.Service]FSharp.Compiler.Xml.XmlDoc, [FSharp.Compiler.Service]FSharp.Compiler.Text.Layout)][offset 0x00000033][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateNamespaceName(string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string)][offset 0x00000063][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateExpectedName([FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string[], string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1)][offset 0x000000AD][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl index c7871e0fe77..b807dac2981 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl @@ -65,7 +65,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.IlxGen::HashRangeSorted([S.P.CoreLib]System.Collections.Generic.IDictionary`2>)][offset 0x00000012][found ref '[FSharp.Compiler.Service]FSharp.Compiler.IlxGen+HashRangeSorted@1875'][expected ref '[FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,T0>'] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.PatternMatchCompilation::isProblematicClause([FSharp.Compiler.Service]FSharp.Compiler.PatternMatchCompilation+MatchClause)][offset 0x00000040][found Byte] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.PatternMatchCompilation::.cctor()][offset 0x0000000B][found Boolean] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2070-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000B3][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2072-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000B3][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+PrintUtilities::layoutXmlDoc([FSharp.Compiler.Service]FSharp.Compiler.TypedTreeOps+DisplayEnv, bool, [FSharp.Compiler.Service]FSharp.Compiler.Xml.XmlDoc, [FSharp.Compiler.Service]FSharp.Compiler.Text.Layout)][offset 0x00000034][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateNamespaceName(string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string)][offset 0x00000074][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateExpectedName([FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string[], string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1)][offset 0x000000A8][found Char] Unexpected type on the stack.