Skip to content

Commit 74f1dc8

Browse files
authored
Fix garbage text in markdown help heading for template-expanded options (#10096)
Fixes #10084 The markdown help output (`slangc -help-style markdown -h`) listed all expanded names in `###` headings for template-expanded options. For `-<compiler>-path`, this produced a heading with 14 compiler-specific names (`-none-path, -fxc-path, -dxc-path, ...`), rendering as unreadable garbage in the Downstream section of the docs. The same issue affected `-fvk-<vulkan-shift>-shift` with 4 expanded names. The text writer already handles this correctly by using the usage string instead of the expanded names. The markdown writer had no way to distinguish template-expanded names from regular aliases (e.g. `-h, -help, --help`). This adds a `displayName` field to `CommandOptions::Option` that separates the display heading from the lookup names. Template-expanded options set `displayName` to the template form (e.g. `-<compiler>-path`), while alias options leave it empty and continue to list all names in the heading. The markdown writer uses `displayName` when set, and falls back to listing all names otherwise.
1 parent db7cd04 commit 74f1dc8

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

docs/command-line-slangc-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Make data accessed through ConstantBuffer, ParameterBlock, StructuredBuffer, Byt
490490

491491

492492
<a id="fvk-b-shift"></a>
493-
### -fvk-b-shift, -fvk-s-shift, -fvk-t-shift, -fvk-u-shift
493+
### -fvk-&lt;vulkan-shift&gt;-shift
494494

495495
**-fvk-&lt;[vulkan-shift](#vulkan-shift)&gt;-shift &lt;N&gt; &lt;space&gt;**
496496

@@ -621,7 +621,7 @@ Sets a comma-separates list of architecture-specific features for the LLVM targe
621621
Downstream compiler options
622622

623623
<a id="none-path"></a>
624-
### -none-path, -fxc-path, -dxc-path, -glslang-path, -spirv-dis-path, -clang-path, -visualstudio-path, -gcc-path, -genericcpp-path, -nvrtc-path, -llvm-path, -spirv-opt-path, -metal-path, -tint-path
624+
### -&lt;compiler&gt;-path
625625

626626
**-&lt;[compiler](#compiler)&gt;-path &lt;path&gt;**
627627

source/core/slang-command-options-writer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,14 @@ void MarkdownCommandOptionsWriter::_appendDescriptionForCategory(Index categoryI
352352
}
353353

354354
m_builder << "### ";
355-
StringUtil::join(names.getBuffer(), names.getCount(), toSlice(", "), m_builder);
355+
if (option.displayName.getLength())
356+
{
357+
_appendEscapedMarkdown(option.displayName, m_builder);
358+
}
359+
else
360+
{
361+
StringUtil::join(names.getBuffer(), names.getCount(), toSlice(", "), m_builder);
362+
}
356363
m_builder << "\n";
357364

358365
if (option.usage.getLength())

source/core/slang-command-options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ void CommandOptions::add(
239239
const char* inName,
240240
const char* usage,
241241
const char* description,
242-
UserValue userValue)
242+
UserValue userValue,
243+
const char* displayName)
243244
{
244245
UnownedStringSlice nameSlice(inName);
245246

246247
Option option;
247248
option.categoryIndex = m_currentCategoryIndex;
249+
option.displayName = _addString(displayName);
248250
option.usage = _addString(usage);
249251
option.description = _addString(UnownedStringSlice(description));
250252
option.userValue = userValue;

source/core/slang-command-options.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ struct CommandOptions
8686
struct Option
8787
{
8888
UnownedStringSlice names; ///< Comma delimited list of names, first name is the default
89-
UnownedStringSlice usage; ///< Describes usage, can be empty
89+
UnownedStringSlice displayName; ///< Heading override for docs (e.g. template form); empty
90+
///< means use names
91+
UnownedStringSlice usage; ///< Describes usage, can be empty
9092
UnownedStringSlice description; ///< A description of usage
9193

9294
UserValue userValue = kInvalidUserValue;
@@ -118,7 +120,8 @@ struct CommandOptions
118120
const char* name,
119121
const char* usage,
120122
const char* description,
121-
UserValue userValue = kInvalidUserValue);
123+
UserValue userValue = kInvalidUserValue,
124+
const char* displayName = nullptr);
122125
void add(
123126
const UnownedStringSlice* names,
124127
Count namesCount,

source/slang/slang-options.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct Option
4646
const char* name;
4747
const char* usage = nullptr;
4848
const char* description = nullptr;
49+
const char* displayName = nullptr;
4950
};
5051

5152
enum class ValueCategory
@@ -101,8 +102,12 @@ static void _addOptions(const ConstArrayView<Option>& options, CommandOptions& c
101102
{
102103
for (auto& opt : options)
103104
{
104-
cmdOptions
105-
.add(opt.name, opt.usage, opt.description, CommandOptions::UserValue(opt.optionKind));
105+
cmdOptions.add(
106+
opt.name,
107+
opt.usage,
108+
opt.description,
109+
CommandOptions::UserValue(opt.optionKind),
110+
opt.displayName);
106111
}
107112
}
108113

@@ -698,7 +703,8 @@ void initCommandOptions(CommandOptions& options)
698703
"SPIR-V.rst#implicit-binding-number-assignment)\n"
699704
"* [GLSL "
700705
"wiki](https://github.com/KhronosGroup/glslang/wiki/"
701-
"HLSL-FAQ#auto-mapped-binding-numbers)\n"},
706+
"HLSL-FAQ#auto-mapped-binding-numbers)\n",
707+
"-fvk-<vulkan-shift>-shift"},
702708
{OptionKind::VulkanBindGlobals,
703709
"-fvk-bind-globals",
704710
"-fvk-bind-globals <N> <descriptor-set>",
@@ -803,7 +809,8 @@ void initCommandOptions(CommandOptions& options)
803809
"-<compiler>-path <path>",
804810
"Specify path to a downstream <compiler> "
805811
"executable or library.\n",
806-
UserValue(OptionKind::CompilerPath));
812+
UserValue(OptionKind::CompilerPath),
813+
"-<compiler>-path");
807814
}
808815

809816
const Option downstreamOpts[] = {

0 commit comments

Comments
 (0)