generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection between session host and plugin
- Loading branch information
Showing
20 changed files
with
1,177 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Generate Protocol" type="GradleRunConfiguration" factoryName="Gradle"> | ||
<ExternalSystemSettings> | ||
<option name="executionName"/> | ||
<option name="externalProjectPath" value="$PROJECT_DIR$"/> | ||
<option name="externalSystemIdString" value="GRADLE"/> | ||
<option name="scriptParameters" value=""/> | ||
<option name="taskDescriptions"> | ||
<list/> | ||
</option> | ||
<option name="taskNames"> | ||
<list> | ||
<option value="rdgen"/> | ||
</list> | ||
</option> | ||
<option name="vmOptions" value=""/> | ||
</ExternalSystemSettings> | ||
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled> | ||
<method v="2"/> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") | ||
} | ||
|
||
val rdLibDirectory: () -> File by rootProject.extra | ||
|
||
repositories { | ||
maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") } | ||
flatDir { | ||
dir(rdLibDirectory()) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib") | ||
implementation(group = "", name = "rd-gen") | ||
implementation(group = "", name = "rider-model") | ||
} |
32 changes: 32 additions & 0 deletions
32
protocol/src/main/kotlin/model/sessionHost/AspireSessionHostModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package model.sessionHost | ||
|
||
import com.jetbrains.rd.generator.nova.* | ||
import com.jetbrains.rd.generator.nova.PredefinedType.* | ||
import com.jetbrains.rd.generator.nova.csharp.CSharp50Generator | ||
import com.jetbrains.rd.generator.nova.kotlin.Kotlin11Generator | ||
|
||
object AspireSessionHostRoot : Root() { | ||
init { | ||
setting(Kotlin11Generator.Namespace, "com.github.rafaelldi.aspireplugin.generated") | ||
setting(CSharp50Generator.Namespace, "AspireSessionHost.Generated") | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
object AspireSessionHostModel : Ext(AspireSessionHostRoot) { | ||
private val EnvironmentVariableModel = structdef { | ||
field("key", string) | ||
field("value", string) | ||
} | ||
|
||
private val SessionModel = structdef { | ||
field("projectPath", string) | ||
field("debug", bool) | ||
field("envs", array(EnvironmentVariableModel).nullable) | ||
field("args", array(string).nullable) | ||
} | ||
|
||
init { | ||
map("sessions", string, SessionModel) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
pluginManagement { | ||
repositories { | ||
maven { setUrl("https://cache-redirector.jetbrains.com/plugins.gradle.org") } | ||
} | ||
resolutionStrategy { | ||
eachPlugin { | ||
when(requested.id.name) { | ||
"rdgen" -> { | ||
useModule("com.jetbrains.rd:rd-gen:${requested.version}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" | ||
} | ||
|
||
|
||
rootProject.name = "aspire-plugin" | ||
|
||
include(":protocol") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using AspireSessionHost.Generated; | ||
using JetBrains.Collections.Viewable; | ||
using JetBrains.Lifetimes; | ||
using JetBrains.Rd; | ||
using JetBrains.Rd.Impl; | ||
|
||
namespace AspireSessionHost; | ||
|
||
internal class Connection : IDisposable | ||
{ | ||
private readonly LifetimeDefinition _lifetimeDef = new(); | ||
private readonly Lifetime _lifetime; | ||
private readonly IScheduler _scheduler; | ||
private readonly IProtocol _protocol; | ||
private readonly Task<AspireSessionHostModel> _model; | ||
|
||
internal Connection(int port) | ||
{ | ||
_lifetime = _lifetimeDef.Lifetime; | ||
_scheduler = SingleThreadScheduler.RunOnSeparateThread(_lifetime, "AspireSessionHost Protocol Connection"); | ||
var wire = new SocketWire.Client(_lifetime, _scheduler, port); | ||
_protocol = new Protocol( | ||
"AspireSessionHost Protocol", | ||
new Serializers(), | ||
new Identities(IdKind.Client), | ||
_scheduler, | ||
wire, | ||
_lifetime | ||
); | ||
_model = InitializeModelAsync(); | ||
} | ||
|
||
private Task<AspireSessionHostModel> InitializeModelAsync() | ||
{ | ||
var tcs = new TaskCompletionSource<AspireSessionHostModel>(); | ||
_scheduler.Queue(() => | ||
{ | ||
try | ||
{ | ||
tcs.SetResult(new AspireSessionHostModel(_lifetime, _protocol)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
tcs.SetException(ex); | ||
} | ||
}); | ||
return tcs.Task; | ||
} | ||
|
||
internal async Task<T> DoWithModel<T>(Func<AspireSessionHostModel, T> action) | ||
{ | ||
var model = await _model; | ||
var tcs = new TaskCompletionSource<T>(); | ||
_scheduler.Queue(() => | ||
{ | ||
try | ||
{ | ||
tcs.SetResult(action(model)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
tcs.SetException(ex); | ||
} | ||
}); | ||
return await tcs.Task; | ||
} | ||
|
||
internal Task DoWithModel(Action<AspireSessionHostModel> action) => | ||
DoWithModel(model => | ||
{ | ||
action(model); | ||
return 0; | ||
}); | ||
|
||
public void Dispose() | ||
{ | ||
_lifetimeDef.Terminate(); | ||
} | ||
} |
Oops, something went wrong.