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

[Python] Decorator refactoring #743

Merged
merged 6 commits into from
Apr 5, 2017

Conversation

FichteFoll
Copy link
Collaborator

@FichteFoll FichteFoll commented Dec 19, 2016

Requires sublimehq/sublime_text#1190 to be fixed before merging!


When trying to implement proper scoping according to #709 and #737, I noticed that I would have to rebuild almost the entire function-calls scope for decorators only with different scope names. Since I religiously hate duplicated code (especially considering I would have to duplicate it twice), I worked on refactoring how qualified names are matched instead and qualified-name-until-leaf was born.

Unfortunately, it is affected by the bug described in sublimehq/sublime_text#1190 and thus is not ready to be merged yet. The following 17 failing tests should be fixed when this bug is fixed:

Packages/Python/syntax_test_python.py:102:2: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:3: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:4: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:5: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:6: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:7: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:8: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:9: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:102:10: [meta.qualified-name variable.function] does not match scope [source.python meta.function-call.python]
Packages/Python/syntax_test_python.py:508:7: [meta.annotation] does not match scope [source.python invalid.illegal.character.python]
Packages/Python/syntax_test_python.py:508:8: [meta.annotation] does not match scope [source.python]
Packages/Python/syntax_test_python.py:508:9: [meta.annotation] does not match scope [source.python]
Packages/Python/syntax_test_python.py:508:6: [meta.qualified-name variable.annotation.function] does not match scope [source.python meta.annotation.python meta.annotation.python meta.qualified-name.python]
Packages/Python/syntax_test_python.py:508:7: [meta.qualified-name variable.annotation.function] does not match scope [source.python invalid.illegal.character.python]
Packages/Python/syntax_test_python.py:508:8: [meta.qualified-name variable.annotation.function] does not match scope [source.python]
Packages/Python/syntax_test_python.py:508:9: [meta.qualified-name variable.annotation.function] does not match scope [source.python]
Packages/Python/syntax_test_python.py:520:10: [invalid.illegal.character] does not match scope [source.python meta.structure.list.python punctuation.section.list.begin.python]
FAILED: 17 of 3525 assertions in 2 files failed

Note: I am unsure if I split the commits correctly (and tests are passing after each of them).

Also called "qualified names", just like the context is called now.

Additionally, add meta scopes for qualified names and generic names for
more precise testing.
... and use it to match function calls less explicitly and more
magically. Usually you would think this is bad, but it's not because
it's not really less explicit. It just avoids repetition when scoping
the last (non-special) part of a qualified name with a name other than
"meta.generic-name".

This change triggers the bug described in
sublimehq/sublime_text#1190, where the
most-inner context in a multi-push operation *must* match at least one
character before it can be popped.

Due this, the tests are currently *not* passing.
Adheres to conventions discussed in
sublimehq#709 and
sublimehq#737.
- match: (?=\.?\s*{{path}}\s*\() # now we do
set: [decorator-function-call-wrapper, qualified-name-until-leaf]
- match: (?=\.?\s*{{path}})
push: [decorator-wrapper, qualified-name-until-leaf]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this (and two lines above) is where you are pushing two contexts, the later of which does not consume anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. The latter may or may not consume something, but due to the bug it always consumes the first character.

@FichteFoll
Copy link
Collaborator Author

Note that after this is merged, https://github.com/FichteForks/Packages/tree/python_unpacking-operators can probably be merged too. It's been a while since I looked into this and I obviously can't test it myself.

@wbond wbond merged commit e63d477 into sublimehq:master Apr 5, 2017
@FichteFoll FichteFoll deleted the python_decorator-scopes branch April 5, 2017 03:10
deathaxe pushed a commit to deathaxe/sublime-packages that referenced this pull request Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants