Skip to content

Commit

Permalink
diag: Do not emit cross-file diag for single-file folders
Browse files Browse the repository at this point in the history
  • Loading branch information
artempyanykh committed Sep 8, 2022
1 parent f0bfcbc commit 098a7b8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Marksman/Diag.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ let checkNonBreakingWhitespace (doc: Doc) =

[ NonBreakableWhitespace(whitespaceRange) ])

let isCrossFileLink uref =
match uref with
| Uref.Doc _ -> true
| Uref.Heading(doc = Some _) -> true
| Uref.Heading(doc = None) -> false
| Uref.LinkDef _ -> false

let checkLink (folder: Folder) (doc: Doc) (link: Element) : seq<Entry> =
let uref = Uref.ofElement link

Expand All @@ -50,7 +57,9 @@ let checkLink (folder: Folder) (doc: Doc) (link: Element) : seq<Entry> =
| Some uref ->
let refs = Dest.tryResolveUref uref doc folder |> Array.ofSeq

if refs.Length = 1 then
if Folder.isSingleFile folder && isCrossFileLink uref then
[]
else if refs.Length = 1 then
[]
else if refs.Length = 0 then
match link with
Expand Down
5 changes: 5 additions & 0 deletions Marksman/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ module Folder =

let singleFile doc = SingleFile doc

let isSingleFile =
function
| SingleFile _ -> true
| MultiFile _ -> false

let multiFile name root docs = MultiFile(name, root, docs)

let docs: Folder -> seq<Doc> =
Expand Down
1 change: 1 addition & 0 deletions Marksman/Workspace.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Folder =

val singleFile: Doc -> Folder
val multiFile: name: string -> root: RootPath -> docs: Map<PathUri, Doc> -> Folder
val isSingleFile: Folder -> bool

val withDoc: Doc -> Folder -> Folder
val withoutDoc: PathUri -> Folder -> option<Folder>
Expand Down
17 changes: 17 additions & 0 deletions Tests/DiagTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,20 @@ let noDiagOnNonMarkdownFiles () =
"fake.md", "Link to non-existent document at 'another%20bad.md'" ],
diag
)

[<Fact>]
let noCrossFileDiagOnSingleFileFolders () =
let doc =
FakeDoc.Mk(
[| "[](bad.md)" //
"[[another-bad]]"
"[bad-ref][bad-ref]" |]
)

let folder = Folder.singleFile doc
let diag = checkFolder folder |> diagToHuman

Assert.Equal<string * string>(
[ "fake.md", "Link to non-existent link definition with the label 'bad-ref'" ],
diag
)

0 comments on commit 098a7b8

Please sign in to comment.