dkandalov / live-plugin

IntelliJ plugin for writing IntelliJ plugins at runtime ⚡️
https://plugins.jetbrains.com/plugin/7282
Apache License 2.0
858 stars 67 forks source link

Tool windows gets empty after adding a new plugin #96

Closed krasa closed 5 years ago

krasa commented 5 years ago

It looks like this: image

Resizing or hovering over buttons fixes it:

image

live-plugin  0.6.3 beta

IntelliJ IDEA 2019.2 EAP (Ultimate Edition)
Build #IU-192.4787.16, built on June 6, 2019
Runtime version: 11.0.3+12-b281.38 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
krasa commented 5 years ago

Deleting has the same effect. (and with proper 0.6.3 beta)

dkandalov commented 5 years ago

I think this also happens in older versions of IJ (e.g. in 2019.1) but I could only reproduce it with a task running in background, e.g.

Screenshot 2019-06-12 at 22 38 26
krasa commented 5 years ago

Yeah I think it was there from the beginning. I can reproduce it without it, almost always, but not in pom.xml files, plaintext works great.

krasa commented 5 years ago

If I am long enough in the Add dialog, so that this popup disappears: image then it works fine, because as the popup gets automatically shown, the tool window gets repainted with it.

I could try to fix it if you want.

dkandalov commented 5 years ago

Sure, if you want give it a go 👍

I think fundamentally the problem is that the way file tree is created in PluginToolWindow is just a hack. My plan was to look at the latest IJ API to find what is the "right" way to do it these days but I don't mind any other fixes :)

krasa commented 5 years ago

Why don't you use LivePluginAppComponent#livePluginsPath as the tree root + filter to get rid of .idea folder? It would solve everything.

dkandalov commented 5 years ago

If you mean addRoots function, then as the comment below says it's because of the case when there is only one plugin, the tree was doing something funny and basically automatically changing root to one level down. IIRC it was true in 2013, might not be true anymore though.

        private fun addRoots(descriptor: FileChooserDescriptor, virtualFiles: List<VirtualFile>) {
            // Adding file parent is a hack to suppress size == 1 checks in com.intellij.openapi.fileChooser.ex.RootFileElement.
            // Otherwise, if there is only one plugin, tree will show files in plugin directory instead of plugin folder.
            // (Note that this code is also used by "Copy from Path" action.)
            if (virtualFiles.size == 1) {
                val parent = virtualFiles[0].parent
                descriptor.roots = if (parent != null) listOf(parent) else virtualFiles
            } else {
                descriptor.roots = virtualFiles
            }
        }
krasa commented 5 years ago

Yes, and seemed to work fine now.

dkandalov commented 5 years ago

Hm, to me it looks like it hasn't changed 🤔

Screenshot 2019-06-14 at 17 02 58 Screenshot 2019-06-14 at 17 04 12

I don't mean though there is no way to actually fix it instead using this hack.

dkandalov commented 5 years ago

Actually, what you suggested look like this

krasa commented 5 years ago

What I did: descriptor.setRoots(VfsUtil.findFile(Paths.get(livePluginsPath),true)) instead of PluginToolWindowManager.addRoots(descriptor, virtualFiles)

looked totally the same as the current solution. I will check other IDE versions.

krasa commented 5 years ago

works fine on 2018.3, maybe OS dependant?

lp

krasa commented 5 years ago

This is what I did: https://github.com/dkandalov/live-plugin/compare/master...krasa:treeFlicker2?expand=1

krasa commented 5 years ago

Well, I reproduced this, several times, but only in sandbox image there were plugins shown after start, but then just disappeared. After that the tree did not work at all.

krasa commented 5 years ago
krasa commented 5 years ago

Ok I know where was the problem. I found a nice little method VfsUtil.findFile(path, true), but it returns a VirtualFile even for non existing directory (both #exists and #valid return true) - looks like a bug in IJ... Gradle or something must have deleted my directory, so the tree had it's root, but the root folder did not really exist, and when it got created it did not make a difference.

krasa commented 5 years ago

https://user-images.githubusercontent.com/28375/59522398-835ba180-8ec6-11e9-8275-29b2cc413319.png That was caused only by not disabling the action when there are no plugins.