Skip to content

Commit f8c503c

Browse files
authored
UltiSnips: add an option to comment non-required options. (pearofducks#129)
Co-authored-by: Guillaume-Jean Herbiet <[email protected]>
1 parent 4ea551a commit f8c503c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Diff for: UltiSnips/generate.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def module_options_to_snippet_options(module_options: Any) -> List[str]:
220220

221221
# insert an empty option above the list of non-required options
222222
for index, (_, option) in enumerate(module_options):
223-
if not option.get("required"):
223+
if not option.get("required") and not args.comment_non_required:
224224
if index != 0:
225225
module_options.insert(index, (None, None))
226226
break
@@ -230,14 +230,19 @@ def module_options_to_snippet_options(module_options: Any) -> List[str]:
230230
if not name and not option_data:
231231
options += [""]
232232
else:
233+
# set comment character for non-required options
234+
if not option_data.get("required") and args.comment_non_required:
235+
comment = "#"
236+
else:
237+
comment = ""
233238
# the free_form option in some modules are special
234239
if name == "free_form":
235240
options += [
236-
f"\t${{{index}:{name}{delimiter}{option_data_to_snippet_completion(option_data)}}}"
241+
f"\t{comment}${{{index}:{name}{delimiter}{option_data_to_snippet_completion(option_data)}}}"
237242
]
238243
else:
239244
options += [
240-
f"\t{name}{delimiter}${{{index}:{option_data_to_snippet_completion(option_data)}}}"
245+
f"\t{comment}{name}{delimiter}${{{index}:{option_data_to_snippet_completion(option_data)}}}"
241246
]
242247

243248
return options
@@ -322,6 +327,12 @@ def get_collection_name(filepath:str) -> str:
322327
action="store_true",
323328
default=False
324329
)
330+
parser.add_argument(
331+
'--comment-non-required',
332+
help="Comment non-required options",
333+
action="store_true",
334+
default=False
335+
)
325336
args = parser.parse_args()
326337

327338

0 commit comments

Comments
 (0)