Skip to content

Commit

Permalink
Make [omit] work when markDownComments is false. Fail early when we c…
Browse files Browse the repository at this point in the history
…annot get the attributes of the current member.
  • Loading branch information
matthid committed Sep 19, 2015
1 parent 5d4b440 commit 40797b0
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 29 deletions.
36 changes: 22 additions & 14 deletions src/FSharp.MetadataFormat/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FSharpAttribute>) =
Expand Down Expand Up @@ -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<RequireQualifiedAccessAttribute> 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
Expand All @@ -352,8 +355,7 @@ module ValueReader =
// Ordinary instance members
| _, true, _, name -> name + (defaultArg parArgs "(...)")
// Ordinary functions or values
| false, _, _, name when
not (hasAttrib<RequireQualifiedAccessAttribute> 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 "(...)")
Expand Down Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion tests/FSharp.MetadataFormat.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,41 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.diagnostics>
<sources>
<source name="FSharp.Formatting"
switchName="sourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="consoleListener"/>
<remove name="Default"/>
</listeners>
</source>
<source name="Yaaf.FSharp.Scripting"
switchName="sourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="consoleListener"/>
<remove name="Default"/>
</listeners>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="All"/>
</switches>
<sharedListeners>
<add name="consoleListener"
type="System.Diagnostics.ConsoleTraceListener">
<filter type="System.Diagnostics.EventTypeFilter"
initializeData="Information"/>
</add>
</sharedListeners>
</system.diagnostics>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0-4.3.0.0" newVersion="4.3.1.0" />
<bindingRedirect oldVersion="2.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="CommandLine" publicKeyToken="de6f01bd326f8c32" culture="neutral" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.Formatting.Common\FSharp.Formatting.Common.fsproj">
<Name>FSharp.Formatting.Common</Name>
<Project>{91bad90e-bf3b-4646-a1a7-1568f8f25075}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\src\FSharp.MetadataFormat\FSharp.MetadataFormat.fsproj">
<Name>FSharp.MetadataFormat</Name>
<Project>{bc4946ba-2724-4524-ac50-dfc49ee154a1}</Project>
Expand Down
42 changes: 29 additions & 13 deletions tests/FSharp.MetadataFormat.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ let removeWhiteSpace (str:string) =
str.Replace("\n", "").Replace("\r", "").Replace(" ", "")

[<Test>]
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) ]

Expand Down Expand Up @@ -119,14 +120,15 @@ let ``MetadataFormat works on two sample F# assemblies``() =
#endif

[<Test>]
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)
Expand Down Expand Up @@ -268,7 +270,7 @@ let ``MetadataFormat test that csharp (publiconly) support works``() =
#endif


[<Ignore>]
[<Ignore>] // Ignored because publicOnly=false is currently not working, see https://github.com/tpetricek/FSharp.Formatting/pull/259
[<Test>]
let ``MetadataFormat test that csharp support works``() =
let libraries =
Expand Down Expand Up @@ -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"

[<Test>]
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) ]

Expand All @@ -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 "<a href=\"fslib-nested.html\">Nested</a>"


open System.Diagnostics
open FSharp.Formatting.Common

[<Test>]
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
36 changes: 35 additions & 1 deletion tests/FSharp.MetadataFormat.Tests/files/FsLib/Library2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,38 @@ type Test_Issue287 () =
/// Function Foo!
abstract member Foo: int-> unit
/// Empty function for signature
default x.Foo a = ()
default x.Foo a = ()

type ITestInterface =
abstract Test : unit -> RazorEngine.Templating.IRazorEngineService
abstract FixScript : string -> string

/// Issue 201 docs
[<System.Runtime.CompilerServices.Extension>]
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
[<System.Runtime.CompilerServices.Extension>]
let MyExtension (o : ITestInterface) =
ignore <| o.Test().GetKey(null)

[<AutoOpen>]
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 = ()

0 comments on commit 40797b0

Please sign in to comment.