samwillis / python-inline-source

Python Inline Source Syntax Highlighting Using Type Annotations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

judfs opened this issue · comments

commented

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.

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.