From 40797b0bc1cb1fc39904f26035da294b5603549c Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sat, 19 Sep 2015 21:52:58 +0200 Subject: [PATCH] Make [omit] work when markDownComments is false. Fail early when we cannot get the attributes of the current member. --- src/FSharp.MetadataFormat/Main.fs | 36 +++++++++------- tests/FSharp.MetadataFormat.Tests/App.config | 32 +++++++++++++- .../FSharp.MetadataFormat.Tests.fsproj | 5 +++ tests/FSharp.MetadataFormat.Tests/Tests.fs | 42 +++++++++++++------ .../files/FsLib/Library2.fs | 36 +++++++++++++++- 5 files changed, 122 insertions(+), 29 deletions(-) diff --git a/src/FSharp.MetadataFormat/Main.fs b/src/FSharp.MetadataFormat/Main.fs index e23b81380..f28f7c2eb 100644 --- a/src/FSharp.MetadataFormat/Main.fs +++ b/src/FSharp.MetadataFormat/Main.fs @@ -214,7 +214,7 @@ module ValueReader = let uncapitalize (s:string) = s.Substring(0, 1).ToLowerInvariant() + s.Substring(1) - let isAttrib<'T> (attrib: FSharpAttribute) = + let isAttrib<'T> (attrib: FSharpAttribute) = attrib.AttributeType.CompiledName = typeof<'T>.Name let hasAttrib<'T> (attribs: IList) = @@ -338,9 +338,12 @@ module ValueReader = | Some loc -> Some loc | None -> symbol.DeclarationLocation - let readMemberOrVal (ctx:ReadingContext) (v:FSharpMemberOrFunctionOrValue) = + let readMemberOrVal (ctx:ReadingContext) (v:FSharpMemberOrFunctionOrValue) = + // we calculate this early just in case this fails with an FCS error. + let requireQualifiedAccess = + hasAttrib v.LogicalEnclosingEntity.Attributes + let buildUsage (args:string option) = - let tyname = v.LogicalEnclosingEntity.DisplayName let parArgs = args |> Option.map (fun s -> if String.IsNullOrWhiteSpace(s) then "" elif s.StartsWith("(") then s @@ -352,8 +355,7 @@ module ValueReader = // Ordinary instance members | _, true, _, name -> name + (defaultArg parArgs "(...)") // Ordinary functions or values - | false, _, _, name when - not (hasAttrib v.LogicalEnclosingEntity.Attributes) -> + | false, _, _, name when not <| requireQualifiedAccess -> name + " " + (defaultArg args "(...)") // Ordinary static members or things (?) that require fully qualified access | _, _, _, name -> name + (defaultArg parArgs "(...)") @@ -577,23 +579,29 @@ module Reader = dict[], Comment.Empty else dict[], (Comment.Create ("", el.Value, [])) - else - if ctx.MarkdownComments then - let lines = removeSpaces sum.Value - let cmds = new System.Collections.Generic.Dictionary<_, _>() - let text = - lines |> Seq.filter (function + else + let lines = removeSpaces sum.Value + let cmds = new System.Collections.Generic.Dictionary<_, _>() + let findCommand = (function | String.StartsWithWrapped ("[", "]") (ParseCommand(k, v), rest) -> + Some (k, v) + | _ -> None) + if ctx.MarkdownComments then + let text = + lines |> Seq.filter (findCommand >> (function + | Some (k, v) -> cmds.Add(k, v) false - | _ -> true) |> String.concat "\n" + | _ -> true)) |> String.concat "\n" let doc = Literate.ParseMarkdownString ( text, path=Path.Combine(ctx.AssemblyPath, "docs.fsx"), formatAgent=ctx.FormatAgent, compilerOptions=ctx.CompilerOptions ) cmds :> IDictionary<_, _>, readMarkdownComment doc - else - let cmds = new System.Collections.Generic.Dictionary<_, _>() + else + lines + |> Seq.choose findCommand + |> Seq.iter (fun (k, v) -> cmds.Add(k,v)) cmds :> IDictionary<_, _>, readXmlComment ctx.UrlMap sum let readComment ctx xmlSig = readCommentAndCommands ctx xmlSig |> snd diff --git a/tests/FSharp.MetadataFormat.Tests/App.config b/tests/FSharp.MetadataFormat.Tests/App.config index 060643e7f..4e1805713 100644 --- a/tests/FSharp.MetadataFormat.Tests/App.config +++ b/tests/FSharp.MetadataFormat.Tests/App.config @@ -3,11 +3,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/tests/FSharp.MetadataFormat.Tests/FSharp.MetadataFormat.Tests.fsproj b/tests/FSharp.MetadataFormat.Tests/FSharp.MetadataFormat.Tests.fsproj index 6c04d0138..75ba61565 100644 --- a/tests/FSharp.MetadataFormat.Tests/FSharp.MetadataFormat.Tests.fsproj +++ b/tests/FSharp.MetadataFormat.Tests/FSharp.MetadataFormat.Tests.fsproj @@ -88,6 +88,11 @@ --> + + FSharp.Formatting.Common + {91bad90e-bf3b-4646-a1a7-1568f8f25075} + True + FSharp.MetadataFormat {bc4946ba-2724-4524-ac50-dfc49ee154a1} diff --git a/tests/FSharp.MetadataFormat.Tests/Tests.fs b/tests/FSharp.MetadataFormat.Tests/Tests.fs index 343ee70d3..23f0fdb0f 100644 --- a/tests/FSharp.MetadataFormat.Tests/Tests.fs +++ b/tests/FSharp.MetadataFormat.Tests/Tests.fs @@ -72,12 +72,13 @@ let removeWhiteSpace (str:string) = str.Replace("\n", "").Replace("\r", "").Replace(" ", "") [] -let ``MetadataFormat works on two sample F# assemblies``() = +let ``MetadataFormat works on two sample F# assemblies``() = + let binDir = root @@ "files" @@ "FsLib" @@ "bin" @@ "Debug" let libraries = - [ root @@ "files/FsLib/bin/Debug" @@ "FsLib1.dll" - root @@ "files/FsLib/bin/Debug" @@ "FsLib2.dll" ] + [ binDir @@ "FsLib1.dll" + binDir @@ "FsLib2.dll" ] let output = getOutputDir() - MetadataFormat.Generate(libraries, output, layoutRoots, info, libDirs = [root @@ "../../lib"]) + MetadataFormat.Generate(libraries, output, layoutRoots, info, libDirs = [binDir; root @@ "../../lib"]) let fileNames = Directory.GetFiles(output) let files = dict [ for f in fileNames -> Path.GetFileName(f), File.ReadAllText(f) ] @@ -119,14 +120,15 @@ let ``MetadataFormat works on two sample F# assemblies``() = #endif [] -let ``MetadataFormat generates Go to GitHub source links``() = +let ``MetadataFormat generates Go to GitHub source links``() = + let binDir = root @@ "files" @@ "FsLib" @@ "bin" @@ "Debug" let libraries = - [ root @@ "files/FsLib/bin/Debug" @@ "FsLib1.dll" - root @@ "files/FsLib/bin/Debug" @@ "FsLib2.dll" ] + [ binDir @@ "FsLib1.dll" + binDir @@ "FsLib2.dll" ] let output = getOutputDir() printfn "Output: %s" output MetadataFormat.Generate - ( libraries, output, layoutRoots, info, libDirs = [root @@ "../../lib"], + ( libraries, output, layoutRoots, info, libDirs = [binDir; root @@ "../../lib"], sourceRepo = "https://github.com/tpetricek/FSharp.Formatting/tree/master", sourceFolder = root @@ "../.." ) let fileNames = Directory.GetFiles(output) @@ -268,7 +270,7 @@ let ``MetadataFormat test that csharp (publiconly) support works``() = #endif -[] +[] // Ignored because publicOnly=false is currently not working, see https://github.com/tpetricek/FSharp.Formatting/pull/259 [] let ``MetadataFormat test that csharp support works``() = let libraries = @@ -392,10 +394,11 @@ let ``MetadataFormat processes C# properties on types and includes xml comments files.["manoli-utils-csharpformat-clikeformat.html"] |> should contain "Regular expression string to match single line and multi-line" [] -let ``MetadataFormat generates module link in nested types``() = - let library = root @@ "files/FsLib/bin/Debug" @@ "FsLib2.dll" +let ``MetadataFormat generates module link in nested types``() = + let binDir = root @@ "files/FsLib/bin/Debug" + let library = binDir @@ "FsLib2.dll" let output = getOutputDir() - MetadataFormat.Generate([library], output, layoutRoots, info, libDirs = [root @@ "../../lib"], markDownComments = true) + MetadataFormat.Generate([library], output, layoutRoots, info, libDirs = [binDir; root @@ "../../lib"], markDownComments = true) let fileNames = Directory.GetFiles(output) let files = dict [ for f in fileNames -> Path.GetFileName(f), File.ReadAllText(f) ] @@ -420,4 +423,17 @@ let ``MetadataFormat generates module link in nested types``() = // Check that nested submodules have links to its module files.["fslib-nested-submodule.html"] |> should contain "Parent Module:" files.["fslib-nested-submodule.html"] |> should contain "Nested" - \ No newline at end of file + +open System.Diagnostics +open FSharp.Formatting.Common + +[] +let ``MetadataFormat omit works without markdown``() = + let binDir = root @@ "files/FsLib/bin/Debug" + let library = binDir @@ "FsLib2.dll" + let output = getOutputDir() + MetadataFormat.Generate([library], output, layoutRoots, info, libDirs = [binDir; root @@ "../../lib"], markDownComments = false) + let fileNames = Directory.GetFiles(output) + let files = dict [ for f in fileNames -> Path.GetFileName(f), File.ReadAllText(f) ] + + files.ContainsKey "fslib-test_omit.html" |> should equal false diff --git a/tests/FSharp.MetadataFormat.Tests/files/FsLib/Library2.fs b/tests/FSharp.MetadataFormat.Tests/files/FsLib/Library2.fs index 4f9cc533e..c967f85e9 100644 --- a/tests/FSharp.MetadataFormat.Tests/files/FsLib/Library2.fs +++ b/tests/FSharp.MetadataFormat.Tests/files/FsLib/Library2.fs @@ -36,4 +36,38 @@ type Test_Issue287 () = /// Function Foo! abstract member Foo: int-> unit /// Empty function for signature - default x.Foo a = () \ No newline at end of file + default x.Foo a = () + +type ITestInterface = + abstract Test : unit -> RazorEngine.Templating.IRazorEngineService + abstract FixScript : string -> string + +/// Issue 201 docs +[] +module Test_Issue201 = + let internal notImpl () = + (raise <| System.NotSupportedException("Migration is not supported by this type, please implement GetMigrator.")) + : 'a + /// Test FixScript_MSSQL Documentation + let FixScript_MSSQL (script:string) = script + /// Test FixScript_MySQL Documentation + let FixScript_MySQL (script:string) = + script.Replace( + "from information_schema.columns where", + "FROM information_schema.columns WHERE table_schema = SCHEMA() AND") + + /// Extension docs + [] + let MyExtension (o : ITestInterface) = + ignore <| o.Test().GetKey(null) + +[] +module Test_Issue201Extensions = + type ITestInterface with + member x.MyExtension() = + Test_Issue201.MyExtension x + +/// [omit] +type Test_Omit() = + /// This Should not be displayed + member x.Foo a = () \ No newline at end of file