Skip to content

Commit 3ad6842

Browse files
authored
Merge pull request #26 from clojure-vim/lua/wrapper
Lua/wrapper
2 parents 041cd8b + 22bbf73 commit 3ad6842

20 files changed

+418
-97
lines changed

rplugin/python3/acid/clj_fns/manage_requires.clj renamed to clj/acid/refactor/manage_requires.clj

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(ns acid.refactor.manage-requires)
2+
13
(defn manipulate-req [reqs modify]
24
(let [[[h] v] (split-at 1 reqs)]
35
(conj (sort-by first (modify v)) h)))

clj/acid/test/report.clj

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(ns acid.test.report
2+
(:require [clojure.test :as ct]))
3+
4+
(def ^:dynamic details nil)
5+
6+
(defn- with-error [m k c]
7+
(if (some? (k c))
8+
(update c k conj m)
9+
(assoc c k [m])))
10+
11+
(defmulti acid-clj-test-report :type)
12+
13+
(defmethod acid-clj-test-report :pass [m]
14+
(ct/inc-report-counter :pass))
15+
16+
(defmethod acid-clj-test-report :fail [m]
17+
(ct/inc-report-counter :fail)
18+
(swap! details (partial with-error m :failures)))
19+
20+
(defmethod acid-clj-test-report :error [m]
21+
(ct/inc-report-counter :error)
22+
(swap! details (partial with-error m :errors)))
23+
24+
(defmethod acid-clj-test-report :summary [m])
25+
26+
(defmethod acid-clj-test-report :default [m])
27+
(defmethod acid-clj-test-report :begin-test-ns [m])
28+
(defmethod acid-clj-test-report :end-test-ns [m])
29+
(defmethod acid-clj-test-report :begin-test-var [m])
30+
(defmethod acid-clj-test-report :end-test-var [m])
31+
32+
33+
(defn run-n-tests [run-test-fn args]
34+
(binding [ct/report acid-clj-test-report
35+
details (atom {})]
36+
(-> (apply run-test-fn args)
37+
(merge @details)
38+
(dissoc :type))))
39+
40+
(defn run-all-tests [] (run-n-tests ct/run-all-tests []))
41+
(defn run-tests [& nss] (run-n-tests ct/run-tests nss))

lua/acid/init.lua

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- luacheck: globals unpack vim
2+
local nvim = vim.api
3+
4+
local indirection = {}
5+
local acid = {}
6+
7+
acid.send = function(obj, handler)
8+
local session = math.random(10000, 99999)
9+
10+
indirection[session] = handler
11+
12+
nvim.nvim_call_function("AcidSendNrepl", {
13+
obj,
14+
"LuaFn",
15+
"require('acid').callback(" .. session .. ", _A)"
16+
})
17+
end
18+
19+
acid.callback = function(session, ret)
20+
return indirection[session](ret)
21+
end
22+
23+
return acid

rplugin/python3/acid/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,16 @@ def acid_unset_session(self):
125125
def acid_command(self, args):
126126
cmd, *args = args
127127
log_info(r"Received args for command {}: {}", cmd, args)
128+
command = self.extensions['commands'].get(cmd.strip())
129+
128130
url = formatted_localhost_address(self.nvim)
129131

130-
if url is None:
132+
if url is None and command.handlers:
131133
path = current_path(self.nvim)
132134
echo(self.nvim, "No REPL open")
133135
log_info("No repl open on path {}".format(path))
134136
return
135137

136-
command = self.extensions['commands'].get(cmd.strip())
137138
command.call(self, self.context(), *args)
138139

139140
@neovim.function("AcidCommandMeta", sync=True)

rplugin/python3/acid/commands/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ def __init__(self, nvim):
3131
def on_init(self):
3232
pass
3333

34+
def on_configure(self, *args, **kwargs):
35+
return []
36+
3437
def prepare_payload(self, *args):
3538
return {}
3639

3740
def configure(self, context, handler, *args):
38-
handler.configure(*args, **context)
41+
data = [*self.on_configure(*args, **context), *args]
42+
handler.configure(*data, **context)
3943
return handler
4044

4145
def start_handler(self, context, handler, *args):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from acid.commands import BaseCommand
2+
from acid.pure.doc_fmt import doc_transform
3+
from acid.nvim import path_to_ns, log
4+
5+
def tf(f):
6+
if type(f) == list:
7+
return ', '.join(f)
8+
return f
9+
10+
definition = {
11+
'data': {
12+
'spec-name': {},
13+
'spec-form': {
14+
'transform': lambda k: [
15+
tf(i) for i in k
16+
]
17+
},
18+
},
19+
'format': [
20+
'spec-name',
21+
[],
22+
'spec-form'
23+
]
24+
}
25+
26+
27+
class Command(BaseCommand):
28+
29+
name = 'DescribeSpec'
30+
priority = 0
31+
nargs = 1
32+
handlers = ['Doc']
33+
op = "spec-form"
34+
shorthand_mapping = 'css'
35+
shorthand="call setreg('s', expand('<cword>'))"
36+
37+
def on_configure(self, *_a, **_k):
38+
log.log_debug('Passing spec transformation fn')
39+
return [doc_transform(definition)]
40+
41+
def prepare_payload(self, data):
42+
return {'spec-name': data}
43+

rplugin/python3/acid/commands/doc.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,57 @@
11
from acid.commands import BaseCommand
2-
from acid.nvim import path_to_ns
2+
from acid.nvim import path_to_ns, log
3+
from acid.pure.doc_fmt import doc_transform
4+
from collections import OrderedDict
5+
6+
7+
definition = {
8+
'data': OrderedDict([
9+
['name', {}],
10+
['ns', {'default': ''}],
11+
['arglists-str', {
12+
'default': [],
13+
'rename': 'fn_calls',
14+
'transform': lambda t, name: ' '.join([
15+
'({}{})'.format(name, ' {}'.format(i) if i else '')
16+
for i in t[2:-2].split('] [')
17+
])
18+
}],
19+
['doc', {
20+
'default': '',
21+
'transform': lambda k: [i.strip() for i in k.split('\n')]
22+
}],
23+
['javadoc', {'default': ''}],
24+
['added', {'default': '', 'transform': 'Since version: {}'.format}],
25+
['super', {'default': '', 'transform': 'Extends: {}'.format}],
26+
['modifiers', {'default': []}],
27+
['see-also', {
28+
'default': [],
29+
'prepend': 'See Also:',
30+
'transform': lambda k: [
31+
'https://clojuredocs.org/{}'.format(i)
32+
for i in k
33+
]
34+
}],
35+
['interfaces', {
36+
'default': [],
37+
'transform': lambda k: 'Implements: {}'.format(', '.join(k))
38+
}]
39+
]),
40+
'format': [
41+
'fn_calls',
42+
[],
43+
'ns',
44+
'modifiers',
45+
[],
46+
'javadoc',
47+
'doc',
48+
[],
49+
'added',
50+
'interfaces',
51+
'super',
52+
'see-also',
53+
]
54+
}
355

456

557
class Command(BaseCommand):
@@ -12,6 +64,10 @@ class Command(BaseCommand):
1264
shorthand_mapping = 'K'
1365
shorthand="call setreg('s', expand('<cword>'))"
1466

67+
def on_configure(self, *_a, **_k):
68+
log.log_debug('Passing doc transformation fn')
69+
return [doc_transform(definition)]
70+
1571
def prepare_payload(self, data):
1672
return {"symbol": data, "ns": path_to_ns(self.nvim)}
1773

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from acid.commands import BaseCommand
2+
from acid.nvim import list_clj_files
3+
import os
4+
5+
def transform_path_to_ns(path):
6+
return os.path.splitext(os.path.basename(path))[0].replace('_', '-')
7+
8+
class Command(BaseCommand):
9+
10+
name = 'ListClj'
11+
priority = 0
12+
enabled = 0
13+
nargs = 0
14+
handlers = []
15+
mapping = 'clf'
16+
17+
def prepare_payload(self, ns):
18+
clj_files = [i for i in list_clj_files(self.nvim)]
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from acid.commands import BaseCommand
2+
from acid.nvim import list_clj_files, current_path, log
3+
from acid.pure import ns_to_path
4+
import os
5+
6+
7+
class Command(BaseCommand):
8+
9+
name = 'LoadFile'
10+
priority = 0
11+
handlers = ['Ignore']
12+
nargs = 1
13+
prompt = 1
14+
op = "load-file"
15+
16+
def prepare_payload(self, ns):
17+
files = list(list_clj_files(self.nvim))
18+
path = '{}.clj'.format(ns_to_path(ns))
19+
20+
log.log_debug('Found all this clojure files: {}', files)
21+
log.log_debug('Attempting to match against {}', path)
22+
23+
match = list(filter(lambda k: k.endswith(path), files))
24+
if any(match):
25+
fpath, *_ = match
26+
fpath = os.path.relpath(fpath, start=current_path(self.nvim))
27+
with open(fpath, 'r') as source:
28+
data = '\n'.join(source.readlines())
29+
30+
return {
31+
'file': data,
32+
'file-path': fpath,
33+
'file-name': os.path.basename(fpath)
34+
}
35+
else:
36+
log.warning(self.nvim, 'no file found!')

rplugin/python3/acid/commands/new.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def prepare_payload(self, ns):
2626
open_with = self.nvim.vars.get('acid_open_new_file_with', 'edit')
2727
path = os.path.join(current_path(self.nvim), base, fname)
2828
directory = os.path.dirname(path)
29+
2930
if not os.path.exists(directory):
3031
os.makedirs(directory)
3132

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from acid.commands import BaseCommand
2+
from acid.nvim import get_acid_ns, find_clojure_fn
3+
import os
4+
5+
6+
class Command(BaseCommand):
7+
8+
name = 'RunTests'
9+
priority = 0
10+
enabled = 0
11+
handlers = ['Ignore']
12+
nargs='*'
13+
op = "eval"
14+
requires = ['acid.test.report']
15+
16+
def prepare_payload(self, *args):
17+
pass
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from acid.commands import BaseCommand
2+
from acid.zen.ui import build_window
3+
from acid.nvim.log import warning
4+
import random
5+
import os
6+
7+
8+
class Command(BaseCommand):
9+
10+
name = 'Scratchpad'
11+
priority = 0
12+
nargs=0
13+
handlers = []
14+
mapping = 'csp'
15+
16+
@staticmethod
17+
def prompt_default(nvim):
18+
path = nvim.funcs.expand('%:p:h')
19+
return "{}.".format(path_to_ns(path))
20+
21+
22+
def prepare_payload(self):
23+
send = "map <buffer> <silent> <localleader><CR> {}".format(
24+
"".join(map(
25+
str.strip,
26+
""":call AcidSendNrepl({'op': 'eval',
27+
'code': join(getline(1, '$'), '\\n')}, 'MetaRepl')
28+
<CR>""".splitlines()
29+
))
30+
)
31+
32+
cmds = ['file acid://scratch-buffer-{}'.format(random.randint(0, 100)),
33+
'set ft=clojure',
34+
'let b:acid_ns_strategy="ns:user"',
35+
'nmap <buffer> <silent> q :bd! %<CR>',
36+
send,
37+
]
38+
39+
40+
build_window(
41+
self.nvim,
42+
throwaway=1,
43+
orientation="rightbelow 20 split",
44+
commands=cmds,
45+
)
46+
47+
return None

rplugin/python3/acid/handlers/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self):
2727
def configure(self, *args, **kwargs):
2828
self.nvim = kwargs['nvim']
2929
self.context = kwargs
30+
self.on_configure(*args, **kwargs)
3031
return self
3132

3233
def new_child_handler(self, handler):
@@ -43,6 +44,9 @@ def pass_to(self, msg, handler):
4344
def on_init(self):
4445
pass
4546

47+
def on_configure(self, *_a, **_k):
48+
pass
49+
4650
def on_pre_send(self, *_):
4751
pass
4852

rplugin/python3/acid/handlers/doautocmd.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ def on_init(self):
1010
self.cmd_group = ""
1111
self.successful = True
1212

13-
def configure(self, cmd_group, *args, **kwargs):
14-
super().configure(*args, **kwargs)
13+
def on_configure(self, cmd_group, *args, **kwargs):
1514
self.cmd_group = cmd_group
16-
return self
1715

1816
def on_handle(self, msg, *_):
1917
self.successful = self.successful and not 'err' in msg

0 commit comments

Comments
 (0)