This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 785
perf: modularize built-ins #288
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d78734b
perf: modularize built-ins
1aea5fc
doc: organize alphabetically and mention undocumented sources
f6dc0a0
test: fix test builtins
c4260bf
Merge branch 'main' into modularize-builtins
3ab1b84
refactor(builtins): modularize completion sources
c350b74
doc: misc cleanup
9841276
chore: fix style
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local h = require("null-ls.helpers") | ||
local methods = require("null-ls.methods") | ||
|
||
local COMPLETION = methods.internal.COMPLETION | ||
|
||
return h.make_builtin({ | ||
method = COMPLETION, | ||
filetypes = {}, | ||
name = "spell", | ||
generator = { | ||
fn = function(params, done) | ||
local get_candidates = function(entries) | ||
local items = {} | ||
for k, v in ipairs(entries) do | ||
items[k] = { label = v, kind = vim.lsp.protocol.CompletionItemKind["Text"] } | ||
end | ||
|
||
return items | ||
end | ||
|
||
local candidates = get_candidates(vim.fn.spellsuggest(params.word_to_complete)) | ||
done({ { items = candidates, isIncomplete = #candidates } }) | ||
end, | ||
async = true, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local h = require("null-ls.helpers") | ||
local methods = require("null-ls.methods") | ||
local utils = require("null-ls.utils") | ||
|
||
local COMPLETION = methods.internal.COMPLETION | ||
|
||
return h.make_builtin({ | ||
method = COMPLETION, | ||
filetypes = {}, | ||
name = "tags", | ||
generator_opts = { | ||
runtime_condition = function(_) | ||
return #vim.fn.tagfiles() > 0 | ||
end, | ||
}, | ||
generator = { | ||
fn = function(params, done) | ||
-- Tags look up can be expensive. | ||
if #params.word_to_complete < 4 then | ||
done({ { items = {}, isIncomplete = false } }) | ||
return | ||
end | ||
|
||
local tags = vim.fn.taglist(params.word_to_complete) | ||
if tags == 0 then | ||
done({ { items = {}, isIncomplete = false } }) | ||
return | ||
end | ||
|
||
local words = {} | ||
local items = {} | ||
for _, tag in ipairs(tags) do | ||
table.insert(words, tag.name) | ||
end | ||
|
||
words = utils.table.uniq(words) | ||
for _, word in ipairs(words) do | ||
table.insert(items, { | ||
label = word, | ||
insertText = word, | ||
}) | ||
end | ||
|
||
done({ { items = items, isIncomplete = #items == 0 } }) | ||
end, | ||
async = true, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local u = require("null-ls.utils") | ||
local methods = require("null-ls.methods") | ||
local config = require("null-ls.config").get() | ||
|
||
local M = {} | ||
|
||
M.handler = function(method, original_params, handler) | ||
local params = u.make_params(original_params, methods.map[method]) | ||
if method == methods.lsp.COMPLETION then | ||
require("null-ls.generators").run_registered({ | ||
filetype = params.ft, | ||
method = methods.map[method], | ||
params = params, | ||
callback = function(results) | ||
u.debug_log("received completion results from generators") | ||
u.debug_log(results) | ||
if #results == 0 then | ||
handler({}) | ||
else | ||
local items = {} | ||
local isIncomplete = false | ||
for _, result in ipairs(results) do | ||
isIncomplete = isIncomplete or result.isIncomplete | ||
|
||
if config.debug then | ||
vim.validate({ | ||
items = { result.items, "table" }, | ||
isIncomplete = { result.isIncomplete, "boolean" }, | ||
}) | ||
|
||
vim.validate({ | ||
item = { result.items[1], "table" }, | ||
}) | ||
end | ||
|
||
vim.list_extend(items, result.items) | ||
end | ||
|
||
handler({ isIncomplete = isIncomplete, items = items }) | ||
end | ||
end, | ||
}) | ||
original_params._null_ls_handled = true | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if shfmt supports zsh actually.
mvdan/sh#120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange – I've been using
shfmt
forzsh
since we added it about 2 weeks ago and haven't run into any problems. I don't know much about the project, but maybe the issue you linked is about a different feature?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not so sure, I just tried it myself for the first time and it reformatted:
to
which is not valid and errors with
bad math expression
. There is no mention of official support for zsh in shfmt's repository, so I would recommend not setting it as default option here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it – I'll remove it from the defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, amazing refactor btw, excellent work on null-ls, using it every day!