Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item access not only with variables #205

Open
echasnovski opened this issue Apr 18, 2020 · 1 comment
Open

Item access not only with variables #205

echasnovski opened this issue Apr 18, 2020 · 1 comment
Assignees

Comments

@echasnovski
Copy link

@echasnovski echasnovski commented Apr 18, 2020

Using item access with anything other than a variable isn't recognized as item access.

I have set "punctuation.definition.arguments" to a custom color in order to highlight brackets and parenthesis only if they are used for item access and function call respectively. However, it doesn't work in all cases when item access is actually done.

  • Editor name and version: VS Code 1.44.1
  • Platform: Ubuntu 18.04
  • Color scheme: Customized "Solarized Dark" (color of "punctuation.definition.arguments" is set to "#b58900")
  • MagicPython version: the one shipped with VS Code
  • A sreenshot:
    magicpython_item-access
    Expectation here is that all cases of [0] should have colored brackets.
  • 5-10 lines of surrounding code:
x = [1, 2, 3]
x[0]
sorted(x, reverse=True)[0]
(x)[0]
(sorted(x))[0]
("a", "b")[0]
["a", "b"][0]
{0: "a", 1: "b"}[0]

I can see that solving this might be tricky, but highly appreciated.

Afterthought: Seems like detecting item accessing can be done by the rule "if ['s first preceding non-blank character is present and is not operator". All other cases of [ is a list creation. However, capturing object which items are accessed is challenging with regular expressions.

@vpetrovykh
Copy link
Member

@vpetrovykh vpetrovykh commented May 1, 2020

I can use a trick similar to the one for detecting function calls and kwargs when they aren't preceded by a plain function name. So I should be able to distinguish the array literals from item access that way in most cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.