How to listens to ..


I'm stuck, in the CamouflagePlugin. To provide
auto-folding/camouflaging, and fix a huge bug, I need to know ..

Q1/ How to detect that the caret entered/left a foldregion?
..without scanning all the fold regions, after each single caracter
move of the caret ?

Q2/ How to detect code changes ?

As the user types, and refactor, I need to detect some specific code
modification :
Example:
- add/remove the keyword "final"
- change in the for statements parameter lists
- change in if condition or block statement

How can I do that? I checked the Psi classes for appropriate listeners, but
Editor :
only Mouse and MouseMotion listeners.

CaretModel :
CaretListener only listens to caretPositionChanged



I guess I need some
PsiTreeChangelistener

that would offer :
modifiersListChanged()
forParameterListChanged


Should a solution exist for the problems above,

Q3/ how to add a listener to all the editors, current and future?



Alain

5 comments

Q1/ How to detect that the caret entered/left a foldregion?
..without scanning all the fold regions, after each single caracter
move of the caret ?

Do you need the only fact you're in one of the collapsed fold regions or
you'd like to know what fold region you're in? Or you don't mind to process
expanded as well?

Q2/ How to detect code changes ?

>

As the user types, and refactor, I need to detect some specific code
I guess I need some
PsiTreeChangelistener

>

that would offer :
modifiersListChanged()
forParameterListChanged

Exactly. But that listener does not provide events of that level. I'm
affraid you'd have to extract necessary information from low level AST
change events by yourself.

Q3/ how to add a listener to all the editors, current and future?

That's the easiest one :)
EditorFactory.getInstance().getEventMulticaster().addXXXListener()

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"





0

Maxim Shafirov (JetBrains) wrote:

>>Q1/ How to detect that the caret entered/left a foldregion?
>> ..without scanning all the fold regions, after each single character
>>move of the caret ?
>
>Do you need the only fact you're in one of the collapsed fold regions or
>you'd like to know what fold region you're in? Or you don't mind to
process
>expanded as well?


What I want to achieve :

1/ when leaving an expanded CamouflagedRegion (== fold region with non
default placeholder),

1.a: refresh its placeholding text (if necessary)
ex: before = "for (int i in 1..99)"
after = "for (int j in -1..1)"

1.b: automatically collapse (if requested through a config option)

2/ when entering a CamouflagedRegion
2.a: automatically and immediately expand (if requested through a
config option)



So, I need to
a) detect the "leaving the expanded area" (VERY VERY IMPORTANT)
b) obtain the fold region
c) detect the "entering the area" (less important)


note: I have a routine to do b), but if a fold region listener were to
send it back in the event, I wouldn't complain :).

>>Q2/ How to detect code changes ?
>>As the user types, and refactor, I need to detect some specific code
>>I guess I need some PsiTreeChangelistener
>>
>>that would offer :
>> modifiersListChanged()
>> forParameterListChanged
>
>Exactly. But that listener does not provide events of that level. I'm
>afraid you'd have to extract necessary information from low level AST
>change events by yourself.

Is there currently such a listener in the openAPI? I couldn't find it.


What I want to achieve :

3/ when 'final' is added to/removed from the modifiers list of a
method/variable/...,
automatically wrap a camouflage region around it, and collapse it,

4/ when a for statement is created/modified, automatically ..

..etc

As some code modifications are done through refactorings, I also need to
be able to detect

5/ when a variable is renamed : => update the camouflaged regions that
use it (for, accessors).
ex: before = "for (int i in 1..99)"
after = "for (int index in 1..99)"

6/ when a getter/setter/constructor is created through "Generate",
automatically camouflage it (if ..)
7/ when a getter/setter/constructor is created through "Encapsulate",
automatically ..


Alain


0

Alain Ravet wrote:

Maxim Shafirov (JetBrains) wrote:
>>




Any comment to my previous remarks/questions?
Sorry to insist, but I'm stuck without this info.

Alain

0

Alain Ravet wrote:

Maxim Shafirov (JetBrains) wrote:
>>





Any comment to my previous remarks/questions?
Sorry to insist, but I'm stuck without this info.

Additional question : has everything to be done through the CaretListener ?


Alain

0

Sorry, Alain, I haven't answered immediately. As the matter of fact not all
of your needs can be covered by OpenAPI or even API at all. At the moment
I'm thinking what minimal changes would cover your needs.

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Alain Ravet" <alain.ravet.list@wanadoo.be> wrote in message
news:bnld51$p1e$1@is.intellij.net...

Alain Ravet wrote:

>

Maxim Shafirov (JetBrains) wrote:
>>

>
>
>
>

Any comment to my previous remarks/questions?
Sorry to insist, but I'm stuck without this info.

>

Additional question : has everything to be done through the CaretListener

?
>
>

Alain

>


0

Please sign in to leave a comment.