How to get "project" object when project is opened

I wanna make rider UnityHost like server to make communicate between unity editor and rider, so I try following code:

 

def pj = new ProjectImpl(pjPath, RoFile.basename(pjPath))
new SolutionInitializer().beforeProjectLoaded(pj)
if (cmd == "replay") {
unityHost.CallBackendPlay(pj, true);
}

but #beforeProjectLoaded raise error:

 

EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@3c0138d5
Current thread: Thread[Thread-7,6,Idea Thread Group] 385679865
SystemEventQueueThread: Thread[AWT-EventQueue-0 2018.2.3#RD-182.4231.496 Rider, eap:false, os:Linux 4.10.0-38-generic, java-version:Oracle Corporation 1.8.0_151-b12,6,Idea Thread Group] 891782419

 

so I need a way to get Project or AnActionEvent outside AnAction, if I can do that, I can invoke all exist idea Action outside Action

 

 

here is my full code:

 

package ro.idea.cs

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ProjectComponent
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.impl.ProjectImpl
import com.jetbrains.rider.plugins.unity.UnityHost
import com.jetbrains.rider.projectView.SolutionInitializer
import ro.JSON
import ro.Kernel
import ro.ProcessUtil
import ro.RoFile
import ro.RoHttpServer

import javax.swing.JComponent

import static ro.Kernel.toMd5

class Startup {
Startup() {
msStartServer()
}
static def tasks = [:]

static def addTask(pjPath, task_key, ... args) {
if (!tasks[toMd5(pjPath)]) {
tasks[toMd5(pjPath)] = [:]
}
tasks[toMd5(pjPath)][task_key] = args
}

def msStartServer() {
def port = 23336
if (!ProcessUtil.portIsListened(port)) {
def sv = new RoHttpServer(port)
def unityHost = new UnityHost.Companion()
sv.get("/handle_unity_editor_request", { rq ->
ApplicationManager.application.runWriteAction(new Runnable() {
@Override
void run() {
def pjPath = rq.params["pj_path"]
def cmd = rq.params["cmd"]
def pj = new ProjectImpl(pjPath, RoFile.basename(pjPath))
new SolutionInitializer().beforeProjectLoaded(pj)
if (cmd == "replay") {
unityHost.CallBackendPlay(pj, true);
}
}
})
})

sv.get("/tasks", { rq ->
JSON.dump(tasks)
})

sv.get("/del_task", { rq ->
tasks[toMd5(rq.params["pj_path"])].remove(rq.params["task_key"])
})

sv.start()
}
}
}

 

 

1 comment
Comment actions Permalink

What are you trying to accomplish? You can't simply create a project out of nothing, you need an actual solution file to open in Rider.

0

Please sign in to leave a comment.