Skip to content

Xml documentation comments imported into View Variables - #5430

Open
Mervill wants to merge 59 commits into
space-wizards:masterfrom
Mervill:vv-docstring
Open

Mervill wants to merge 59 commits into
space-wizards:masterfrom
Mervill:vv-docstring

Conversation

@Mervill

@Mervill Mervill commented Sep 8, 2024 •

Copy link
Copy Markdown
Member

2024-09-06 22_10_55-Space Station 14

Overview

Adds code that can read the xml files generated by C# documentation comments and display those comments (currently the <summary> block) below types and variables in View Variables windows.

This PR doesn't (yet) actually toggle the xml doc file generation. You should add <GenerateDocumentationFile>True</GenerateDocumentationFile> to the csproj of the project you want to generate docs for then copy the resulting xml file into Resources/ViewVariables. You can use this to test this PR with the xml docs from content as well.

I will do a content PR when this gets merged but to test you need to add:

    <ViewVariables>true</ViewVariables>

to the Content csproj files to get them generating the doc files correctly.

The xml docs are a little big, and they contain a bunch of info we're never going to use like function documentation. It wouldn't be to hard to have a script that discards unneeded entries to optimize the size of the resulting files.

All the individual doc strings are loaded from the client resources folder, we don't send the doc strings over the network.

XML docs generated for server dlls get generated into /Resources/Server/ and that file is ignored during the client content build. Server docs get sent over the wire to users with VV access. Client and Shared xml docs get bundled into the client content package and are thus always visible.

Since this info comes from the code (just like the type and variable names) we can't really expect to localize this text. That may be a deal-breaker.

TODO

  • fix xml tags inside the <summary> block breaking the doc string.
    • Most of the tags are now good enough, I would like to try implementing <inheritdoc/> but it might be in a follow-up PR.
  • actually add <GenerateDocumentationFile> to the csproj files.
    • I spent some time in the MSBuild mines and I found a way to get the xml doc to write to the Resources folder cleanly. Right now it's only enabled for the Robust DLLS. If you want to test it locally you can add <ViewVariables>true</ViewVariables> to the Content DLLS. You may need to an an empty Resources\ViewVariables\ folder for the build to work properly.
  • post-compile script to move the generated xml files into the Resources folder
    • See above.
  • post-compile process to trim down the size of the xml files (discard all method definitions)
    • XmlDocTool implemented and working 👍
  • Add support for <viewvariables> block inside the xml comments that can add docs tailor-made for vv

[ ] cleaner code
[ ] (?) CVar config?
[ ] (?) Improve the UI slightly to better accommodate the new doc strings

@EmoGarbage404

Copy link
Copy Markdown
Contributor

images

@Mervill

Mervill commented Sep 10, 2024

Copy link
Copy Markdown
Member Author

vv-list

@mirrorcult

Copy link
Copy Markdown
Contributor

insanely zased

@mirrorcult

Copy link
Copy Markdown
Contributor

xmldoc should probably be gitignored since it'll be regenerated anyway

@Mervill

Mervill commented Sep 10, 2024 •

Copy link
Copy Markdown
Member Author

xmldoc should probably be gitignored since it'll be regenerated anyway

Yes I was hoping someone would weigh in on this. If we want to do this we need a way to keep Resources\ViewVariables from being deleted since the build script can't (yet?) create the folder if it does not exist.

@Mervill

Mervill commented Sep 10, 2024 •

Copy link
Copy Markdown
Member Author

Actually scratch that last, I can make msbuild create the folder apparently

@Mervill
Mervill removed the request for review from PJB3005 August 25, 2026 21:21
@Mervill
Mervill force-pushed the vv-docstring branch 2 times, most recently from c1401b3 to 8e21e9e Compare October 16, 2026 00:10

@metalgearsloth metalgearsloth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@Mervill

Mervill commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

2026 Update

I didn't manage to prepare in time for the Sep 7th anniversary of the original pr. c'est la vive.

The configuration instruction for this is now simply to add:

<ViewVariables>true</ViewVariables>

To a csproj to have it's xml generated and loaded into VV.

  • Client and Shared xml is copied to /Resources/ViewVariables/ and that xml can be inspected by clients directily (like client and shared dlls).
  • Server xml is copied to /Resources/Server/ViewVariables/ and /Resources/Server/ is ignored by the client packager. Server XML is then sent on-demand to clients that have VV permissions. This should resolve the issues around leaking the docs to unauthorized parties.
  • Copying is based on a dll ending with .Server but you can manually toggle the behavior with <ViewVariablesServerOnly>true</ViewVariablesServerOnly>

Inflates the warning count to 681. Due to some xml in the project being invalid. I have a follow up PR to address most of these. We ignore CS1591;CS1573 for now because we don't yet require xml docs. The warnings that show up now are broken formatting / bad references in xml.

@Fildrance Fildrance self-assigned this Oct 28, 2026
This is required to stop everything from wobbling when XMLDoc is too
long, and makes sure it's always displaying everything.
Bold looked back, DarkGray was good, just now using white more.

@Fildrance Fildrance left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so my comments are mostly minor things, there are several things up in the air but considering this is quite niche feature and it is okay to drop it as a matter of graceful degradation (i wish we had one for perf but i mean feature-richness wise, if it crashes of fails - not so much of a problem, game is still playable, unless it crashes the game).

I got a little bit tired to the end of the thing, and i felt really lacking in understanding what is multithread-threat engine-wise there, and what is okay to be - i know a lot of stuff is running on single thread, but there are async interactions, but i am just lacking knowledge on how generally engine works thread-wise (considering access to stuff like UI elements from different threads, etc). I feel like engine in general does not have PROPER tooling to do what you are doing, but building full idiot-proof infrastructure just for that feature seams insane, so i guess we are fine there?

Its nice if you could apply some stuff i proposed, and we could try think about solutions to problems i mentioned, or they could be not really a problem <_<

Comment thread Robust.XmlDocTool/Program.cs Resolved
Comment thread Robust.XmlDocTool/Program.cs Resolved
Comment thread Robust.XmlDocTool/XmlUtil.cs Resolved
Comment thread Robust.XmlDocTool/Program.cs Resolved
Comment thread Robust.XmlDocTool/XmlUtil.cs Resolved
Comment on lines +46 to +47
var missingKeys = new List<string>();
var missingIdx = new List<int>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be better to use HashSet for those?


if (missingKeys.Count == 0 || !_netManager.IsConnected)
{
foreach (var i in missingIdx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if missingKeys.Count == 0 , then missingIdx is empty, so that loop would effectively is doing nothing (probably separate early return is better?). And i am a bit confused how _netManager.IsConnected flag is working here... why would we need to do any of this if we are not connected?

{
var count = Math.Min(MsgViewVariablesReqDocStrings.MaxKeys, missingKeys.Count - start);
var chunk = missingKeys.GetRange(start, count);
var remote = await RequestDocStrings(kind, chunk);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose naming it promise or task, or something along those lines.

{
var count = Math.Min(MsgViewVariablesReqDocStrings.MaxKeys, missingKeys.Count - start);
var chunk = missingKeys.GetRange(start, count);
var remote = await RequestDocStrings(kind, chunk);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having no parallelism here is a bit odd. Should there be? From what i see that should not really be a problem, and doing parallelism here would be a dirty thing in itself, not trivial. Considering the only thing that currently would ask for batches is server-side components... should not be a problem i presume?


for (var i = 0; i < targets.Count; i++)
{
targets[i].Apply(docStrings[i]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this can contain basically anything - i would propose a bit of redundancy - wrapping whole thing in try-catch and logging any suspicious stuff. Otherwise async void method will fall silently and you will never know whats going on.

Fildrance

This comment was marked as duplicate.

@Aeshus

Aeshus commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
image

Here's the stylistic changes we discussed in the Discord.

As a future TODO that I didn't have time to complete (non-blocking):

  • Have the header also use a collapsible so that the docs there are hidden unless you click to expand them. Also fix the word clipping and the label stuff that it currently is doing.
  • Also make sure the header documentation text is using a RichTextLabel

This did require exposing the CollapsibleHeading's internal BoxContainer, but that's a fine change IMO and is useful for other things.

Also, this required the VV window to disable horizontal scrolling as otherwise text would not wrap.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants