How can i create a plugin to create custom java code folding when every open java file ?

已回答

I hava see demo : SimpleFoldingBuilder in  sdk-code-example , but the deom can not collapse code every open file.

but in impl of AbstractBundle , when a param annoation by @propertyKey, every open file while folding code then display property value,   how can i get the same  effect: collapse   custom Java code when open file

1

Hi,

I'm not sure I understand the case. Do you mean that some foldings are not enabled when you open the file? Is it random behavior?

Please describe what is happening in detail, with screenshots.

0

hi

expect:

1.open file ,all folding area are collapsed

2.expand all filding area 

3.close file

4.reopen file

when reopen file,all folding area are collapsed,like first step.

 

“message” method is 

fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String {
	return CodeGlanceBundle.getAdaptedMessage(key, *params)
}

What's above is what I expect. i think it may achieve by PropertyFoldingBuilder,but i find there is non diff between   PropertyFoldingBuilder and SimpleFoldingBuilder .

actual:

but when i do like this https://plugins.jetbrains.com/docs/intellij/folding-builder.html#define-a-folding-builder,

1.first use Intellij idea open file, folding area are collapsed

2.expand folding area

3.close file 

4.reopen file , folding area don not collapse .

 

May I ask how to achieve the desired results?


 


 

0

Hi,

Thank you for the explanation. This is the expected behavior. Folding state should be remembered even between IDE restarts.

0

Hi,

But why does the code that calls the "message" method get folded every time the file is reopened, regardless of whether it was folded before opening? What can I do if I want to achieve this effect?

may this feature call i18n folding? i really want to know how this ,and use in my plugin .Please help me .

 

And i find the feature only effect in UE , CE is not support 

0

Hi,

I can't reproduce your behavior with message(). When I open a file:

  1. Messages are collapsed (I see the values, not the code).
  2. I expand messages (I see the actual code).
  3. I close the file.
  4. I reopen the file.
  5. I see expanded messages (the actual code).
  6. I restart the IDE.
  7. I see expanded messages (the actual code).

In short, the state is remembered and restored on file reopening or the IDE restart.

If you experience it, I think this is an unexpected behavior. I don't see any configuration option that allows controlling it. Is it possible that your folding state is not remembered due to cleaning up the IDE state (e.g., when using sandbox IDE)?

0

Hi,

Thinks for your reply,

I open same project use UE edition and CE edition  Intellij Idea,   the effect I want is in the video of UE.

Intellij Idea 2023.3.4 UE edition :

https://www.youtube.com/watch?v=PKe1XP_CkVg

 

The project in two video is from :https://github.com/Nasller/CodeGlancePro

For successful build you need to find and delete the following code, 

signPlugin {
		certificateChainFile.set(File(env.getOrDefault("CERTIFICATE_CHAIN", "$dir/pluginCert/chain.crt")))
		privateKeyFile.set(File(env.getOrDefault("PRIVATE_KEY", "$dir/pluginCert/private.pem")))
		password.set(File(env.getOrDefault("PRIVATE_KEY_PASSWORD", "$dir/pluginCert/password.txt")).readText(Charsets.UTF_8))
	}

please  open file :com.nasller.codeglance.config.CodeGlanceConfigurable ,

locate:

	private fun EditorKind.getMessageWidth() = when(this){

then repeat your previous steps.

Looking forward to your reply.

0

My plugin is not executed once my file is opened.

I make a folding region for call of method named 'getBoolean' in com.example.myinlayhints.MyFoldingBuilder,
and the test class in video is Test.java in Test directory.

there is my plugin video :https://www.youtube.com/watch?v=voMmpe5ydXE

and there is my code : https://github.com/adgai/MyFoldingPlugin.

Looking forward to your reply.

0

Hi,

This is the correct behavior, and your video https://www.youtube.com/watch?v=PKe1XP_CkVg looks like a bug (I suggest reporting it).

I checked both projects and everything worked as expected for me. In both projects, the folding state is remembered after a file is reopened. This is also presented on your last video (https://www.youtube.com/watch?v=voMmpe5ydXE).

Unfortunately, resetting the state after editor reopening is not currently supported. Please vote and follow this issue:
https://youtrack.jetbrains.com/issue/IJPL-791/Add-possibility-of-resetting-code-folding-state-to-the-default-after-editor-reopening

0

thinks for your reply,i will follow the issue

0

请先登录再写评论。