python-inline-source icon indicating copy to clipboard operation
python-inline-source copied to clipboard

Needs a space after `:` before the type to activate

Open judfs opened this issue 2 years ago • 5 comments

The extension does not work unless there is a space after the : that separates the variable name and the type name.

html = str
html_doc:html = """
<!DOCTYPE html>
"""
html_doc: html = """
<!DOCTYPE html>
"""

image

I was ready to assume the extension simply didn't work and was about to uninstall it, after already trying restarting vscode and opening and closing the file, but I happened to hit my format shortcut just before giving up on it.

judfs avatar Aug 08 '23 21:08 judfs

Regex for all types are stored in vscode-python-inline-source/syntaxes/python-inline-source.json file

For example: Regex for Markdown is

(:) ((((\\w+)(\\.))?(markdown|md))|((\")(markdown|md)(\"))|((')(markdown|md)('))) (=) ([bBrRuU]?f?)(\"{3})

In order to support both conditions, i.e. with and without spaces, we only need to make a small change to the regex and make the whitespace optional.

So, we can simply change it to

(:) ?((((\\w+)(\\.))?(markdown|md))|((\")(markdown|md)(\"))|((')(markdown|md)('))) (=) ([bBrRuU]?f?)(\"{3})

By adding ? after (:) we can fix the confusion, it should now work with and without a space. I'll be more than happy to open a PR for this but this looks like an abandoned project. I hope this info can help someone.

roushikk avatar Apr 08 '24 12:04 roushikk