-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resolve help tags ourselves in cmdline
Closes #631
- Loading branch information
Showing
4 changed files
with
98 additions
and
90 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local async = require('blink.cmp.lib.async') | ||
|
||
local help = {} | ||
|
||
--- Processes a help file and returns a list of tags asynchronously | ||
--- @param file string | ||
--- @return blink.cmp.Task | ||
--- TODO: rewrite using async lib, shared as a library in lib/fs.lua | ||
local function read_tags_from_file(file) | ||
return async.task.new(function(resolve) | ||
vim.uv.fs_open(file, 'r', 438, function(err, fd) | ||
if err or fd == nil then return resolve({}) end | ||
|
||
-- Read file content | ||
vim.uv.fs_fstat(fd, function(stat_err, stat) | ||
if stat_err or stat == nil then | ||
vim.uv.fs_close(fd) | ||
return resolve({}) | ||
end | ||
|
||
vim.uv.fs_read(fd, stat.size, 0, function(read_err, data) | ||
vim.uv.fs_close(fd) | ||
|
||
if read_err or data == nil then return resolve({}) end | ||
|
||
-- Process the file content | ||
local tags = {} | ||
for line in data:gmatch('[^\r\n]+') do | ||
local tag = line:match('^([^\t]+)') | ||
if tag then table.insert(tags, tag) end | ||
end | ||
|
||
resolve(tags) | ||
end) | ||
end) | ||
end) | ||
end) | ||
end | ||
|
||
function help.get_completions() | ||
local help_files = vim.api.nvim_get_runtime_file('doc/tags', true) | ||
return async.task | ||
.await_all(vim.tbl_map(read_tags_from_file, help_files)) | ||
:map(function(results) return require('blink.cmp.lib.utils').flatten(results) end) | ||
end | ||
|
||
return help |
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 was deleted.
Oops, something went wrong.