xylo / intellij-postfix-templates

Custom Postfix Templates for Intellij IDEA
https://plugins.jetbrains.com/plugin/9862-custom-postfix-templates
Apache License 2.0
515 stars 94 forks source link

Python: Please add support for other class names too. #172

Open sairam4123 opened 4 years ago

sairam4123 commented 4 years ago

I am trying to add a converters like this:

.int : Convert into int
    ANY -> int($expr$)$END$
.str : Convert into str
    ANY -> str($expr$)$END$
.frozenset : Convert into frozenset
    list -> frozenset($expr$)$END$
    tuple -> frozenset($expr$)$END$
    set -> frozenset($expr$)$END$
    dict -> frozenset($expr$)$END$
.set : Convert into set
    ANY -> set($expr$)$END$
.list : Convert into list
    ANY -> list($expr$)$END$
.dict : Convert into dict
    ANY -> dict($expr$)$END$
.tuple : Convert into tuple
    ANY -> tuple($expr$)$END$
.bool : Convert into bool
    ANY -> bool($expr$)$END$
.frozenset : Convert into frozenset
    list -> frozenset($expr$)$END$
    tuple -> frozenset($expr$)$END$
    set -> frozenset($expr$)$END$
    dict -> frozenset($expr$)$END$

this can be simplified even further using like this

.frozenset : Convert into frozenset
    iter -> frozenset($expr$)$END$

But as there's no class like iterable in Postfix here. So, the workaround would be this:

.frozenset : Convert into frozenset
    list -> frozenset($expr$)$END$
    tuple -> frozenset($expr$)$END$
    set -> frozenset($expr$)$END$
    dict -> frozenset($expr$)$END$

So it would be nice if you add support for other classes too. like frozenset, iter, ... Thank you!

ikopysov commented 3 years ago

I've added support for frozenset type and introduced "complex" types, which can include multiple types, like "iter" mentioned by you.

It's not really flexible, and it may be possible to implement checks for the type methods

It seems tuples currently are not working due to their names being different, e.g.: according to documentation, iterator should have iter method. But this feature is quite large.

Also, it seems the "tuple" type is not detected correctly (for the entire Python CPT): (1, 2, 3) will have (int, int, int) type name, but "tuple" is expected. I'm trying to get the correct name differently, but it should be tested.

sairam4123 commented 3 years ago

Is there any progress on this?