JetBrains / sbt-idea-plugin

Develop IntelliJ plugins with Scala and SBT
Apache License 2.0
97 stars 28 forks source link

Updating Components on Change of Another #131

Closed AlexWeinstein92 closed 3 months ago

AlexWeinstein92 commented 3 months ago

I am trying to build a ToolWindow that responds to a change in Settings. I have been able to update state via settings, but now am very unsure how to make the ToolWindow subscribe to the state updates.

I have tried 2 solution, the second in 2 forms:

Solution 1: updating the ToolWindow component directly from the state update function Issue 1: ToolWindowManager cannot find the window based on its ID (project.getToolWindow returns null according to the log)

Solution 2: Setting up a topic that the state update pushes to Issue 2.1: No clue how to add a handler function for the topic. I have tried putting it on the companion object of the topic then calling the handler on the topic companion object after syncPublisher, resulting in error Connection must have default handler installed prior to any anonymous subscriptions. Have tried setting up default handler, it didn't compile (can try again to reproduce the error if requested). There seems to be no documentation of syncPublisher, I got recommended to use it talking to Copilot

Issue 2.2: I thought I saw some documentation about being able to use a handler after messageBus.subscribe is called, but then I couldn't find it. CoPilot seems to think is handler can be a second argument to subscribe, not sure way. subscribe seems just as undocumented as syncPublisher

If interested in seeing my code, here is my latest WIP commit: https://github.com/ossuminc/riddl-idea-plugin/commit/7e7387a1261728377aeedba430cb7429553eb8f4

I appreciate any and all help provided

AlexWeinstein92 commented 3 months ago

I ended up calling the component update function using putClientProperty and calling getClientProperty from the apply function on my custom Configurable