diff options
author | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-24 03:34:52 +0300 |
---|---|---|
committer | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-24 03:34:52 +0300 |
commit | f9b36bf730fda5488be87b91fd03a6f7cbf64e73 (patch) | |
tree | d8a7da573111d40c0e51c9e9954a3bb1977dd39c /lua/cmake-explorer | |
parent | 672f0d32e322b79661b5d7959887adaa9e41ad98 (diff) |
refactor: full rewrite
Diffstat (limited to 'lua/cmake-explorer')
-rw-r--r-- | lua/cmake-explorer/cache.lua | 47 | ||||
-rw-r--r-- | lua/cmake-explorer/capabilities.lua | 46 | ||||
-rw-r--r-- | lua/cmake-explorer/config.lua | 46 | ||||
-rw-r--r-- | lua/cmake-explorer/file_api.lua | 92 | ||||
-rw-r--r-- | lua/cmake-explorer/init.lua | 67 | ||||
-rw-r--r-- | lua/cmake-explorer/notification.lua | 14 | ||||
-rw-r--r-- | lua/cmake-explorer/project.lua | 283 | ||||
-rw-r--r-- | lua/cmake-explorer/project_uauaua.lua | 113 | ||||
-rw-r--r-- | lua/cmake-explorer/runner.lua | 84 | ||||
-rw-r--r-- | lua/cmake-explorer/telescope/make_entry.lua | 57 | ||||
-rw-r--r-- | lua/cmake-explorer/telescope/pickers.lua | 103 | ||||
-rw-r--r-- | lua/cmake-explorer/telescope/previewers.lua | 40 | ||||
-rw-r--r-- | lua/cmake-explorer/telescope/test.lua | 46 | ||||
-rw-r--r-- | lua/cmake-explorer/utils.lua | 92 |
14 files changed, 0 insertions, 1130 deletions
diff --git a/lua/cmake-explorer/cache.lua b/lua/cmake-explorer/cache.lua deleted file mode 100644 index 046a9f9..0000000 --- a/lua/cmake-explorer/cache.lua +++ /dev/null @@ -1,47 +0,0 @@ -local Cache = {} - -local os = { - iswin32 = vim.fn.has("win32") == 1, - ismac = vim.fn.has("mac") == 1, - iswsl = vim.fn.has("wsl") == 1, - islinux = vim.fn.has("linux") == 1, -} - -local dir = { - unix = vim.fn.expand("~") .. "/.cache/cmake_explorer_nvim/", - mac = vim.fn.expand("~") .. "/.cache/cmake_explorer_nvim/", - win = vim.fn.expand("~") .. "/AppData/Local/cmake_explorer_nvim/", -} - -local function get_cache_path() - if os.islinux then - return dir.unix - elseif os.ismac then - return dir.mac - elseif os.iswsl then - return dir.unix - elseif os.iswin32 then - return dir.win - end -end - -local function get_clean_path(path) - local current_path = path - local clean_path = current_path:gsub("/", "") - clean_path = clean_path:gsub("\\", "") - clean_path = clean_path:gsub(":", "") - return clean_path -end - -function Cache.load(path) - return -end - -function Cache.save_global(tbl) - local to_save = vim.tbl_deep_extend("keep", tbl) - setmetatable(to_save, nil) - local path = get_project_path() - local file = io.open(path, "w") -end - -return Cache diff --git a/lua/cmake-explorer/capabilities.lua b/lua/cmake-explorer/capabilities.lua deleted file mode 100644 index 052f484..0000000 --- a/lua/cmake-explorer/capabilities.lua +++ /dev/null @@ -1,46 +0,0 @@ -local config = require("cmake-explorer.config") - -local multiconfig_generators = { - "Ninja Multi-Config", - "Xcode", - "Visual Studio 12 2013", - "Visual Studio 14 2015", - "Visual Studio 15 2017", - "Visual Studio 16 2019", - "Visual Studio 17 2022", - "Green Hills MULTI", -} - -local Capabilities = { - json = nil, -} - -function Capabilities.generators() - local ret = {} - if not Capabilities then - return ret - end - for k, v in pairs(Capabilities.json.generators) do - table.insert(ret, v.name) - end - return vim.fn.reverse(ret) -end - -function Capabilities.is_multiconfig_generator(generator) - -- if generator is nil, assume is is not multiconifg - if not generator then - return - end - return vim.tbl_contains(multiconfig_generators, generator) -end - -function Capabilities.has_fileapi() - return vim.tbl_get(Capabilities.json, "fileApi") ~= nil -end - -Capabilities.setup = function() - local output = vim.fn.system({ config.cmake_path, "-E", "capabilities" }) - Capabilities.json = vim.json.decode(output) -end - -return Capabilities diff --git a/lua/cmake-explorer/config.lua b/lua/cmake-explorer/config.lua deleted file mode 100644 index 611f526..0000000 --- a/lua/cmake-explorer/config.lua +++ /dev/null @@ -1,46 +0,0 @@ -local default_config = { - cmake_path = "cmake", - environment = {}, - configure_environment = {}, - build_directory = "${workspaceFolder}/build-${buildType}", - build_environment = {}, - build_args = {}, - build_tool_args = {}, - generator = nil, - default_variants = { - { - default = "debug", - description = "Build type", - choices = { - debug = { short = "Debug", long = "Long debug", buildType = "Debug" }, - release = { short = "Release", long = "Long release", buildType = "Release" }, - }, - }, - { - default = "static", - choices = { - static = { short = "Static", long = "Long static", linkage = "static" }, - shared = { short = "Shared", long = "Long shared", linkage = "shared" }, - }, - }, - }, - variants_display = { - short_sep = " × ", - long_sep = " ❄ ", - }, - parallel_jobs = nil, - save_before_build = true, - source_directory = "${workspaceFolder}", -} - -local M = vim.deepcopy(default_config) - -M.setup = function(opts) - local newconf = vim.tbl_deep_extend("force", default_config, opts or {}) - - for k, v in pairs(newconf) do - M[k] = v - end -end - -return M diff --git a/lua/cmake-explorer/file_api.lua b/lua/cmake-explorer/file_api.lua deleted file mode 100644 index 37eda3a..0000000 --- a/lua/cmake-explorer/file_api.lua +++ /dev/null @@ -1,92 +0,0 @@ -local capabilities = require("cmake-explorer.capabilities") -local Path = require("plenary.path") -local Scandir = require("plenary.scandir") -local notif = require("cmake-explorer.notification") -local utils = require("cmake-explorer.utils") - -local query_path_suffix = { ".cmake", "api", "v1", "query", "client-cmake-explorer", "query.json" } -local reply_dir_suffix = { ".cmake", "api", "v1", "reply" } - -local FileApi = {} - -FileApi.__index = FileApi - -function FileApi:new(opts) - if not capabilities.has_fileapi() then - notif.notify("No fileapi files", vim.log.levels.ERROR) - return - end - local path - if type(opts) == "string" then - path = opts - end - local obj = { - path = path, - index = nil, - cmakefiles = nil, - codemodel = nil, - targets = {}, - } - setmetatable(obj, FileApi) - return obj -end - -function FileApi:create() - local query = Path:new(self.path, unpack(query_path_suffix)) - if not query:exists() then - if not query:touch({ parents = true }) then - notif.notify("Cannot create query file", vim.log.levels.ERROR) - return - end - query:write(vim.json.encode(capabilities.json.fileApi), "w") - end - Path:new(self.path, unpack(reply_dir_suffix)):mkdir({ parents = true }) - return true -end - -function FileApi:read_reply() - if not self:reply_exists() then - notif.notify("No reply directory", vim.log.levels.ERROR) - return - end - local reply_dir = Path:new(self.path, unpack(reply_dir_suffix)) - local index = Scandir.scan_dir(tostring(reply_dir), { search_pattern = "index*" }) - if #index == 0 then - notif.notify("No files in reply", vim.log.levels.ERROR) - return - end - self.index = vim.json.decode(Path:new(index[1]):read()) - for _, object in ipairs(self.index.objects) do - if object.kind == "codemodel" then - self.codemodel = vim.json.decode((reply_dir / object.jsonFile):read()) - for _, target in ipairs(self.codemodel.configurations[1].targets) do - self.targets[target.name] = vim.json.decode((reply_dir / target.jsonFile):read()) - end - elseif object.kind == "cmakeFiles" then - self.cmakefiles = vim.json.decode(Path:new(reply_dir / object.jsonFile):read()) - end - end - return true -end - -function FileApi:query_exists() - return Path:new(self.path, unpack(query_path_suffix)):exists() -end - -function FileApi:reply_exists() - local reply_dir = Path:new(self.path, unpack(reply_dir_suffix)) - if not reply_dir:exists() then - return - end - return true -end - -function FileApi:exists() - return self:query_exists() and self:reply_exists() -end - -function FileApi.is_fileapi(other) - return getmetatable(other) == FileApi -end - -return FileApi diff --git a/lua/cmake-explorer/init.lua b/lua/cmake-explorer/init.lua deleted file mode 100644 index 622eebd..0000000 --- a/lua/cmake-explorer/init.lua +++ /dev/null @@ -1,67 +0,0 @@ -local config = require("cmake-explorer.config") -local runner = require("cmake-explorer.runner") -local Project = require("cmake-explorer.project") -local capabilities = require("cmake-explorer.capabilities") -local utils = require("cmake-explorer.utils") -local Path = require("plenary.path") -local pickers = require("cmake-explorer.telescope.pickers") -local notif = require("cmake-explorer.notification") - -local M = {} - -M.project = nil - -local format_build_dir = function() - if Path:new(config.build_dir):is_absolute() then - return function(v) - return Path:new(v.path):make_relative(vim.env.HOME) - end - else - return function(v) - return Path:new(v.path):make_relative(M.project.path) - end - end -end - -function M.configure(opts) - assert(M.project) - opts = opts or {} - pickers.configure(opts) -end - -function M.configure_last(opts) - if not M.project.current_config then - notif.notify("No current configuration") - return - end - runner.start(M.project:configure_command()) -end - -function M.build(opts) - opts = opts or {} - pickers.build(opts) -end - -function M.build_last(opts) - if not M.project.current_config then - notif.notify("No current configuration") - return - end - runner.start(M.project:build_command()) -end - -function M.setup(opts) - opts = opts or {} - - config.setup(opts) - capabilities.setup() - - M.project = Project:from_variants(config.default_variants) - - if not M.project then - print("fuuuuuuuuuuuu") - return - end -end - -return M diff --git a/lua/cmake-explorer/notification.lua b/lua/cmake-explorer/notification.lua deleted file mode 100644 index 0029241..0000000 --- a/lua/cmake-explorer/notification.lua +++ /dev/null @@ -1,14 +0,0 @@ -local has_notify, notify = pcall(require, "notify") - -local Notification = {} - -function Notification.notify(msg, lvl, opts) - opts = opts or {} - if has_notify then - opts.hide_from_history = true - opts.title = "CMake Explorer" - return notify(msg, lvl, opts) - end -end - -return Notification diff --git a/lua/cmake-explorer/project.lua b/lua/cmake-explorer/project.lua deleted file mode 100644 index ca77728..0000000 --- a/lua/cmake-explorer/project.lua +++ /dev/null @@ -1,283 +0,0 @@ -local config = require("cmake-explorer.config") -local Path = require("plenary.path") -local utils = require("cmake-explorer.utils") -local FileApi = require("cmake-explorer.file_api") - -local VariantConfig = {} - -VariantConfig.__index = VariantConfig - -local variant_subs = { - ["${workspaceFolder}"] = vim.loop.cwd(), - ["${userHome}"] = vim.loop.os_homedir(), -} - -function VariantConfig:new(obj) - setmetatable(obj, VariantConfig) - obj.subs = obj:_subs() - obj.build_directory = obj:_build_directory() - obj.configure_args = obj:_configure_args() - obj.configure_command = obj:_configure_command() - obj.build_args = obj:_build_args() - obj.build_command = obj:_build_command() - if not obj.fileapis[obj.build_directory] then - local fa = FileApi:new(obj.build_directory) - if fa and fa:exists() then - fa:read_reply() - obj.fileapis[obj.build_directory] = fa - end - end - - return obj -end - -function VariantConfig:_subs() - return vim.tbl_deep_extend("keep", variant_subs, { ["${buildType}"] = self.buildType }) -end - -function VariantConfig:_build_directory() - return utils.substitude(config.build_directory, self.subs) -end - -function VariantConfig:_configure_args() - local args = {} - if self.generator then - table.insert(args, "-G " .. '"' .. self.generator .. '"') - end - if self.buildType then - table.insert(args, "-DCMAKE_BUILD_TYPE=" .. self.buildType) - end - if self.linkage and string.lower(self.linkage) == "static" then - table.insert(args, "-DCMAKE_BUILD_SHARED_LIBS=OFF") - elseif self.linkage and string.lower(self.linkage) == "shared" then - table.insert(args, "-DCMAKE_BUILD_SHARED_LIBS=ON") - end - for k, v in pairs(self.settings or {}) do - table.insert(args, "-D" .. k .. "=" .. v) - end - table.insert(args, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") - table.insert( - args, - "-B" .. Path:new(self.build_directory):make_relative(utils.substitude(config.source_directory, self.subs)) - ) - return args -end - -function VariantConfig:_configure_command() - local ret = {} - ret.cmd = config.cmake_path - ret.args = self.configure_args - ret.cwd = variant_subs["${workspaceFolder}"] - ret.env = vim.tbl_deep_extend("keep", self.env, config.configure_environment, config.environment) - ret.after_success = function() - utils.symlink_compile_commands(self.build_directory, variant_subs["${workspaceFolder}"]) - self.fileapis[self.build_directory]:read_reply() - end - ret.before_run = function() - self.current_config_ref = self - local fa = FileApi:new(self.build_directory) - if not fa then - return - end - if not fa:create() then - return - end - self.fileapis[self.build_directory] = fa - return true - end - return ret -end - -function VariantConfig:_build_args() - local args = { "--build" } - table.insert( - args, - Path:new(self.build_directory):make_relative(utils.substitude(config.source_directory, self.subs)) - ) - if #self.buildArgs ~= 0 then - for _, v in ipairs(self.buildArgs) do - table.insert(args, v) - end - elseif #config.build_args ~= 0 then - for _, v in ipairs(config.build_args) do - table.insert(args, v) - end - end - if #self.buildToolArgs ~= 0 or #config.build_tool_args ~= 0 then - table.insert(args, "--") - if #self.buildToolArgs ~= 0 then - for _, v in ipairs(self.buildToolArgs) do - table.insert(args, v) - end - elseif #config.build_tool_args ~= 0 then - for _, v in ipairs(config.build_tool_args) do - table.insert(args, v) - end - end - end - return args -end - -function VariantConfig:_build_command() - local ret = {} - ret.cmd = config.cmake_path - ret.args = self.build_args - ret.cwd = variant_subs["${workspaceFolder}"] - ret.env = vim.tbl_deep_extend("keep", self.env, config.configure_environment, config.environment) - return ret -end - -local function cartesian_product(sets) - local function collapse_result(res) - local ret = { - short = {}, - long = {}, - buildType = nil, - linkage = nil, - generator = nil, - buildArgs = {}, - buildToolArgs = {}, - settings = {}, - env = {}, - } - local is_default = true - for _, v in ipairs(res) do - if not v.default then - is_default = false - end - ret.short[#ret.short + 1] = v.short - ret.long[#ret.long + 1] = v.long - ret.buildType = v.buildType or ret.buildType - ret.linkage = v.linkage or ret.linkage - ret.generator = v.generator or ret.generator - ret.buildArgs = v.buildArgs or ret.buildArgs - ret.buildToolArgs = v.buildToolArgs or ret.buildToolArgs - for sname, sval in pairs(v.settings or {}) do - ret.settings[sname] = sval - end - for ename, eres in pairs(v.env or {}) do - ret.env[ename] = eres - end - end - ret.display = {} - ret.display.short = table.concat(ret.short, config.variants_display.short_sep) - ret.display.long = table.concat(ret.long, config.variants_display.short_sep) - ret.default = is_default or nil - return ret - end - local result = {} - local set_count = #sets - local function descend(depth) - for k, v in pairs(sets[depth].choices) do - if sets[depth].default ~= k then - result.default = false - end - result[depth] = v - result[depth].default = (k == sets[depth].default) - if depth == set_count then - coroutine.yield(collapse_result(result)) - else - descend(depth + 1) - end - end - end - return coroutine.wrap(function() - descend(1) - end) -end - -local Project = {} - -Project.__index = Project - -function Project:from_variants(variants) - local obj = - { headers = {}, display = { short_len = 10, long_len = 30 }, configs = {}, current_config = nil, fileapis = {} } - for _, v in pairs(variants) do - table.insert(obj.headers, v.description or "") - end - for v in cartesian_product(variants) do - v.fileapis = obj.fileapis - v.current_config_ref = obj.current_config - v = VariantConfig:new(v) - obj.display.short_len = math.max(obj.display.short_len, string.len(v.display.short)) - table.insert(obj.configs, v) - if v.default then - obj.current_config = v - end - if not obj.fileapis[v.build_directory] then - local fa = FileApi:new(v.build_directory) - if fa and fa:exists() then - fa:read_reply() - obj.fileapis[v.build_directory] = fa - end - end - end - setmetatable(obj, Project) - return obj -end - -function Project:from_presets(presets) - local obj = { { 1, 3, ddf = "" } } - return setmetatable(obj, self) -end - -function Project:set_current_config(idx) - self.current_config = self.configs[idx] -end - -function Project:set_current_build() end - -function Project:configure_command() - return self.current_config.configure_command -end - -function Project:current_configure_index() - for k, v in ipairs(self.configs) do - if v == self.current_config then - return k - end - end - return 1 -end - -function Project:current_build_index() - if not self.current_config then - return 1 - end - if getmetatable(self.current_config) == VariantConfig then - return 1 - end -end - -function Project:configure_display_options() - return self.display_options -end - -function Project:build_command() - if not self.current_config then - return - end - if getmetatable(self.current_config) == VariantConfig then - return self.current_config.build_command - end -end - -function Project:build_directory() - if not self.current_config then - return - end - return self.current_config.build_directory -end - -function Project:list_configs() - return self.configs -end - -function Project:list_builds(opts) - if getmetatable(self.current_config) == VariantConfig then - return { self.current_config } - end -end - -return Project diff --git a/lua/cmake-explorer/project_uauaua.lua b/lua/cmake-explorer/project_uauaua.lua deleted file mode 100644 index b54abd6..0000000 --- a/lua/cmake-explorer/project_uauaua.lua +++ /dev/null @@ -1,113 +0,0 @@ -local config = require("cmake-explorer.config") -local capabilities = require("cmake-explorer.capabilities") -local FileApi = require("cmake-explorer.file_api") -local Path = require("plenary.path") -local Scandir = require("plenary.scandir") -local utils = require("cmake-explorer.utils") -local notif = require("cmake-explorer.notification") - -local Project = {} - -Project.__index = Project - -function Project:new(o) - o = o or {} - - local path - if type(o) == "string" then - path = o - elseif type(o) == "table" and o.path then - path = o.path - else - return - end - - if not Path:new(path, "CMakeLists.txt"):exists() then - return - end - - local obj = { - path = path, - fileapis = {}, - last_generate = nil, - } - notif.notify("PATH " .. obj.path) - setmetatable( - obj.fileapis, - utils.make_maplike_list(function(v) - return v.path - end) - ) - setmetatable(obj, Project) - return obj -end - -function Project:scan_build_dirs() - local builds_root = utils.is_eq( - Path:new(config.build_dir):is_absolute(), - true, - Path:new(config.build_dir), - Path:new(self.path, config.build_dir) - ) - local candidates = - Scandir.scan_dir(builds_root:absolute(), { hidden = false, only_dirs = true, depth = 0, silent = true }) - for _, v in ipairs(candidates) do - local fa = FileApi:new(v) - if fa and fa:exists() and fa:read_reply() then - self.fileapis[fa.path] = fa - end - end -end - -function Project:symlink_compile_commands(path) - local src = Path:new(path, "compile_commands.json") - if src:exists() then - vim.cmd( - 'silent exec "!' - .. config.cmake_cmd - .. " -E create_symlink " - .. src:normalize() - .. " " - .. Path:new(self.path, "compile_commands.json"):normalize() - .. '"' - ) - end -end - -function Project:configure(params) - params = params or {} - local args = utils.generate_args(params, self.path) - local build_dir = utils.build_path(params, self.path) - if not args then - return - end - if not self.fileapis[build_dir] then - local fa = FileApi:new(build_dir) - if not fa then - notif.notify("Cannot fileapi object", vim.log.levels.ERROR) - return - end - if not fa:create() then - return - end - self.fileapis[build_dir] = fa - end - - local job_args = { - cmd = config.cmake_cmd, - args = args, - cwd = self.path, - after_success = function() - self.last_generate = job_args - self.fileapis[build_dir]:read_reply() - self:symlink_compile_commands(build_dir) - end, - } - return job_args -end - -function Project:configure_last() - return self.last_generate -end - -return Project diff --git a/lua/cmake-explorer/runner.lua b/lua/cmake-explorer/runner.lua deleted file mode 100644 index f2765fe..0000000 --- a/lua/cmake-explorer/runner.lua +++ /dev/null @@ -1,84 +0,0 @@ -local Job = require("plenary.job") -local notif = require("cmake-explorer.notification") - -local M = {} - -local running_jobs = {} -local last_job = nil - -function M.start(command) - if not command then - print("runner start. command is nil") - return - end - local env = vim.tbl_extend("force", vim.loop.os_environ(), command.env and command.env or {}) - - if command.before_run then - if not command.before_run() then - notif.notify("Before run command failed", vim.log.levels.ERROR) - return - end - end - notif.notify(command.cmd .. " " .. table.concat(command.args, " ")) - local job = Job:new({ - command = command.cmd, - args = command.args, - env = env, - on_stdout = vim.schedule_wrap(function(err, data) end), - on_exit = vim.schedule_wrap(function(_, code, signal) - if code == 0 and signal == 0 then - if command.after_success then - command.after_success() - end - else - notif.notify( - "Code " - .. code - .. " Signal " - .. signal - .. ": " - .. command.cmd - .. " " - .. table.concat(command.args, " "), - vim.log.levels.ERROR - ) - end - end), - }) - job:start() - table.insert(running_jobs, job) - last_job = job -end - -function M.cancel_job() - if not last_job then - return false - end - - -- Check if this job was run through debugger. - if last_job.session then - if not last_job.session() then - return false - end - last_job.terminate() - return true - end - - if last_job.is_shutdown then - return false - end - - last_job:shutdown(1, 9) - - if vim.fn.has("win32") == 1 or vim.fn.has("mac") == 1 then - -- Kill all children. - for _, pid in ipairs(vim.api.nvim_get_proc_children(last_job.pid)) do - vim.loop.kill(pid, 9) - end - else - vim.loop.kill(last_job.pid, 9) - end - return true -end - -return M diff --git a/lua/cmake-explorer/telescope/make_entry.lua b/lua/cmake-explorer/telescope/make_entry.lua deleted file mode 100644 index cc919bd..0000000 --- a/lua/cmake-explorer/telescope/make_entry.lua +++ /dev/null @@ -1,57 +0,0 @@ -local make_entry = require("telescope.make_entry") -local entry_display = require("telescope.pickers.entry_display") -local config = require("cmake-explorer.config") - -local M = {} - -M.gen_from_configure = function(opts) - local project = require("cmake-explorer").project - local displayer = entry_display.create({ - separator = " ", - items = { - { width = project.display.short_len + 5 }, - { remaining = true }, - }, - }) - local make_display = function(entry) - vim.print(entry) - return displayer({ - { entry.value.display.short, "TelescopeResultsIdentifier" }, - { entry.value.display.long, "TelescopeResultsComment" }, - }) - end - return function(entry) - return make_entry.set_default_entry_mt({ - value = entry, - ordinal = table.concat(entry.short, config.variants_display.short_sep), - display = make_display, - }, opts) - end -end - -M.gen_from_build = function(opts) - local project = require("cmake-explorer").project - local displayer = entry_display.create({ - separator = " ", - items = { - { width = project.display.short_len + 5 }, - { remaining = true }, - }, - }) - local make_display = function(entry) - vim.print(entry) - return displayer({ - { entry.value.display.short, "TelescopeResultsIdentifier" }, - { entry.value.display.long, "TelescopeResultsComment" }, - }) - end - return function(entry) - return make_entry.set_default_entry_mt({ - value = entry, - ordinal = table.concat(entry.short, config.variants_display.short_sep), - display = make_display, - }, opts) - end -end - -return M diff --git a/lua/cmake-explorer/telescope/pickers.lua b/lua/cmake-explorer/telescope/pickers.lua deleted file mode 100644 index b2c7f56..0000000 --- a/lua/cmake-explorer/telescope/pickers.lua +++ /dev/null @@ -1,103 +0,0 @@ -local pickers = require("telescope.pickers") -local finders = require("telescope.finders") -local conf = require("telescope.config").values -local actions = require("telescope.actions") -local action_state = require("telescope.actions.state") -local cmake_make_entry = require("cmake-explorer.telescope.make_entry") -local notif = require("cmake-explorer.notification") -local previewers = require("cmake-explorer.telescope.previewers") - -local M = {} - -M.build_dirs = function(opts) - local cmake = require("cmake-explorer") - pickers - .new(opts, { - prompt_title = "CMake Builds", - finder = finders.new_table({ - results = cmake.project.fileapis, - -- entry_maker = cmake_make_entry.gen_from_fileapi(opts), - entry_maker = function(entry) - return { - value = entry, - display = entry.path, - ordinal = entry.path, - } - end, - sorter = conf.generic_sorter(opts), - -- attach_mappings = function(prompt_bufnr, map) - -- actions.select_default:replace(function() end) - -- return true - -- end, - }), - }) - :find() -end - -M.configure = function(opts) - local cmake = require("cmake-explorer") - local runner = require("cmake-explorer.runner") - opts.layout_strategy = "vertical" - opts.layout_config = { - prompt_position = "top", - preview_cutoff = 0, - preview_height = 5, - mirror = true, - } - pickers - .new(opts, { - default_selection_index = cmake.project:current_configure_index(), - prompt_title = "CMake Configure Options", - finder = finders.new_table({ - results = cmake.project:list_configs(), - entry_maker = cmake_make_entry.gen_from_configure(opts), - }), - sorter = conf.generic_sorter(opts), - previewer = previewers.configure_previewer(), - attach_mappings = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - cmake.project.current_config = selection.value - runner.start(selection.value.configure_command) - end) - return true - end, - }) - :find() -end - -M.build = function(opts) - local cmake = require("cmake-explorer") - local runner = require("cmake-explorer.runner") - opts.layout_strategy = "vertical" - opts.layout_config = { - prompt_position = "top", - preview_cutoff = 0, - preview_height = 5, - mirror = true, - } - pickers - .new(opts, { - default_selection_index = cmake.project:current_build_index(), - prompt_title = "CMake Build Options", - finder = finders.new_table({ - results = cmake.project:list_builds(), - entry_maker = cmake_make_entry.gen_from_configure(opts), - }), - sorter = conf.generic_sorter(opts), - previewer = previewers.build_previewer(), - attach_mappings = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - cmake.project.current_config = selection.value - runner.start(selection.value.build_command) - end) - return true - end, - }) - :find() -end - -return M diff --git a/lua/cmake-explorer/telescope/previewers.lua b/lua/cmake-explorer/telescope/previewers.lua deleted file mode 100644 index 39fea4a..0000000 --- a/lua/cmake-explorer/telescope/previewers.lua +++ /dev/null @@ -1,40 +0,0 @@ -local previewers = require("telescope.previewers") -local config = require("cmake-explorer.config") - -local M = {} - -M.configure_previewer = function(opts) - return previewers.new_buffer_previewer({ - title = "Configure Details", - - define_preview = function(self, entry) - if self.state.bufname then - return - end - local entries = { - "Command:", - config.cmake_path .. " " .. table.concat(entry.value.configure_args, " "), - } - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries) - end, - }) -end - -M.build_previewer = function(opts) - return previewers.new_buffer_previewer({ - title = "Build Details", - - define_preview = function(self, entry) - if self.state.bufname then - return - end - local entries = { - "Command:", - config.cmake_path .. " " .. table.concat(entry.value.build_args, " "), - } - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries) - end, - }) -end - -return M diff --git a/lua/cmake-explorer/telescope/test.lua b/lua/cmake-explorer/telescope/test.lua deleted file mode 100644 index 7b8bb00..0000000 --- a/lua/cmake-explorer/telescope/test.lua +++ /dev/null @@ -1,46 +0,0 @@ -local pickers = require("telescope.pickers") -local finders = require("telescope.finders") -local conf = require("telescope.config").values -local actions = require("telescope.actions") -local action_state = require("telescope.actions.state") - --- our picker function: colors -local colors = function(opts) - opts = opts or {} - pickers - .new(opts, { - prompt_title = "colors", - finder = finders.new_table({ - results = { - { "red", "#ff0000" }, - { "green", "#00ff00" }, - { "blue", "#0000ff" }, - }, - entry_maker = function(entry) - return { - value = entry, - display = entry[1], - ordinal = entry[1], - } - end, - }), - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr, map) - map({ "i", "n" }, "<C-r>", function(_prompt_bufnr) - print("You typed <C-r>") - end) - - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - -- print(vim.inspect(selection)) - vim.api.nvim_put({ selection[1] }, "", false, true) - end) - return true - end, - }) - :find() -end - --- to execute the function -colors() diff --git a/lua/cmake-explorer/utils.lua b/lua/cmake-explorer/utils.lua deleted file mode 100644 index 61b5c98..0000000 --- a/lua/cmake-explorer/utils.lua +++ /dev/null @@ -1,92 +0,0 @@ -local config = require("cmake-explorer.config") -local capabilities = require("cmake-explorer.capabilities") -local Path = require("plenary.path") - -local utils = {} - -utils.build_path = function(build_dir, source_dir) - local build_path = Path:new(config.build_dir) - if build_path:is_absolute() then - return (build_path / build_dir):absolute() - else - return Path:new(build_path, build_dir):normalize() - end -end - -utils.substitude = function(str, subs) - local ret = str - for k, v in pairs(subs) do - ret = ret:gsub(k, v) - end - return ret -end - -function utils.symlink_compile_commands(src_path, dst_path) - local src = Path:new(src_path, "compile_commands.json") - if src:exists() then - vim.cmd( - 'silent exec "!' - .. config.cmake_path - .. " -E create_symlink " - .. src:normalize() - .. " " - .. Path:new(dst_path, "compile_commands.json"):normalize() - .. '"' - ) - end -end - -utils.is_eq = function(val, cmp, if_eq, if_not_eq) - if val == cmp then - if if_eq then - return if_eq - else - return val - end - else - if if_not_eq then - return if_not_eq - else - return nil - end - end -end - -utils.is_neq = function(val, cmp, if_eq, if_not_eq) - if val ~= cmp then - if if_eq then - return if_eq - else - return val - end - else - if if_not_eq then - return if_not_eq - else - return nil - end - end -end - -utils.make_maplike_list = function(proj) - local mt = {} - mt.__index = function(t, k) - for _, value in ipairs(t) do - if proj(value) == k then - return value - end - end - end - mt.__newindex = function(t, k, v) - for key, value in ipairs(t) do - if proj(value) == k then - rawset(t, key, v) - return - end - end - rawset(t, #t + 1, v) - end - return mt -end - -return utils |