summaryrefslogtreecommitdiff
path: root/fnl
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-04-22 20:42:34 +0200
committerMike Vink <mike1994vink@gmail.com>2023-04-22 20:42:34 +0200
commitb91bb045f335eb2e15bebc5fa108e5893b5d9951 (patch)
tree63491f4773069755ed5b8f5d344b202b34f23bc6 /fnl
parent1b6566231b8bfc8223fcbf11d1243d9328f65f4f (diff)
small things
Diffstat (limited to 'fnl')
-rw-r--r--fnl/conf/filetype.fnl44
-rw-r--r--fnl/conf/init.fnl3
-rw-r--r--fnl/conf/lsp.fnl2
-rw-r--r--fnl/conf/pkgs/cmp.fnl2
-rw-r--r--fnl/conf/pkgs/lspconfig.fnl7
-rw-r--r--fnl/conf/pkgs/null-ls.fnl33
-rw-r--r--fnl/conf/settings.fnl1
7 files changed, 76 insertions, 16 deletions
diff --git a/fnl/conf/filetype.fnl b/fnl/conf/filetype.fnl
new file mode 100644
index 0000000..29f64b0
--- /dev/null
+++ b/fnl/conf/filetype.fnl
@@ -0,0 +1,44 @@
+(fn playbook? [filename]
+ (P filename)
+ (local pattern (vim.regex :^playbook.*))
+ (pattern:match_str filename))
+
+(fn group-vars? [relative-dir]
+ (local pattern (vim.regex :group_vars$))
+ (pattern:match_str relative-dir))
+
+(fn roles? [relative-dir]
+ (local pattern (vim.regex :roles$))
+ (pattern:match_str relative-dir))
+
+(fn task? [relative-file]
+ (local pattern (vim.regex :.*tasks.*))
+ (pattern:match_str relative-file))
+
+(fn ansible-files? [items]
+ (local [item & rest] items)
+ (if (not item) :yaml
+ (task? item) :yaml.ansible
+ (roles? item) :yaml.ansible
+ (group-vars? item) :yaml.ansible
+ (ansible-files? rest)))
+
+(fn yaml-filetype [path buf]
+ (local [repo?]
+ (vim.fs.find :.git
+ {:upward true
+ :path (vim.fs.dirname path)
+ :stop (vim.fs.dirname (vim.loop.cwd))}))
+ (local files (or (not repo?) (icollect [path file-or-dir (vim.fs.dir (vim.fs.dirname repo?)
+ {:skip #(not= "."
+ ($1:sub 1
+ 1))
+ :depth 2})]
+ (do
+ path))))
+ (if (and repo? (playbook? (vim.fn.fnamemodify path ":t"))) :yaml.ansible
+ (and repo? (task? (vim.fn.fnamemodify path ":."))) :yaml.ansible
+ repo? (ansible-files? files)
+ :yaml))
+
+(vim.filetype.add {:extension {:yml yaml-filetype :yaml yaml-filetype}})
diff --git a/fnl/conf/init.fnl b/fnl/conf/init.fnl
index bf71329..6309919 100644
--- a/fnl/conf/init.fnl
+++ b/fnl/conf/init.fnl
@@ -7,11 +7,10 @@
(require :conf.pkgs)
(require :conf.lsp)
(require :conf.events)
+(require :conf.filetype)
(require :conf.newtab)
(require :conf.nix-develop)
-;; (require :conf.cmd)
-
(require :conf.diagnostic)
;; TODO: make a function that sets this autocommand: au BufWritePost currentfile :!curl -X POST -d "{\"previewRun\": true, \"yamlOverride\": \"$(cat % | yq -P)\", \"resources\": {\"repositories\": {\"self\": {\"refName\": \"refs/heads/branch\"}}}}" -s -H "Content-Type: application/json" -H "Authorization: Basic $WORK_AZDO_GIT_AUTH" "$WORK_AZDO_GIT_ORG_URL/Stater/_apis/pipelines/pipelineid/preview?api-version=7.1-preview.1" | jq -r '.finalYaml // .' > scratch.yaml
diff --git a/fnl/conf/lsp.fnl b/fnl/conf/lsp.fnl
index 3755d64..2dcd2f4 100644
--- a/fnl/conf/lsp.fnl
+++ b/fnl/conf/lsp.fnl
@@ -41,7 +41,7 @@
(vim.lsp.diagnostic.on_publish_diagnostics _ result ctx
config)
(vim.diagnostic.setloclist {:open false}))
- {:virtual_text false
+ {:virtual_text true
:underline true
:update_in_insert false
:severity_sort true}))
diff --git a/fnl/conf/pkgs/cmp.fnl b/fnl/conf/pkgs/cmp.fnl
index 51a88f0..76319f4 100644
--- a/fnl/conf/pkgs/cmp.fnl
+++ b/fnl/conf/pkgs/cmp.fnl
@@ -53,7 +53,7 @@
[:i :s]))
:<C-b> (cmp.mapping.scroll_docs -4)
:<C-f> (cmp.mapping.scroll_docs 4)
- :<C-A> (cmp.mapping.complete)
+ :<C-j> (cmp.mapping.complete)
:<CR> (cmp.mapping.confirm {:behavior (enum :ConfirmBehavior
:Replace)
:select true})}
diff --git a/fnl/conf/pkgs/lspconfig.fnl b/fnl/conf/pkgs/lspconfig.fnl
index c2803cd..8d01061 100644
--- a/fnl/conf/pkgs/lspconfig.fnl
+++ b/fnl/conf/pkgs/lspconfig.fnl
@@ -28,6 +28,13 @@
;; Show a code lens toggling the display of gc's choices.}
:buildFlags [:-tags=all]}}})
+(lspconfig.ansiblels.setup {:ansible {:ansible {:path :ansible}
+ :executionEnvironment {:enabled false}
+ :python {:interpreterPath :python}
+ :validation {:enabled true
+ :lint {:enabled false
+ :path :ansible-lint}}}})
+
;; (tset configs :fennel_language_server
;; {:default_config {;; replace it with true path
;; :cmd [:fennel-language-server]
diff --git a/fnl/conf/pkgs/null-ls.fnl b/fnl/conf/pkgs/null-ls.fnl
index 858d0d3..9908823 100644
--- a/fnl/conf/pkgs/null-ls.fnl
+++ b/fnl/conf/pkgs/null-ls.fnl
@@ -1,12 +1,21 @@
-(let [null-ls (require :null-ls)
- lsp-conf (require :conf.lsp)]
- (null-ls.setup {:update_on_insert false
- :on_attach (fn [client buf]
- (lsp-conf.attach client buf true))
- :sources [null-ls.builtins.formatting.black
- null-ls.builtins.formatting.goimports
- null-ls.builtins.formatting.gofumpt
- null-ls.builtins.formatting.raco_fmt
- null-ls.builtins.formatting.alejandra
- null-ls.builtins.formatting.terraform_fmt
- null-ls.builtins.formatting.fnlfmt]}))
+(local lsp-conf (require :conf.lsp))
+(local null-ls (require :null-ls))
+
+(local fmt null-ls.builtins.formatting)
+(local diag null-ls.builtins.diagnostics)
+
+(fn executable? [program]
+ (fn []
+ (= 1 (vim.fn.executable program))))
+
+(null-ls.setup {:update_in_insert false
+ :debug true
+ :on_attach (fn [client buf]
+ (lsp-conf.attach client buf true))
+ :sources [fmt.alejandra
+ fmt.fnlfmt
+ (fmt.black.with {:condition (executable? :black)})
+ (fmt.goimports.with {:condition (executable? :goimports)})
+ (fmt.gofumpt.with {:condition (executable? :gofumpt)})
+ (fmt.raco_fmt.with {:condition (executable? :raco)})
+ (fmt.terraform_fmt.with {:condition (executable? :terraform)})]})
diff --git a/fnl/conf/settings.fnl b/fnl/conf/settings.fnl
index aedb88e..d1d7a77 100644
--- a/fnl/conf/settings.fnl
+++ b/fnl/conf/settings.fnl
@@ -44,6 +44,7 @@
showbreak "﬋"
listchars { :tab " " :eol "﬋"}
list on
+ autoread on
autoindent on
smartindent on
expandtab on