MagicPython icon indicating copy to clipboard operation
MagicPython copied to clipboard

Incorrect highlighting of a call with preceding __getitem__

Open elprans opened this issue 4 years ago • 7 comments

Observe the differences in highlighting of the keyword argument names below:

image

elprans avatar Feb 21 '20 16:02 elprans

The class token is also misclassified:

image

elprans avatar Mar 16 '20 22:03 elprans

I have a solution for better kwargs detection.

Regarding the class definition I need a better idea of what's the expectation here. Technically everything that appears in the parentheses after the class name is part of the class inheritance. It could be a simple identifier (SomeClass), but also an array element (FooObject[Bar]) or even a function call (FooFactory(Bar) - this is a bit odd, but not forbidden). It could be all of the above: Foo(Bar)[Baz]. Should all of these be highlighted as entity.other.inherited-class.python? Essentially making that the default, like source is for normal code? Or should it only be some prefix?

vpetrovykh avatar May 01 '20 17:05 vpetrovykh

Can we just handle the Foo[Bar] case specifically? I don't think we should veer too much into supporting other weird expressions there.

elprans avatar May 01 '20 22:05 elprans

Perhaps you misunderstand me. This is not a question of how technically hard the solution is - it's comparable complexity, regardless of what we choose here. This is a question of what kind of consistency we want to show.

So by default I would think that every argument in class definition is definitely another class semantically, regardless of how obscure the expression. So I would tend to suggest that we can then just wrap all arguments in entity.other.inherited-class.python at the base level. This way all the code that was normally white would now be green (for our color scheme) and the argument entire expression would have the inherited-class scope. This seems semantically consistent and would have the net effect of accounting for the particular special case that we currently have.

We can special-case only this one, but it's not saving me any work and I'd prefer to not make an exception. So unless you have strong opposition to calling the entire argument as entity.other.inherited-class.python let's just go with the first option.

vpetrovykh avatar May 01 '20 23:05 vpetrovykh

How would the blanket approach highlight this:

class FooMeta(type(Bar)):
    pass

?

elprans avatar May 01 '20 23:05 elprans

The entire type(Bar) would have the entity.other.inherited-class.python scope (making (Bar) green) and the type would also have the support.type.python scope (the thing that makes it blue in our color scheme).

This is similar to how strings are highlighted where the entire string has a common "string" scope and then parts of it may have additional scopes (like escape sequences).

vpetrovykh avatar May 01 '20 23:05 vpetrovykh

OK that seems fine to me.

elprans avatar May 02 '20 00:05 elprans