Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deps edn options #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lua/jazz/interrupt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- luacheck: globals vim
local acid = require("acid")
local utils = require("jazz.utils")
local log = require("jazz.log").msg
local interrupt_op = require("acid.ops").interrupt
local connections = require("acid.connections")
local sessions = require("acid.sessions")
local impromptu = require("impromptu")

local interrupt = {}


interrupt.select_session = function()
local connection_ix = connections.peek()
local session_ids = sessions.store[connection_ix]
if session_ids ~= nil then
session_ids = session_ids.list
else
return
end

local response = function(data)
if utils.contains('interrupted', data.status) then
log"Successfully interrupted session"
elseif utils.contains('session-idle', data.status) then
log"Nothing to interrupt"
else
log"shrug" -- TODO deal with other two cases
end
end

if #session_ids > 1 then

impromptu.filter{
title = "🎵 Select session for interrupting",
options = utils.map(function(id)
return {description = id}
end, session_ids),
handler = function(_, selected)
acid.run(interrupt_op{session = selected.description}:with_handler(response))
return true
end
}
else
acid.run(interrupt_op{session = session_ids[1]}:with_handler(response))
end

end

return interrupt
10 changes: 2 additions & 8 deletions lua/jazz/navigation.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- luacheck: globals vim
local acid = require("acid")
local go_to = require("acid.features").go_to
local ops = require("acid.ops")
local impromptu = require("impromptu")
local log = require("jazz.log").msg
Expand Down Expand Up @@ -29,14 +30,7 @@ navigation.symbols = function(ns)
title = "🎵 Navigate to symbols",
options = {},
handler = function(_, selected)
acid.run(ops["info"]{ns = selected.ns, symbol = selected.var}:with_handler(function(ret)

local fpath = vim.api.nvim_call_function("AcidFindFileInPath", {ret.file, ret.resource})
vim.api.nvim_command("edit " .. fpath)

vim.api.nvim_win_set_cursor(window, {ret.line, ret.column})

end))
go_to(selected.var, selected.ns)
return true
end
}
Expand Down
137 changes: 97 additions & 40 deletions lua/jazz/nrepl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local impromptu = require("impromptu")
local connections = require('acid.connections')
local nrepl = require('acid.nrepl')
local acid_utils = require('acid.utils')
local acid = require("acid")
local eval = require("acid.ops").eval

local find_value = function(tbl, val)
for ix, v in ipairs(tbl) do
Expand All @@ -17,11 +19,11 @@ local jazz_nrepl = {}

local select_portno = function(handler)
return impromptu.new.form{
title = "🎵 Select port number:",
questions = {portno = {description = "Port number"}},
handler = function(session, result)
return handler(session, result)
end
title = "🎵 Select port number:",
questions = {portno = {description = "Port number"}},
handler = function(session, result)
return handler(session, result)
end
}
end

Expand All @@ -33,12 +35,67 @@ local existing = function(obj)
end)
end

local run_alias = function(obj)
local options = {
start = {
description = "Start",
hl = "Function"
}
}

local spawn_options = {
pwd = obj.pwd,
alias = {}
}

local new_session = obj.session:stack(impromptu.new.ask{
title = "🎵 From deps.edn",
options = options,
handler = function(session, selected)
if selected.tp == "alias" then
table.insert(spawn_options.alias, selected.description)
session.lines[selected.description].hl = "String"
else
nrepl.start(spawn_options)
return true
end
end
})
local admin = acid.admin_session()
acid.run(eval{
code = '(map println (keys (:aliases (clojure.edn/read-string (slurp "' ..
obj.pwd .. "/" ..obj.file ..
'")))))'}:with_handler(function(data)
if data.status or data.value then
return
end

for _, v in ipairs(acid_utils.split_lines(data.out)) do
options[v] = {
description = v,
tp = "alias",
hl = "Comment"
}
end

new_session:render()
end),
admin)

return false
end

local toolsdeps = function(obj)
local files = vim.api.nvim_call_function("expand", {"**/*.edn", true, true})

if #files == 1 and files[1] == "deps.edn" then
nrepl.start{pwd = obj.pwd}
return true
local admin = acid.admin_session()
if admin == nil then
nrepl.start{pwd = obj.pwd}
return true
else
return run_alias{file = files[1], session = obj.session, pwd = obj.pwd}
end
end

local options = {}
Expand All @@ -53,9 +110,8 @@ local toolsdeps = function(obj)
obj.session:stack(impromptu.new.ask{
title = "🎵 Select deps.edn file",
options = options,
handler = function(_, selected)
nrepl.start{pwd = obj.pwd, deps_file = selected.description, alias = "-R:nrepl"}
return true
handler = function(session, selected)
return run_alias{file = selected.description, session = session, pwd = obj.pwd}
end
})

Expand All @@ -64,28 +120,28 @@ end

local connect_nrepl = function(obj)
return impromptu.new.form{
title = "🎵 Connect nrepl to:",
questions = {
portno = {description = "Port number"},
host = {description = "Host address"}
},
handler = function(session, result)
obj.port = tonumber(result.portno)
obj.host = result.host
obj.connect = true

session:pop()

session.lines.connect.description = "Connect to remote nrepl? (true)"
session.lines.connect.hl = "String"

session.lines.host.description = "Connect to address(" .. result.host .. ")"
session.lines.host.hl = "String"

session.lines.port.description = "Port number (" .. result.portno .. ")"
session.lines.port.hl = "String"
return false
end
title = "🎵 Connect nrepl to:",
questions = {
portno = {description = "Port number"},
host = {description = "Host address"}
},
handler = function(session, result)
obj.port = tonumber(result.portno)
obj.host = result.host
obj.connect = true

session:pop()

session.lines.connect.description = "Connect to remote nrepl? (true)"
session.lines.connect.hl = "String"

session.lines.host.description = "Connect to address(" .. result.host .. ")"
session.lines.host.hl = "String"

session.lines.port.description = "Port number (" .. result.portno .. ")"
session.lines.port.hl = "String"
return false
end
}
end

Expand All @@ -110,23 +166,23 @@ local custom_nrepl = function(obj)
}

--opts.bind = {
--description = "Bind to address (127.0.0.1)",
--hl = "Comment"
--description = "Bind to address (127.0.0.1)",
--hl = "Comment"
--}

--opts.host = {
--description = "Connect to address (127.0.0.1)",
--hl = "Comment"
--description = "Connect to address (127.0.0.1)",
--hl = "Comment"
--}

--opts.connect = {
--description = "Connect to remote nrepl? (false)",
--hl = "Comment"
--description = "Connect to remote nrepl? (false)",
--hl = "Comment"
--}

--opts.pwd = {
--description = "Directory (" .. obj.pwd .. ")",
--hl = "Comment"
--description = "Directory (" .. obj.pwd .. ")",
--hl = "Comment"
--}

opts.start = {description = "Start with custom configuration"}
Expand Down Expand Up @@ -169,6 +225,7 @@ local custom_nrepl = function(obj)
}
end


jazz_nrepl.nrepl_menu = function(pwd)
pwd = pwd or vim.api.nvim_call_function("getcwd", {})
if not acid_utils.ends_with(pwd, "/") then
Expand Down
19 changes: 14 additions & 5 deletions lua/jazz/usages.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- luacheck: globals unpack vim
local acid = require('acid')
local go_to = require("acid.features").go_to
local forms = require('acid.forms')
local commands = require('acid.commands')
local impromptu = require('impromptu')
Expand All @@ -23,8 +24,8 @@ usages.find_all = function(symbol, ns)
local ui = impromptu.filter{
title = "🎵 Finding usages of [" .. ns .. "/" .. symbol .. "]",
options = {},
handler = function(_, obj)
local data = obj.data.occurrence
handler = function(_, selected)
local data = selected.data.occurrence

local fpath = data.file
local col = math.floor(data['col-beg'] or 1)
Expand All @@ -35,15 +36,23 @@ usages.find_all = function(symbol, ns)
else
vim.api.nvim_command(winnr .. "wincmd w | edit +" .. ln .. " " .. fpath)
end

return true
end
}

local acid_handler = function(data)
if data.occurrence ~= nil then
if data.err ~= nil then
vim.api.nvim_err_writeln(data.ex)
vim.api.nvim_err_writeln(data.err)
ui:handle("__quit")
return
elseif data.occurrence ~= nil then
--[[
2019-12-06 16:02:39,935 - [acid :INFO] - {'col-beg': 1, 'col-end': 5, 'file': '/opt/code/klarna/exam.ple/src/exam/ple.clj', 'line-beg': 5, 'line-end': 6, 'match': '(defn my-function []\n 1)', 'name': 'exam.ple/my-function'}
--]]
local occr_ns = vim.fn.AcidGetNs(data.occurrence.file)
local descr = (
data.occurrence.match .. " @ " .. data.occurrence.file .. ":" .. math.floor(data.occurrence['line-beg'])
data.occurrence.match .. " @ " .. occr_ns .. " [" .. math.floor(data.occurrence['line-beg']) .. ":" .. math.floor(data.occurrence['col-beg']) .. ']'
):gsub("\n", "\\n")

ui:update{description = descr, data = data}
Expand Down
16 changes: 16 additions & 0 deletions lua/jazz/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@ utils.map = function(fn, tbl)
return new
end

utils.iter_map = function(fn, iter, c, zero)
return function(inv, cc)
local ix, value = iter(inv, cc)
return ix, fn(value)
end, c, zero
end

utils.contains = function(item, iter)
for _, v in ipairs(iter) do
if v == item then
return true
end
end
return false
end

return utils
5 changes: 3 additions & 2 deletions plugin/jazz.vim
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
command! -nargs=0 JazzNrepl lua require('jazz.nrepl').nrepl_menu()
command! -nargs=? JazzFindUsages lua require('jazz.usages').find_all(<f-args>)
command! -nargs=0 JazzNavigateSymbols lua require('jazz.navigation').symbols()
command! -nargs=? JazzFindSymbols lua require('jazz.navigation').symbols(<f-args>)

nmap <C-j>n <Cmd>JazzNrepl<CR>

augroup Jazz
au FileType clojure nmap <buffer> <C-j>u <Cmd>JazzFindUsages<Cr>
au FileType clojure nmap <buffer> <C-j>s <Cmd>JazzNavigateSymbols<Cr>
au FileType clojure nmap <buffer> <C-j>s <Cmd>lua require('jazz.navigation').symbols()<Cr>
au FileType clojure nmap <buffer> <C-j>a <Cmd>lua require("jazz.files").alternate()<Cr>
au FileType clojure nmap <buffer> <C-j>f <Cmd>lua require("jazz.files").new()<Cr>
au FileType clojure nmap <buffer> <C-j>c <Cmd>lua require("jazz.interrupt").select_session()<Cr>
augroup END