feat: v1 options menu (#133)

Still has a bunch of improvements that can be done, but wanted to merge in some of the related changes.

* options parser

* wip: vimoptions finder

* feat: pre-populate ex-command line with `:set foo=`

* use options current value when populating command line

* fix: use result.raw_value to store original option value

* .

* options: Continue work on option finder

* [WIP]: Tue 27 Oct 2020 10:34:09 PM EDT

* [WIP]: Mon 02 Nov 2020 08:20:13 PM EST

* [WIP]: Mon 02 Nov 2020 09:04:23 PM EST

Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
This commit is contained in:
Senghan Bright
2020-11-02 21:05:10 -05:00
committed by GitHub
co-authored by TJ DeVries
parent 855d818a5d
commit 051aefdb8c
5 changed files with 303 additions and 14 deletions
+107
View File
@@ -1,6 +1,7 @@
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')
local conf = require('telescope.config').values
local entry_display = require('telescope.pickers.entry_display')
local path = require('telescope.path')
local utils = require('telescope.utils')
@@ -465,4 +466,110 @@ function make_entry.gen_from_marks(_)
end
end
function make_entry.gen_from_vimoptions(opts)
-- TODO: Can we just remove this from `options.lua`?
function N_(s)
return s
end
local process_one_opt = function(o)
local ok, value_origin
local option = {
name = "",
description = "",
current_value = "",
default_value = "",
value_type = "",
set_by_user = false,
last_set_from = "",
}
local is_global = false
for _, v in ipairs(o.scope) do
if v == "global" then
is_global = true
end
end
if not is_global then
return
end
if is_global then
option.name = o.full_name
ok, option.current_value = pcall(vim.api.nvim_get_option, o.full_name)
if not ok then
return
end
local str_funcname = o.short_desc()
option.description = assert(loadstring("return " .. str_funcname))()
-- if #option.description > opts.desc_col_length then
-- opts.desc_col_length = #option.description
-- end
if o.defaults ~= nil then
option.default_value = o.defaults.if_true.vim or o.defaults.if_true.vi
end
if type(option.default_value) == "function" then
option.default_value = "Macro: " .. option.default_value()
end
option.value_type = (type(option.current_value) == "boolean" and "bool" or type(option.current_value))
if option.current_value ~= option.default_value then
option.set_by_user = true
value_origin = vim.fn.execute("verbose set " .. o.full_name .. "?")
if string.match(value_origin, "Last set from") then
-- TODO: parse file and line number as separate items
option.last_set_from = value_origin:gsub("^.*Last set from ", "")
end
end
return option
end
end
-- TODO: don't call this 'line'
local displayer = entry_display.create {
separator = "",
items = {
{ width = 25 },
{ width = 50 },
{ remaining = true },
},
}
local make_display = function(entry)
return displayer {
entry.name,
string.format(
"[%s] %s",
entry.value_type,
utils.display_termcodes(tostring(entry.current_value))),
entry.description,
}
end
return function(line)
local entry = process_one_opt(line)
if not entry then
return
end
entry.valid = true
entry.display = make_display
entry.value = line
entry.ordinal = line.full_name
-- entry.raw_value = d.raw_value
-- entry.last_set_from = d.last_set_from
return entry
end
end
return make_entry