Skip to content

Commit bd0bd10

Browse files
committed
move executeIfRunning
1 parent cac22b9 commit bd0bd10

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal class LSPProcessListener : ProcessListener {
8787

8888
@Service(Service.Level.PROJECT)
8989
class AmazonQLspService(private val project: Project, private val cs: CoroutineScope) : Disposable {
90-
internal var instance: AmazonQServerInstance? = null
90+
private var instance: AmazonQServerInstance? = null
9191

9292
init {
9393
cs.launch {
@@ -103,6 +103,9 @@ class AmazonQLspService(private val project: Project, private val cs: CoroutineS
103103
}
104104
}
105105

106+
fun executeIfRunning(runnable: (AmazonQLanguageServer) -> Unit) =
107+
instance?.languageServer?.let { runnable(it) }
108+
106109
override fun dispose() {
107110
}
108111

@@ -117,7 +120,7 @@ internal class AmazonQServerInstance(private val project: Project, private val c
117120

118121
private val launcher: Launcher<AmazonQLanguageServer>
119122

120-
internal val languageServer: AmazonQLanguageServer
123+
val languageServer: AmazonQLanguageServer
121124
get() = launcher.remoteProxy
122125

123126
@Suppress("ForbiddenVoid")

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import org.eclipse.lsp4j.TextDocumentContentChangeEvent
2323
import org.eclipse.lsp4j.TextDocumentIdentifier
2424
import org.eclipse.lsp4j.TextDocumentItem
2525
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
26-
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLanguageServer
2726
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
2827
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
2928

@@ -54,11 +53,8 @@ class TextDocumentServiceHandler(
5453
)
5554
}
5655

57-
private fun executeIfRunning(project: Project, runnable: (AmazonQLanguageServer) -> Unit) =
58-
AmazonQLspService.getInstance(project).instance?.languageServer?.let { runnable(it) }
59-
6056
override fun beforeDocumentSaving(document: Document) {
61-
executeIfRunning(project) {
57+
AmazonQLspService.getInstance(project).executeIfRunning {
6258
val file = FileDocumentManager.getInstance().getFile(document) ?: return@executeIfRunning
6359
it.textDocumentService.didSave(
6460
DidSaveTextDocumentParams().apply {
@@ -72,7 +68,7 @@ class TextDocumentServiceHandler(
7268
}
7369

7470
override fun after(events: MutableList<out VFileEvent>) {
75-
executeIfRunning(project) {
71+
AmazonQLspService.getInstance(project).executeIfRunning {
7672
pluginAwareExecuteOnPooledThread {
7773
events.filterIsInstance<VFileContentChangeEvent>().forEach { event ->
7874
val document = FileDocumentManager.getInstance().getCachedDocument(event.file) ?: return@forEach
@@ -98,7 +94,7 @@ class TextDocumentServiceHandler(
9894
source: FileEditorManager,
9995
file: VirtualFile,
10096
) {
101-
executeIfRunning(project) {
97+
AmazonQLspService.getInstance(project).executeIfRunning {
10298
it.textDocumentService.didOpen(
10399
DidOpenTextDocumentParams().apply {
104100
textDocument = TextDocumentItem().apply {
@@ -114,7 +110,7 @@ class TextDocumentServiceHandler(
114110
source: FileEditorManager,
115111
file: VirtualFile,
116112
) {
117-
executeIfRunning(project) {
113+
AmazonQLspService.getInstance(project).executeIfRunning {
118114
it.textDocumentService.didClose(
119115
DidCloseTextDocumentParams().apply {
120116
textDocument = TextDocumentIdentifier().apply {

0 commit comments

Comments
 (0)