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

clear_scopes behaves differently with push/set #2530

Closed
deathaxe opened this issue Dec 22, 2018 · 6 comments
Closed

clear_scopes behaves differently with push/set #2530

deathaxe opened this issue Dec 22, 2018 · 6 comments

Comments

@deathaxe
Copy link
Collaborator

This issue may already be part of #2326 - not sure, but it adds a minimal test case to illustrate how clear_scopes: 1 behaves differently when using push or set. The attached test file fails at exactly one position.

The example scopes a function definition in two different ways. Functions starting with @ push the context to scope the parameter list to the stack while functions starting with $ set the context to stack to do the same.

As each function does only have one parameter list, using set makes somehow more sense as we want to pop off the param-... context as soon as the closing ) is matched and continue with the next one (which is meta in the example but could be an arbitrary list of contexts in real world).

Actual Behavior

clear_scope: 1 does not clear the meta.function.test scope from the opening (. Hence it contains both meta.function.test and meta.function.parameters.test.

The meta.function.test is already cleared from the closing ) for both push and set.

Expected Behavior

clear_scope: 1 should clear the meta.function.test scope from the opening ( so it contains only meta.function.parameters.test. This is the behavior when using push already. Both set and push should have the same result.

ClearScope.sublime-syntax

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
  - test
scope: source.test
contexts:
  main:
    - match: \@\w+
      scope: entity.name.function.test
      push:
        - meta
        - param-push

    - match: \$\w+
      scope: entity.name.function.test
      push:
        - meta
        - param-set

  param-push:
    - match: \(
      scope: punctuation.section.parameters.begin.test
      push:
        - clear_scopes: 1
        - meta_scope: meta.function.parameters.push.test
        - match: \)
          scope: punctuation.section.parameters.end.test
          pop: true
    - match: $|(?=\S)
      pop: true

  param-set:
    - match: \(
      scope: punctuation.section.parameters.begin.test
      set:
        - clear_scopes: 1
        - meta_scope: meta.function.parameters.set.test
        - match: \)
          scope: punctuation.section.parameters.end.test
          pop: true
    - match: $|(?=\S)
      pop: true

  meta:
    - meta_scope: meta.function.test
    - match: ''
      pop: true

Syntax Test

# SYNTAX TEST "ClearScope.sublime-syntax"

@fun(par)
#^^^ meta.function.test - meta.function.parameters.push.test
#   ^^^^^ meta.function.parameters.push.test - meta.function.test

$fun(par)
#^^^ meta.function.test - meta.function.parameters.set.test
#   ^^^^^ meta.function.parameters.set.test - meta.function.test

Console

Packages/User/syntax_test_clearscope.test:7:5: [meta.function.parameters.set.test - meta.function.test] does not match scope [source.test meta.function.test meta.function.parameters.set.test punctuation.section.parameters.begin.test]
FAILED: 1 of 16 assertions in 1 files failed
[Finished]
@wbond
Copy link
Member

wbond commented Jun 18, 2020

I was working on addressing this. After changes and running the tests on the default packages, all 193 assertion failures are from rules written by you @deathaxe 😃.

@deathaxe
Copy link
Collaborator Author

Propably yes, as I tried to work around or work with this behavior to avoid overlapping meta scopes. I'd be keen enough to have a look at those when the time has come ;-)

@deathaxe
Copy link
Collaborator Author

deathaxe commented Jun 18, 2020

I guess Erlang contains some of the 193 failures?

Example:

  preproc-control-definitions:
    - match: (?=\()
      set:
        - clear_scopes: 1
        - match: \(
          scope: punctuation.section.arguments.begin.erlang
          set:
            - - clear_scopes: 1
              - meta_scope: meta.preprocessor.conditional.arguments.erlang
              - include: expect-arguments-end
            - constant-other-macro
    - include: preproc-stray-arguments-end

With (the second) clear_scope working properly the (?=\() lookahead could be removed.

@wbond
Copy link
Member

wbond commented Jun 18, 2020

Yes, I was mostly just amused that the only situations where this bug would have been hit (in the default packages) were written by you, and you submitted the issue.

Clearly it is mostly just a style of how you approach transitioning between contexts, and there certainly isn't anything wrong with that. It is definitely something that should be fixed, IMO, while we are in the process of making breaking changes.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Jun 18, 2020

I'd expect PackageDev to also have failures, if you want to test that as well. Actually not, I'm not using clear_scopes in two adjacent contexts like in the example above.

A similar pattern is used in Python but without clear_scopes since the meta scope is set in the context that matches the identifier. I would generally prefer the approach here, if it worked properly, so I'm happy for the fix. It should simplify some of the meta.mapping context logic as well.

@wbond
Copy link
Member

wbond commented Jul 10, 2020

This has been fixed in build 4075, but only for version: 2 of .sublime-syntax. This is due to the fact that changing it for all syntaxes would have broken backwards compatibility.

@wbond wbond closed this as completed Jul 10, 2020
@wbond wbond added this to the Build 4075 milestone Jul 10, 2020
@wbond wbond added the R: fixed label Jul 10, 2020
@wbond wbond removed their assignment Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants