mirror of
https://github.com/elkowar/dots-of-war.git
synced 2024-11-06 03:12:24 +00:00
some more pain
This commit is contained in:
parent
118a7d1966
commit
c9c69c5ca9
3 changed files with 110 additions and 23 deletions
|
@ -1,9 +1,10 @@
|
||||||
(module help-thingy
|
(module help-thingy
|
||||||
{autoload {utils utils
|
{require {utils utils
|
||||||
a aniseed.core
|
a aniseed.core
|
||||||
str aniseed.string
|
str aniseed.string
|
||||||
fennel aniseed.fennel
|
fennel aniseed.fennel
|
||||||
popup popup}
|
popup popup
|
||||||
|
ts nvim-treesitter}
|
||||||
require-macros [macros]})
|
require-macros [macros]})
|
||||||
|
|
||||||
(defn get-current-word []
|
(defn get-current-word []
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
(def helpfiles-path (str.join "/" (a.butlast (str.split vim.o.helpfile "/"))))
|
(def helpfiles-path (str.join "/" (a.butlast (str.split vim.o.helpfile "/"))))
|
||||||
|
|
||||||
(def tags
|
(def tags
|
||||||
(let [entries {}]
|
(let [entries {}]
|
||||||
(each [line _ (io.lines (.. helpfiles-path "/tags"))]
|
(each [line _ (io.lines (.. helpfiles-path "/tags"))]
|
||||||
|
@ -28,12 +30,12 @@
|
||||||
(defn find-help-tag-for [topic]
|
(defn find-help-tag-for [topic]
|
||||||
(or (. tags topic)
|
(or (. tags topic)
|
||||||
(. tags (.. topic "()"))
|
(. tags (.. topic "()"))
|
||||||
(. tags (.. (string.gsub topic "vim.api." "") "()"))
|
(. tags (.. (string.gsub topic "vim%.api%." "") "()"))
|
||||||
(. tags (.. (string.gsub topic "vim.fn." "") "()"))
|
(. tags (.. (string.gsub topic "vim%.fn%." "") "()"))
|
||||||
(. tags (.. (string.gsub topic "fn." "") "()"))
|
(. tags (.. (string.gsub topic "fn%." "") "()"))
|
||||||
(. tags (.. (string.gsub topic "vim.o." "") "()"))
|
(. tags (.. (string.gsub topic "vim%.o%." "") "()"))
|
||||||
(. tags (.. (string.gsub topic "vim.b." "") "()"))
|
(. tags (.. (string.gsub topic "vim%.b%." "") "()"))
|
||||||
(. tags (.. (string.gsub topic "vim.g." "") "()"))))
|
(. tags (.. (string.gsub topic "vim%.g%." "") "()"))))
|
||||||
|
|
||||||
|
|
||||||
(defn help-for-tag [tag]
|
(defn help-for-tag [tag]
|
||||||
|
@ -50,14 +52,14 @@
|
||||||
(table.insert data line)
|
(table.insert data line)
|
||||||
(lua "return data")))))
|
(lua "return data")))))
|
||||||
|
|
||||||
(defn pop [text]
|
(defn pop [text ft]
|
||||||
(var width 0)
|
(var width 0)
|
||||||
(each [_ line (ipairs text)]
|
(each [_ line (ipairs text)]
|
||||||
(when (> (length line) width)
|
(when (> (length line) width)
|
||||||
(set width (length line))))
|
(set width (length line))))
|
||||||
(let [bufnr (vim.api.nvim_create_buf false true)]
|
(let [bufnr (vim.api.nvim_create_buf false true)]
|
||||||
(vim.api.nvim_buf_set_option bufnr :bufhidden "wipe")
|
(vim.api.nvim_buf_set_option bufnr :bufhidden "wipe")
|
||||||
(vim.api.nvim_buf_set_option bufnr :filetype "help")
|
(vim.api.nvim_buf_set_option bufnr :filetype ft)
|
||||||
(vim.api.nvim_buf_set_lines bufnr 0 -1 true text)
|
(vim.api.nvim_buf_set_lines bufnr 0 -1 true text)
|
||||||
(popup.create bufnr {:padding [1 1 1 1] :width width})))
|
(popup.create bufnr {:padding [1 1 1 1] :width width})))
|
||||||
|
|
||||||
|
@ -65,15 +67,82 @@
|
||||||
(fn _G.get_help []
|
(fn _G.get_help []
|
||||||
(let [help-tag (find-help-tag-for (get-current-word))]
|
(let [help-tag (find-help-tag-for (get-current-word))]
|
||||||
(when help-tag
|
(when help-tag
|
||||||
(pop (help-for-tag help-tag)))))
|
(pop (help-for-tag help-tag) :help))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(def all-module-paths
|
||||||
|
(let [paths (str.split package.path ";")]
|
||||||
|
(each [_ path (ipairs (str.split vim.o.runtimepath ","))]
|
||||||
|
(table.insert paths (.. path "/fnl/?.fnl"))
|
||||||
|
(table.insert paths (.. path "/fnl/?/init.fnl"))
|
||||||
|
(table.insert paths (.. path "/lua/?.lua"))
|
||||||
|
(table.insert paths (.. path "/lua/?/init.lua")))
|
||||||
|
paths))
|
||||||
|
|
||||||
|
|
||||||
|
(defn file-exists? [path]
|
||||||
|
(let [file (io.open path :r)]
|
||||||
|
(if (~= nil file)
|
||||||
|
(do (io.close file)
|
||||||
|
true)
|
||||||
|
false)))
|
||||||
|
|
||||||
|
(defn find-module-path [module-name]
|
||||||
|
(let [module-name (module-name:gsub "%." "/")]
|
||||||
|
(utils.find-map #(utils.keep-if file-exists? ($1:gsub "?" module-name))
|
||||||
|
all-module-paths)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn read-module-file [module-name]
|
||||||
|
(let [path (find-module-path module-name)]
|
||||||
|
(when path
|
||||||
|
(let [ft (match (string.gsub path ".+%.(%w+)" "%1")
|
||||||
|
:fnl "fennel"
|
||||||
|
:lua "lua")
|
||||||
|
result (icollect [line _ (io.lines path)]
|
||||||
|
line)]
|
||||||
|
(values result ft)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn gib-definition [mod word]
|
||||||
|
(let [(file-lines filetype) (read-module-file mod)
|
||||||
|
query (vim.treesitter.parse_query
|
||||||
|
filetype
|
||||||
|
(.. "((identifier) @fuck (#contains? @fuck \"" word "\"))"))
|
||||||
|
bufnr (vim.api.nvim_create_buf false true)]
|
||||||
|
(vim.api.nvim_buf_set_lines bufnr 0 -1 true file-lines)
|
||||||
|
(let [parser (vim.treesitter.get_parser bufnr filetype)
|
||||||
|
[tstree] (parser:parse)
|
||||||
|
tsnode (tstree:root)
|
||||||
|
code-lines []]
|
||||||
|
(each [id node metadata (query:iter_captures tsnode bufnr 0 -1)]
|
||||||
|
(let [parent (node:parent)
|
||||||
|
(r1 c1 r2 c2) (parent:range)]
|
||||||
|
(for [i (+ r1 1) r2]
|
||||||
|
(table.insert code-lines (. file-lines i)))))
|
||||||
|
(pop code-lines filetype))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(fn _G.gib_def []
|
||||||
|
(let [word (get-current-word)
|
||||||
|
segs (str.split word "%.")]
|
||||||
|
(match segs
|
||||||
|
[mod ident]
|
||||||
|
(gib-definition mod ident)
|
||||||
|
|
||||||
|
[ident]
|
||||||
|
(let [[current-file] (str.split (vim.fn.expand "%:t") "%.")]
|
||||||
|
(gib-definition current-file ident)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;(gib-definition "help-thingy" (ident)))
|
||||||
(utils.keymap :n :L ":call v:lua.get_help()<CR>")
|
(utils.keymap :n :L ":call v:lua.get_help()<CR>")
|
||||||
|
(utils.keymap :n :N ":call v:lua.gib_def()<CR>")
|
||||||
|
|
||||||
|
|
||||||
(def rtp vim.o.runtimepath)
|
|
||||||
(str.split rtp ",")
|
|
||||||
|
|
||||||
|
|
||||||
; vim.api.nvim_buf_get_name
|
; vim.api.nvim_buf_get_name
|
||||||
; vim.api.nvim_buf_call
|
; vim.api.nvim_buf_call
|
||||||
|
|
|
@ -58,4 +58,6 @@
|
||||||
:epic true}})
|
:epic true}})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;(print (fennel.view compe))
|
;(print (fennel.view compe))
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
(~= nil (. packer_plugins name)))
|
(~= nil (. packer_plugins name)))
|
||||||
|
|
||||||
(defn all [f xs]
|
(defn all [f xs]
|
||||||
(not (a.some (not (f $1)))))
|
(not (a.some #(not (f $1)))))
|
||||||
|
|
||||||
(defn single-to-list [x]
|
(defn single-to-list [x]
|
||||||
"Returns the list given to it. If given a single value, wraps it in a list"
|
"Returns the list given to it. If given a single value, wraps it in a list"
|
||||||
|
@ -23,6 +23,22 @@
|
||||||
(when (f k v)
|
(when (f k v)
|
||||||
(values k v))))
|
(values k v))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn find-where [pred xs]
|
||||||
|
(each [_ x (ipairs xs)]
|
||||||
|
(when (pred x)
|
||||||
|
(lua "return x"))))
|
||||||
|
|
||||||
|
(defn find-map [f xs]
|
||||||
|
(each [_ x (ipairs xs)]
|
||||||
|
(let [res (f x)]
|
||||||
|
(when (~= nil res)
|
||||||
|
(lua "return res")))))
|
||||||
|
|
||||||
|
(defn keep-if [f x]
|
||||||
|
(when (f x) x))
|
||||||
|
|
||||||
|
|
||||||
(defn without-keys [keys t]
|
(defn without-keys [keys t]
|
||||||
(filter-table #(not (contains? keys $1)) t))
|
(filter-table #(not (contains? keys $1)) t))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue