diff options
| author | kylo252 <[email protected]> | 2021-08-26 20:32:16 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-26 23:02:16 +0430 | 
| commit | 27679f988fe187f9831ba7895c9c3a7ce2dd14f4 (patch) | |
| tree | c7a9f429311a68f46752e943aa3fa03a690db722 | |
| parent | 14f129cf26a9814dc8f5fa46f483a588b5a813b0 (diff) | |
[Refactor]: only allow a single logger (#1405)
| -rw-r--r-- | .github/workflows/install.yaml | 5 | ||||
| -rw-r--r-- | init.lua | 2 | ||||
| -rw-r--r-- | lua/core/log.lua | 65 | ||||
| -rw-r--r-- | lua/core/lualine/styles.lua | 2 | ||||
| -rw-r--r-- | lua/keymappings.lua | 2 | ||||
| -rw-r--r-- | lua/lsp/init.lua | 8 | ||||
| -rw-r--r-- | lua/lsp/null-ls/formatters.lua | 2 | ||||
| -rw-r--r-- | lua/lsp/null-ls/linters.lua | 2 | ||||
| -rw-r--r-- | lua/plugin-loader.lua | 9 | ||||
| -rw-r--r-- | lua/utils/init.lua | 4 | ||||
| -rwxr-xr-x | utils/installer/install.sh | 50 | 
11 files changed, 74 insertions, 77 deletions
| diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index f7d9da01..fa8bf0e3 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -38,8 +38,9 @@ jobs:        - name: Install LunarVim          timeout-minutes: 4          run: | -          mkdir -p "$HOME/.local/share/lunarvim" -          mkdir -p "$HOME/.config/lvim" +          mkdir -p "$HOME"/.local/share/lunarvim/lvim +          mkdir -p "$HOME"/.config/lvim +          ln -s "$PWD"/* "$HOME"/.local/share/lunarvim/lvim/.            bash ./utils/installer/install.sh        - name: Test LunarVim PackerCompile @@ -25,7 +25,7 @@ local plugins = require "plugins"  local plugin_loader = require("plugin-loader").init()  plugin_loader:load { plugins, lvim.plugins } -local Log = require("core.log").new_default() +local Log = require "core.log"  Log:info "Starting LunarVim"  vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs. diff --git a/lua/core/log.lua b/lua/core/log.lua index 54620625..1eb786ba 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -1,60 +1,59 @@  local Log = {} ---- Creates a log handle based on Plenary.log ----@param opts these are passed verbatim to Plenary.log ----@return log handle -function Log:new(opts) -  local status_ok, handle = pcall(require, "plenary.log") -  if not status_ok then -    vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG) -  end - -  self.__handle = handle - -  local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) - -  self.get_path = function() -    return path -  end - -  setmetatable({}, Log) -  return self -end - +--- Adds a log entry using Plenary.log +---@param msg any +---@param level string [same as vim.log.log_levels]  function Log:add_entry(msg, level) -  local status_ok, _ = pcall(require, "plenary.log") -  if not status_ok then -    return vim.notify(msg, vim.log.levels[level]) +  assert(type(level) == "string") +  if self.__handle then +    -- plenary uses lower-case log levels +    self.__handle[level:lower()](msg) +  end +  local status_ok, plenary = pcall(require, "plenary") +  if status_ok then +    local default_opts = { plugin = "lunarvim", level = lvim.log.level } +    local handle = plenary.log.new(default_opts) +    handle[level:lower()](msg) +    self.__handle = handle    end -  -- plenary uses lower-case log levels -  return self.__handle[level:lower()](msg) +  -- don't do anything if plenary is not available  end ---- Creates or retrieves a log handle for the default logfile ---- based on Plenary.log ----@return log handle -function Log:new_default() -  return Log:new { plugin = "lunarvim", level = lvim.log.level } +---Retrieves the path of the logfile +---@return string path of the logfile +function Log:get_path() +  return string.format("%s/%s.log", vim.fn.stdpath "cache", "lunarvim")  end +---Add a log entry at TRACE level +---@param msg any  function Log:trace(msg)    self:add_entry(msg, "TRACE")  end +---Add a log entry at DEBUG level +---@param msg any  function Log:debug(msg)    self:add_entry(msg, "DEBUG")  end +---Add a log entry at INFO level +---@param msg any  function Log:info(msg)    self:add_entry(msg, "INFO")  end +---Add a log entry at WARN level +---@param msg any  function Log:warn(msg) -  self:add_entry(msg, "TRACE") +  self:add_entry(msg, "WARN")  end +---Add a log entry at ERROR level +---@param msg any  function Log:error(msg) -  self:add_entry(msg, "TRACE") +  self:add_entry(msg, "ERROR")  end +setmetatable({}, Log)  return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 53b0691e..84e8123d 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -118,7 +118,7 @@ function M.get_style(style)        "options are: ",        string.format('"%s"', table.concat(style_keys, '", "'))      ) -    Log:info '"lvim" style is applied.' +    Log:debug '"lvim" style is applied.'      style = "lvim"    end diff --git a/lua/keymappings.lua b/lua/keymappings.lua index fa1af1c4..557e0bde 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -159,7 +159,7 @@ function M.config()      lvim.keys.normal_mode["<A-Down>"] = lvim.keys.normal_mode["<C-Down>"]      lvim.keys.normal_mode["<A-Left>"] = lvim.keys.normal_mode["<C-Left>"]      lvim.keys.normal_mode["<A-Right>"] = lvim.keys.normal_mode["<C-Right>"] -    Log:info "Activated mac keymappings" +    Log:debug "Activated mac keymappings"    end  end diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 94fcf550..f3b019aa 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -99,21 +99,23 @@ end  function M.common_on_init(client, bufnr)    if lvim.lsp.on_init_callback then      lvim.lsp.on_init_callback(client, bufnr) -    Log:info "Called lsp.on_init_callback" +    Log:debug "Called lsp.on_init_callback"      return    end    local formatters = lvim.lang[vim.bo.filetype].formatters    if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then      client.resolved_capabilities.document_formatting = false -    Log:info(string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)) +    Log:debug( +      string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) +    )    end  end  function M.common_on_attach(client, bufnr)    if lvim.lsp.on_attach_callback then      lvim.lsp.on_attach_callback(client, bufnr) -    Log:get_default().info "Called lsp.on_init_callback" +    Log:debug "Called lsp.on_init_callback"    end    lsp_highlight_document(client)    add_lsp_buffer_keybindings(bufnr) diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 05e0ec62..26be00da 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -53,7 +53,7 @@ function M.list_configured(formatter_configs)          Log:warn("Not found:", formatter._opts.command)          errors[fmt_config.exe] = {} -- Add data here when necessary        else -        Log:info("Using formatter:", formatter_cmd) +        Log:debug("Using formatter:", formatter_cmd)          formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args }        end      end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 70c59974..bc191d7e 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -53,7 +53,7 @@ function M.list_configured(linter_configs)          Log:warn("Not found:", linter._opts.command)          errors[lnt_config.exe] = {} -- Add data here when necessary        else -        Log:info("Using linter:", linter_cmd) +        Log:debug("Using linter:", linter_cmd)          linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args }        end      end diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index e238b193..aa1e888d 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -1,13 +1,10 @@  local plugin_loader = {}  function plugin_loader:init() -  local execute = vim.api.nvim_command -  local fn = vim.fn -    local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim" -  if fn.empty(fn.glob(install_path)) > 0 then -    execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path) -    execute "packadd packer.nvim" +  if vim.fn.empty(vim.fn.glob(install_path)) > 0 then +    vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path } +    vim.cmd "packadd packer.nvim"    end    local packer_ok, packer = pcall(require, "packer") diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 322a961f..8ea842ca 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -70,7 +70,7 @@ function utils.toggle_autoformat()          },        },      } -    Log:info "Format on save active" +    Log:debug "Format on save active"    end    if not lvim.format_on_save then @@ -79,7 +79,7 @@ function utils.toggle_autoformat()          :autocmd! autoformat        endif      ]] -    Log:info "Format on save off" +    Log:debug "Format on save off"    end  end diff --git a/utils/installer/install.sh b/utils/installer/install.sh index beef47fd..4392635d 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -50,32 +50,34 @@ EOF    echo "Detecting platform for managing any additional neovim dependencies"    detect_platform -  # skip this in a Github workflow -  if [ -z "$GITHUB_ACTIONS" ]; then -    check_system_deps +  if [ -n "$GITHUB_ACTIONS" ]; then +    install_packer +    setup_lvim +    exit 0 +  fi -    __add_separator "80" +  check_system_deps -    echo "Would you like to check lunarvim's NodeJS dependencies?" -    read -p "[y]es or [n]o (default: no) : " -r answer -    [ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps +  __add_separator "80" -    echo "Would you like to check lunarvim's Python dependencies?" -    read -p "[y]es or [n]o (default: no) : " -r answer -    [ "$answer" != "${answer#[Yy]}" ] && install_python_deps +  echo "Would you like to check lunarvim's NodeJS dependencies?" +  read -p "[y]es or [n]o (default: no) : " -r answer +  [ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps -    echo "Would you like to check lunarvim's Rust dependencies?" -    read -p "[y]es or [n]o (default: no) : " -r answer -    [ "$answer" != "${answer#[Yy]}" ] && install_rust_deps +  echo "Would you like to check lunarvim's Python dependencies?" +  read -p "[y]es or [n]o (default: no) : " -r answer +  [ "$answer" != "${answer#[Yy]}" ] && install_python_deps -    __add_separator "80" +  echo "Would you like to check lunarvim's Rust dependencies?" +  read -p "[y]es or [n]o (default: no) : " -r answer +  [ "$answer" != "${answer#[Yy]}" ] && install_rust_deps -    echo "Backing up old LunarVim configuration" -    backup_old_config +  __add_separator "80" -    __add_separator "80" +  echo "Backing up old LunarVim configuration" +  backup_old_config -  fi +  __add_separator "80"    case "$@" in      *--overwrite*) @@ -219,13 +221,13 @@ function backup_old_config() {  }  function install_packer() { -  git clone --progress --depth 1 https://github.com/wbthomason/packer.nvim \ +  git clone --depth 1 https://github.com/wbthomason/packer.nvim \      "$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim"  }  function clone_lvim() {    echo "Cloning LunarVim configuration" -  if ! git clone --progress --branch "$LV_BRANCH" \ +  if ! git clone --branch "$LV_BRANCH" \      --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then      echo "Failed to clone repository. Installation failed."      exit 1 @@ -258,12 +260,8 @@ function setup_lvim() {      "$LUNARVIM_CONFIG_DIR/config.lua"    nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \ -    +'autocmd User PackerComplete sleep 100m | qall' \ -    +PackerInstall - -  nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \ -    +'autocmd User PackerComplete sleep 100m | qall' \ -    +PackerSync +    -c 'autocmd User PackerComplete quitall' \ +    -c 'PackerSync'    echo "Packer setup complete" | 
