Add basic ledger completion source to null-ls

main
Ensar Sarajčić 2022-05-03 17:55:10 +02:00
parent 56c611beee
commit c622dd6206
3 changed files with 46 additions and 0 deletions

View File

@ -53,6 +53,9 @@ null_ls.setup({
-- Godot -- Godot
custom_sources.formatters.gdformat, custom_sources.formatters.gdformat,
custom_sources.diagnostics.gdlint, custom_sources.diagnostics.gdlint,
-- Vim-Ledger
custom_sources.completion.ledger,
}, },
on_attach = common_config.on_attach, on_attach = common_config.on_attach,
}) })

View File

@ -6,4 +6,7 @@ return {
diagnostics = { diagnostics = {
gdlint = require("esensar.lsp.null-ls_sources.gdlint"), gdlint = require("esensar.lsp.null-ls_sources.gdlint"),
}, },
completion = {
ledger = require("esensar.lsp.null-ls_sources.ledger"),
},
} }

View File

@ -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,
}),
}