From 143fbc7d9f3544c90a22fe36ae9b5d21a5c3472c Mon Sep 17 00:00:00 2001 From: Jonathan GAYVALLET Date: Sun, 31 May 2026 22:33:57 +0200 Subject: [PATCH] Make nixd's noogle.dev code action workaround also work in case of invalid syntax --- .../nixos/idea/lsp/NixLspServerDescriptor.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.kt b/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.kt index 2e5ae79..e6bd54f 100644 --- a/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.kt +++ b/src/main/java/org/nixos/idea/lsp/NixLspServerDescriptor.kt @@ -33,20 +33,26 @@ internal class NixLspServerDescriptor(project: Project, private var settings: Ni override val lspCustomization: LspCustomization = object : LspCustomization() { override val codeActionsCustomizer = object : LspCodeActionsSupport() { - private fun getNoogleUrl(codeAction: CodeAction): String? = - (codeAction.data as? JsonObject)?.get("noogleUrl")?.asString - - override fun createIntentionAction(lspServer: LspServer, codeAction: CodeAction): LspIntentionAction? { - if (getNoogleUrl(codeAction) != null) { - /* set an empty edit to prevent the IDE from calling - the LSP server and automatically opening the url */ - codeAction.edit = WorkspaceEdit() - return object : LspIntentionAction(lspServer, codeAction) { - override fun invoke(project: Project, editor: Editor, psiFile: PsiFile) { - BrowserUtil.open(getNoogleUrl(codeAction)!!) - } + private fun handleOpenNoogleCodeAction(lspServer: LspServer, codeAction: CodeAction): LspIntentionAction? { + var noogleUrl = (codeAction.data as? JsonObject)?.get("noogleUrl")?.asString ?: return null + /* set an empty edit to prevent the IDE from calling + the LSP server and automatically opening the url */ + codeAction.edit = WorkspaceEdit() + return object : LspIntentionAction(lspServer, codeAction) { + override fun invoke(project: Project, editor: Editor, psiFile: PsiFile) { + BrowserUtil.open(noogleUrl) } } + } + + override fun createQuickFix(lspServer: LspServer, codeAction: CodeAction): LspIntentionAction? { + /* discard the "open Noogle" codeAction, or it will be shown twice */ + handleOpenNoogleCodeAction(lspServer, codeAction)?.let {return null} + return super.createQuickFix(lspServer, codeAction) + } + + override fun createIntentionAction(lspServer: LspServer, codeAction: CodeAction): LspIntentionAction? { + handleOpenNoogleCodeAction(lspServer, codeAction)?.let {return it} return super.createIntentionAction(lspServer, codeAction) } }