Skip to content

Commit 8f69348

Browse files
codingupastormbettinaheim
authored andcommitted
Fix for doc generation failing on repeated compilations (microsoft#242)
1 parent 1239a01 commit 8f69348

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/QsCompiler/DocumentationParser/DocNamespace.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,21 @@ string GetItemUid(YamlNode item)
220220
}
221221
}
222222

223-
// Now add our new items
223+
// Now add our new items, overwriting if they already exist
224224
foreach (var item in items)
225225
{
226226
var typeKey = ToSequenceKey(item.ItemType);
227227
SortedDictionary<string, YamlNode> typeList;
228228
if (itemTypeNodes.TryGetValue(typeKey, out typeList))
229229
{
230-
typeList.Add(item.Uid, item.ToNamespaceItem());
230+
if (typeList.ContainsKey(item.Uid))
231+
{
232+
// TODO: Emit a warning log / diagnostic. What is the accepted way to do that here?
233+
// $"Documentation for {item.Uid} already exists in this folder and will be overwritten.
234+
// It's recommended to compile docs to a new folder to avoid deleted files lingering."
235+
}
236+
237+
typeList[item.Uid] = item.ToNamespaceItem();
231238
}
232239
}
233240

src/QsCompiler/Tests.Compiler/CommandLineTests.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ let ``generate docs`` () =
180180
Assert.True (existsAndNotEmpty nsDoc)
181181
Assert.True (existsAndNotEmpty opDoc)
182182

183+
// Verify that we can compile repeatedly without errors despite docs already existing.
184+
let result2 = Program.Main args
185+
Assert.Equal(ReturnCode.SUCCESS, result2)
186+
Assert.True (existsAndNotEmpty toc)
187+
Assert.True (existsAndNotEmpty nsDoc)
188+
Assert.True (existsAndNotEmpty opDoc)
189+
183190

184191
[<Fact>]
185192
let ``find path relative`` () =

0 commit comments

Comments
 (0)