This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-04
Channels
- # aleph (2)
- # announcements (1)
- # biff (1)
- # calva (16)
- # cider (4)
- # clojure (45)
- # clojure-argentina (1)
- # clojure-europe (21)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-uk (7)
- # clojurebridge (1)
- # clojurescript (3)
- # clr (3)
- # cursive (21)
- # datomic (4)
- # fulcro (4)
- # graalvm (3)
- # holy-lambda (8)
- # honeysql (22)
- # lsp (3)
- # malli (3)
- # nbb (1)
- # off-topic (3)
- # portal (13)
- # re-frame (3)
- # reagent (7)
- # releases (1)
- # shadow-cljs (1)
Here's an example for setting up a mapping in neovim for the cycle-coll
refactoring using fennel and the nvim native LSP client:
(module lsp-aug
{autoload {eval conjure.eval
str conjure.aniseed.string
a conjure.aniseed.core}})
(defn cycle-coll []
(let [uri (a.str "file://" (vim.api.nvim_buf_get_name 0))
(row col) (unpack (vim.api.nvim_win_get_cursor 0))]
(vim.lsp.buf.execute_command
{:command "cycle-coll"
:arguments [uri (- row 1) (- col 1)]})))
(vim.keymap.set :n :<leader>et #(cycle-coll))
There is probably a better way of doing it, but it works :man-shrugging: Took me some time to figure out, so I thought I'd share.
Thanks for the help earlier, @ericdallo.This is what I've got in my config, making a user command to run the lsp commands. vim.lsp.util
has some useful helpers for making args.
local commands = { "cycle-coll", ... }
vim.api.nvim_buf_create_user_command(0, "CljLsp", function(info)
local command = info.args
local position_params = vim.lsp.util.make_position_params()
vim.lsp.buf.execute_command({
command = command,
arguments = {
position_params.textDocument.uri,
position_params.position.line,
position_params.position.character,
},
})
end, {
desc = "Run clojure-lsp command",
nargs = 1,
complete = function(arg_lead, cmd_line, cursor_pos)
return vim.tbl_filter(function(s) return s:sub(1, #arg_lead) == arg_lead end, commands)
end,
})
@UF3DZS1DF Thanks for sharing! That's very helpful. There's not much Fennel-specific config discussion here so far, so here's my translated version for posterity:
(module lsp-aug-jp
{autoload {eval conjure.eval
str conjure.aniseed.string
a conjure.aniseed.core}})
(local commands ["cycle-coll"
"thread-first"
"thread-first-all"])
(vim.api.nvim_create_user_command "CljLsp"
(fn [info]
(let [command (a.get info :args)
position-params (vim.lsp.util.make_position_params)
uri (a.get-in position-params [:textDocument :uri])
line (a.get-in position-params [:position :line])
character (- (a.get-in position-params [:position :character]) 1)]
(vim.lsp.buf.execute_command
{:command command
:arguments [uri line character]})))
{:desc "Run clojure-lsp command"
:nargs 1
:complete (fn [arg-lead cmd-line cursor-pos]
(vim.tbl_filter
(fn [s] (= (a.sub s 1 (a.count arg-lead)) arg-lead))
commands))})
(vim.keymap.set :n :<leader>ez ":CljLsp cycle-coll<cr>")
(vim.keymap.set :n :<leader>et ":CljLsp thread-first<cr>")
(vim.keymap.set :n :<leader>el ":CljLsp thread-first-all<cr>")