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: open brackets detector too impatient? #500

Closed
pdknsk opened this issue Jun 23, 2016 · 10 comments · Fixed by #674
Closed

python: open brackets detector too impatient? #500

pdknsk opened this issue Jun 23, 2016 · 10 comments · Fixed by #674
Labels

Comments

@pdknsk
Copy link

pdknsk commented Jun 23, 2016

Write this.

y = list()

def x():
    return

Now delete the closing bracket of list(). Both def and return are immediately marked as errors.
I think Sublime should perhaps not do this while the line is still being edited.

@FichteFoll
Copy link
Collaborator

There is no way to detect if you are "still editing a line" in syntax definitions.

There are a couple tweaks that allow incomplete statements like a bare with keyword, but it is impossible to detect when a function (or class) call is not closed because the user is still working on it.

However, an argument could be made for allowing statement keywords to appear in expression scopes (such as arguments) and not highlighting something like list(def) as invalid. Imo the current behavior helps spotting obvious errors and unclosed parentheses and ST's auto-matching behavior of parentheses should suffice with negating that downside.

@pdknsk
Copy link
Author

pdknsk commented Jun 23, 2016

I agree, there's definitely a positive side to it. That's why I put a question mark. Why not mark the opening bracket as an error, rather than basically the rest of the document? It'd still be very noticeable.

@FichteFoll
Copy link
Collaborator

It's not possible to know whether an opening brace does not have a closing one unless you parse the entire file. This is comparable to the halting problem.

The syntax definition engine also does not support backtracking in this way for performance reasons.

@pdknsk
Copy link
Author

pdknsk commented Jun 23, 2016 via email

@pdknsk
Copy link
Author

pdknsk commented Jun 23, 2016 via email

@wbond wbond added the question label Jun 23, 2016
@pdknsk
Copy link
Author

pdknsk commented Jun 27, 2016

I notice that in 3114 only the first keyword following an open bracket is affected (and less prominently), rather than the rest of the document.

@FichteFoll
Copy link
Collaborator

Hm, I guess we could exit a parens scope on the first keyword we find. That should reduce the amount of noise from illegally placed keywords due to a missing closing paren (or other bracket).

@pdknsk
Copy link
Author

pdknsk commented Nov 22, 2016

Some possible bugs or quirks I noticed.

This works as expected, I think.

1

For some reason the reverse order is different.

2

I'm not sure about this.

3

@wbond
Copy link
Member

wbond commented Nov 22, 2016

@pdknsk I think the second example is working "properly" also. The with is invalid inside of [, and then as is invalid unless paired with something like with.

@FichteFoll
Copy link
Collaborator

The first is odd, because it seems to exit the scope at with instead of break. Third should break at def instead of : in the unbalanced parentheses.

I'll look into it.

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

Successfully merging a pull request may close this issue.

3 participants