python f-string auto close (match bracket)

What is the best way to do the following?

  1. auto close f-strings - i.e. f"f"|"
  2. same question raw-strings (r"") and byte-strings (b"") and valid combinations (e.g. rf"")
  3. same question for triple quotes (including f-triple-quotes, r-triple-quotes, b-triple-quotes, etc)

I noticed that this commit removed auto-closing of brackets inside string literals.

What if this is was my preference (in python)?
Bonus - or if it’s only my preference inside f-string literals?

This wasn’t implemented, but this patch adds the necessary logic.

Add language data for Python that sets the closeBrackets.before option to something else.

1 Like

What’s the API for adding language data?
I had a look but I couldn’t see anything obvious.

Any chance of a minor version bump re the autocomplete closeBrackets patch :slightly_smiling_face:

Something like{closeBrackets: {...}}) with a higher precedence than the python language itself.

I’ve bumped @codemirror/autocomplete and @codemirror/lang-python

1 Like

Tried the bumped versions and currently behaviour closes on the second quote i.e.
f" doesn’t close but f""f""|"

I also have to change the order of the brackets for triple quotes to work:
brackets: ["(", "[", "{", "'", '"', "'''", '"""']brackets: ["(", "[", "{", "'''", '"""', "'", '"']

Odd. For me it closes on the first quote. And the order of the brackets should not be significant. Could you double check your observation and provide reproducing code?

1 Like

Ah - I hadn’t realised that if I used{closeBrackets: {...}})
I needed to override the entire closeBrackets object and not just {closeBrackets: {before: ...}}