MagicStack / MagicStack/MagicPython

Syntax Highlighting regex+format strings (rf)

Open
#256 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.4k
Forks
98
PR merge metrics
No merged PRs in 30d

Description

* **Editor name and version**: VSCode 1.75.1
* **Platform**: macOS
* **Color scheme**: Dark+ (default)
* **MagicPython version**: 1.1.0
* **A sreenshot**:
![image](https://user-images.githubusercontent.com/34556033/221567736-26efec2a-83a0-4a69-a870-9551173f5311.png)
* **5-10 lines of surrounding code**:
```python
myString = "baz"
MYCONST = "qux"
myDict = {
"foo": "bar"
}

correctColoring = rf"(?=[\w]+){myString}{MYCONST}[\d]+"

incorrectDictionary = rf"(?=[\w]+){myDict['foo']}[\d]+"
regularFString = f"word{myDict['foo']}number"
```

This is a followup to #186. After upgrading to 1.1.0, I'm very excited that rf strings support both regex style and format string. In the attached screenshot, behold how correctly varied `correctColoring` is. However, any dictionary or class inside of the {} in an rf string is not colored correctly. See how `myDict['foo']` varies between `incorrectDictionary` and `regularFString`. The square brackets should be purple, and 'foo' orange, but instead it is all absorbed into red.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the rf-string examples in this issue and compare the highlighting behavior of myDict['foo'] with the regular f-string example. Review the implementation related to the follow-up in issue #186, reproduce the incorrect coloring in VSCode, and consider the issue done when dictionary or class expressions inside rf-string format fields are highlighted consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, vscode
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.