From 0eb8396e14b1124be051ca750a2c2c1fd41b6d67 Mon Sep 17 00:00:00 2001 From: Brandon Ringe Date: Sun, 28 Nov 2021 15:06:01 -0800 Subject: [PATCH 1/3] Add resolveCodeAction middleware - WIP --- package-lock.json | 5 +++++ src/lsp/main.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/package-lock.json b/package-lock.json index d6fbbee62..012b0ac03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9967,6 +9967,11 @@ "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" }, + "bin": { + "sshpk-conv": "bin/sshpk-conv", + "sshpk-sign": "bin/sshpk-sign", + "sshpk-verify": "bin/sshpk-verify" + }, "engines": { "node": ">=0.10.0" } diff --git a/src/lsp/main.ts b/src/lsp/main.ts index 808e1a552..bf84d753e 100644 --- a/src/lsp/main.ts +++ b/src/lsp/main.ts @@ -12,6 +12,7 @@ import * as path from 'path'; import * as state from '../state'; import { provideHover } from '../providers/hover'; import { provideSignatureHelp } from '../providers/signature'; +import { ProviderResult, CodeAction } from 'vscode'; const LSP_CLIENT_KEY = 'lspClient'; const RESOLVE_MACRO_AS_COMMAND = 'resolve-macro-as'; @@ -41,6 +42,11 @@ function createClient(clojureLspPath: string): LanguageClient { provideLinkedEditingRange: async (_document, _position, _token, _next): Promise => { return null; }, + resolveCodeAction(item, token, next): ProviderResult { + console.log(item); + // TODO: See if next returns codeAction/resolve response and then use info from that to call lsp command + return next(item, token); + }, handleDiagnostics(uri, diagnostics, next) { if (uri.path.endsWith(config.REPL_FILE_EXT)) { return; From 60241a9bbd67ca4c72c783ad193002e2d67a68cd Mon Sep 17 00:00:00 2001 From: Brandon Ringe Date: Sun, 28 Nov 2021 16:24:15 -0800 Subject: [PATCH 2/3] Send LSP command request for resolved code actions Fix #1373. Update changelog. --- CHANGELOG.md | 1 + src/lsp/main.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c17b114a..ef1a23716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Changes to Calva. - Internal: [Handle the unknown-op status from test commands](https://github.com/BetterThanTomorrow/calva/pull/1365) - Fix: [textDocument/linkedEditingRange failed when opening files or moving cursor](https://github.com/BetterThanTomorrow/calva/issues/1374) - Fix: [paredit.spliceSexp doesn't work with set literals](https://github.com/BetterThanTomorrow/calva/issues/1395) +- Fix: [LSP code actions not working](https://github.com/BetterThanTomorrow/calva/issues/1373) ## [2.0.225] - 2021-11-10 - Revert 224 changes: [Version v2.0.224 causes problems on some machines (possibly Windows related)](https://github.com/BetterThanTomorrow/calva/issues/1379) diff --git a/src/lsp/main.ts b/src/lsp/main.ts index bf84d753e..d09d67fb7 100644 --- a/src/lsp/main.ts +++ b/src/lsp/main.ts @@ -42,10 +42,10 @@ function createClient(clojureLspPath: string): LanguageClient { provideLinkedEditingRange: async (_document, _position, _token, _next): Promise => { return null; }, - resolveCodeAction(item, token, next): ProviderResult { - console.log(item); - // TODO: See if next returns codeAction/resolve response and then use info from that to call lsp command - return next(item, token); + async resolveCodeAction(item, token, next): Promise { + const { command } = await next(item, token); + sendCommandRequest(command.command, command.arguments); + return null; }, handleDiagnostics(uri, diagnostics, next) { if (uri.path.endsWith(config.REPL_FILE_EXT)) { From a5220550e110d0b847cf321eda566b53f4002b2e Mon Sep 17 00:00:00 2001 From: Brandon Ringe Date: Sun, 28 Nov 2021 16:40:51 -0800 Subject: [PATCH 3/3] Only send command for code action if command exists in request --- src/lsp/main.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lsp/main.ts b/src/lsp/main.ts index d09d67fb7..1a1a80a28 100644 --- a/src/lsp/main.ts +++ b/src/lsp/main.ts @@ -44,8 +44,11 @@ function createClient(clojureLspPath: string): LanguageClient { }, async resolveCodeAction(item, token, next): Promise { const { command } = await next(item, token); - sendCommandRequest(command.command, command.arguments); - return null; + if (command) { + sendCommandRequest(command.command, command.arguments); + return null; + } + return next(item, token); }, handleDiagnostics(uri, diagnostics, next) { if (uri.path.endsWith(config.REPL_FILE_EXT)) {