From c622dd62069cab9a518216cf23a0c6b14acdd847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Tue, 3 May 2022 17:55:10 +0200 Subject: [PATCH] Add basic ledger completion source to null-ls --- .../nvim/lua/esensar/lsp/diagnostic.lua | 3 ++ .../lua/esensar/lsp/null-ls_sources/init.lua | 3 ++ .../esensar/lsp/null-ls_sources/ledger.lua | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/ledger.lua diff --git a/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua b/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua index 8ce929e..737e4cb 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua @@ -53,6 +53,9 @@ null_ls.setup({ -- Godot custom_sources.formatters.gdformat, custom_sources.diagnostics.gdlint, + + -- Vim-Ledger + custom_sources.completion.ledger, }, on_attach = common_config.on_attach, }) diff --git a/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/init.lua b/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/init.lua index ee52e3f..a30eb79 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/init.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/init.lua @@ -6,4 +6,7 @@ return { diagnostics = { gdlint = require("esensar.lsp.null-ls_sources.gdlint"), }, + completion = { + ledger = require("esensar.lsp.null-ls_sources.ledger"), + }, } diff --git a/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/ledger.lua b/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/ledger.lua new file mode 100644 index 0000000..c7dbfb2 --- /dev/null +++ b/symlinks/config/nvim/lua/esensar/lsp/null-ls_sources/ledger.lua @@ -0,0 +1,40 @@ +local null_ls = require("null-ls") +local helpers = require("null-ls.helpers") + +return { + name = "ledger-complete", + meta = { + url = "https://github.com/ledger/vim-ledger", + description = "vim-ledger omnifunc completion source", + }, + method = null_ls.methods.COMPLETION, + filetypes = { "ledger" }, + generator = helpers.generator_factory({ + fn = function(params, done) + -- This can be slow + if #params.word_to_complete < 4 then + done({ { items = {}, isIncomplete = false } }) + return + end + + vim.fn.LedgerComplete(1, nil) + local results = vim.fn.LedgerComplete(0, #params.word_to_complete) + + local words = {} + local items = {} + for result in ipairs(results) do + table.insert(words, result) + end + + for _, word in ipairs(words) do + table.insert(items, { + label = word, + insertText = word, + }) + end + + done({ { items = items, isIncomplete = #items == 0 } }) + end, + async = true, + }), +}