diff --git a/.editorconfig b/.editorconfig index bdc2144..78df918 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,4 +6,4 @@ insert_final_newline = false charset = utf-8 trim_trailing_whitespace = true indent_style = space -indent_size = 4 +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53eb759..3aca085 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,7 @@ jobs: if: ${{ github.ref != 'refs/heads/main' }} runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 # - uses: webiny/action-conventional-commits@v1.1.0 - uses: ytanikin/PRConventionalCommits@1.1.0 with: @@ -24,28 +23,23 @@ jobs: name: Lua check runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: LuaLs typecheck - uses: stevearc/nvim-typecheck-action@v1 + - uses: actions/checkout@v4 + - uses: stevearc/nvim-typecheck-action@v1 with: path: lua level: Information configpath: ".luarc.json" neodev-version: stable - - name: Luacheck - uses: lunarmodules/luacheck@v1 + - uses: lunarmodules/luacheck@v1 with: args: lua --config .luacheckrc - - name: Stylua - uses: JohnnyMorganz/stylua-action@v3 + - uses: JohnnyMorganz/stylua-action@v3 with: token: ${{ secrets.GITHUB_TOKEN }} version: latest args: --config-path .stylua.toml lua/ test/ - - name: Auto Commit + - uses: stefanzweifel/git-auto-commit-action@v4 if: ${{ github.ref != 'refs/heads/main' }} - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "chore(pr): auto-commit" unit_test: @@ -55,20 +49,16 @@ jobs: nvim_version: [stable, nightly, v0.6.0] runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Install neovim - uses: rhysd/action-setup-vim@v1 + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 id: vim with: neovim: true version: ${{ matrix.nvim_version }} - - name: Install luajit - uses: leafo/gh-actions-lua@v10 + - uses: leafo/gh-actions-lua@v10 with: luaVersion: "luajit-2.1.0-beta3" - - name: Install luarocks - uses: leafo/gh-actions-luarocks@v4 + - uses: leafo/gh-actions-luarocks@v4 - name: Run test cases shell: bash run: | @@ -88,8 +78,7 @@ jobs: ls -l . echo "cat ./luacov.report.out" cat ./luacov.report.out - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v3 with: files: luacov.report.out env: @@ -122,7 +111,6 @@ jobs: LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} with: version: ${{ steps.release.outputs.tag_name }} - summary: "A performant lsp progress status for Neovim." labels: | vim neovim diff --git a/.nvim.lua b/.nvim.lua new file mode 100644 index 0000000..ed7f6bb --- /dev/null +++ b/.nvim.lua @@ -0,0 +1,3 @@ +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 diff --git a/README.md b/README.md index 92b636c..0fc51d4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,31 @@ + + # lsp-progress.nvim

-Neovim -luarocks +Neovim +luarocks ci.yml codecov

-A performant lsp progress status for Neovim. +

A performant lsp progress status for Neovim.

+ + ![default](https://github.com/linrongbin16/lsp-progress.nvim/assets/6496887/e089234b-d465-45ae-840f-72a57b846b0d) +
+Click here to see how to configure + +```lua +require("lsp-progress").setup() +``` + +
+ + + ![client-names](https://github.com/linrongbin16/lsp-progress.nvim/assets/6496887/01dac7a0-678a-421d-a243-9dba2576b15b)
@@ -18,59 +33,61 @@ A performant lsp progress status for Neovim. ```lua require("lsp-progress").setup({ -client_format = function(client_name, spinner, series_messages) - if #series_messages == 0 then - return nil - end - return { - name = client_name, - body = spinner .. " " .. table.concat(series_messages, ", "), - } -end, -format = function(client_messages) - --- @param name string - --- @param msg string? - --- @return string - local function stringify(name, msg) - return msg and string.format("%s %s", name, msg) or name - end - - local sign = "" -- nf-fa-gear \uf013 - local lsp_clients = vim.lsp.get_active_clients() - local messages_map = {} - for _, climsg in ipairs(client_messages) do - messages_map[climsg.name] = climsg.body - end - - if #lsp_clients > 0 then - table.sort(lsp_clients, function(a, b) - return a.name < b.name - end) - local builder = {} - for _, cli in ipairs(lsp_clients) do - if - type(cli) == "table" - and type(cli.name) == "string" - and string.len(cli.name) > 0 - then - if messages_map[cli.name] then - table.insert(builder, stringify(cli.name, messages_map[cli.name])) - else - table.insert(builder, stringify(cli.name)) + client_format = function(client_name, spinner, series_messages) + if #series_messages == 0 then + return nil + end + return { + name = client_name, + body = spinner .. " " .. table.concat(series_messages, ", "), + } + end, + format = function(client_messages) + --- @param name string + --- @param msg string? + --- @return string + local function stringify(name, msg) + return msg and string.format("%s %s", name, msg) or name + end + + local sign = "" -- nf-fa-gear \uf013 + local lsp_clients = vim.lsp.get_active_clients() + local messages_map = {} + for _, climsg in ipairs(client_messages) do + messages_map[climsg.name] = climsg.body + end + + if #lsp_clients > 0 then + table.sort(lsp_clients, function(a, b) + return a.name < b.name + end) + local builder = {} + for _, cli in ipairs(lsp_clients) do + if + type(cli) == "table" + and type(cli.name) == "string" + and string.len(cli.name) > 0 + then + if messages_map[cli.name] then + table.insert(builder, stringify(cli.name, messages_map[cli.name])) + else + table.insert(builder, stringify(cli.name)) + end end end + if #builder > 0 then + return sign .. " " .. table.concat(builder, ", ") + end end - if #builder > 0 then - return sign .. " " .. table.concat(builder, ", ") - end - end - return "" -end, + return "" + end, }) ```
+ + ![green-check](https://github.com/linrongbin16/lsp-progress.nvim/assets/6496887/2666b105-4939-4985-8b5e-74bc43e5615c)
@@ -130,11 +147,8 @@ require("lsp-progress").setup({ - [Performance](#performance) - [Requirement](#requirement) - [Install](#install) - - [packer.nvim](#packernvim) - - [lazy.nvim](#lazynvim) - - [vim-plug](#vim-plug) - [Usage](#usage) - - [Statusline Integration](#statusline-integration) + - [Lualine Integration](#lualine-integration) - [Configuration](#configuration) - [Credit](#credit) - [Contribute](#contribute) @@ -150,100 +164,67 @@ For more details, please see [Design & Technics](https://github.com/linrongbin16 ## Requirement -- Neovim version ≥ 0.6.0. +- Neovim ≥ 0.6.0. - [Nerd fonts](https://www.nerdfonts.com/) for icons. ## Install -### [packer.nvim](https://github.com/wbthomason/packer.nvim) +
+With packer.nvim ```lua -- lua return require('packer').startup(function(use) - - use {'nvim-tree/nvim-web-devicons'}, use { 'linrongbin16/lsp-progress.nvim', config = function() require('lsp-progress').setup() end } - - -- integrate with lualine - use { - 'nvim-lualine/lualine.nvim', - config = ..., - } - - -- integrate with heirline - use { - 'rebelot/heirline.nvim', - config = ..., - } end) ``` -### [lazy.nvim](https://github.com/folke/lazy.nvim) +
+ +
+With lazy.nvim ```lua -- lua require("lazy").setup({ - { 'linrongbin16/lsp-progress.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' }, config = function() require('lsp-progress').setup() end } - - -- integrate with lualine - { - 'nvim-lualine/lualine.nvim', - dependencies = { - 'nvim-tree/nvim-web-devicons', - 'linrongbin16/lsp-progress.nvim', - }, - config = ... - }, - - -- integrate with heirline - { - 'rebelot/heirline.nvim', - dependencies = { - 'linrongbin16/lsp-progress.nvim', - }, - config = ... - } }) ``` -### [vim-plug](https://github.com/junegunn/vim-plug) +
+ +
+With vim-plug ```vim " vim call plug#begin() -Plug 'nvim-tree/nvim-web-devicons' Plug 'linrongbin16/lsp-progress.nvim' -" integrate with lualine -Plug 'nvim-lualine/lualine.nvim' - -" integrate with heirline -Plug 'rebelot/heirline.nvim' - call plug#end() lua require('lsp-progress').setup() ``` +
+ ## Usage - `LspProgressStatusUpdated`: user event to notify new status, and trigger statusline refresh. -- `require('lsp-progress').progress(option)`: get lsp progress status, parameter - `option` is an optional lua table: +- `require('lsp-progress').progress(opts)`: get lsp progress status, parameter + `opts` is an optional lua table: ```lua require('lsp-progress').progress({ @@ -252,12 +233,10 @@ lua require('lsp-progress').setup() }) ``` - The fields share the same schema with `setup(option)` (see [Configuration](#configuration)) + The fields are the same value passing to `setup` (see [Configuration](#configuration)) to provide more dynamic abilities. -### Statusline Integration - -#### [lualine](https://github.com/nvim-lualine/lualine.nvim) +### [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim) Integration ```lua require("lualine").setup({ @@ -281,7 +260,7 @@ vim.api.nvim_create_autocmd("User", { }) ``` -#### [heirline](https://github.com/rebelot/heirline.nvim) +### [heirline.nvim](https://github.com/rebelot/heirline.nvim) Integration ```lua local LspProgress = { @@ -299,6 +278,8 @@ local StatusLine = { -- Other StatusLine components { ... }, { ... }, + + -- Lsp progress status component here LspProgress } @@ -312,10 +293,10 @@ require('heirline').setup({ To configure options, please use: ```lua -require('lsp-progress').setup(option) +require('lsp-progress').setup(opts) ``` -The `option` is an optional lua table that override the default options. +The `opts` is an optional lua table that overwrite the default options. For complete options and defaults, please check [defaults.lua](https://github.com/linrongbin16/lsp-progress.nvim/blob/main/lua/lsp-progress/defaults.lua). diff --git a/lua/lsp-progress.lua b/lua/lsp-progress.lua index d30bd19..6694853 100644 --- a/lua/lsp-progress.lua +++ b/lua/lsp-progress.lua @@ -8,31 +8,30 @@ local Client = require("lsp-progress.client").Client local Registered = false ---- @type Configs +--- @type lsp_progress.Configs local Configs = {} -- client manager { ---- @type table +--- @type table local LspClients = {} --- @package ---- @param client_id integer +--- @param client_id lsp_progress.ClientId --- @return boolean local function _has_client(client_id) return LspClients[client_id] ~= nil end --- @package ---- @param client_id integer ---- @return Client +--- @param client_id lsp_progress.ClientId +--- @return lsp_progress.Client local function _get_client(client_id) return LspClients[client_id] end --- @package ---- @param client_id integer ---- @return nil +--- @param client_id lsp_progress.ClientId local function _remove_client(client_id) LspClients[client_id] = nil if not next(LspClients) then @@ -41,9 +40,8 @@ local function _remove_client(client_id) end --- @package ---- @param client_id integer +--- @param client_id lsp_progress.ClientId --- @param client_name string ---- @return nil local function _register_client(client_id, client_name) if not _has_client(client_id) then LspClients[client_id] = Client:new(client_id, client_name) @@ -56,11 +54,9 @@ end -- client manager } ---- @param client_id integer ---- @param token string ---- @return nil +--- @param client_id lsp_progress.ClientId +--- @param token lsp_progress.SeriesToken local function spin(client_id, token) - --- @return nil local function spin_again() spin(client_id, token) end @@ -164,20 +160,19 @@ local function spin(client_id, token) event.emit() end ---- @param err any ---- @param msg table ---- @param ctx table ---- @return nil -local function progress_handler(err, msg, ctx) - local client_id = ctx.client_id - local nvim_lsp_client = vim.lsp.get_client_by_id(client_id) - local client_name = nvim_lsp_client and nvim_lsp_client.name or "unknown" +--- @alias lsp_progress.LspClientObj {id:lsp_progress.ClientId,name:string} +--- @alias lsp_progress.LspProgressObj {token:lsp_progress.SeriesToken,value:{kind:"begin"|"report"|"end",title:string?,message:string?,percentage:integer?}} +--- @param client lsp_progress.LspClientObj +--- @param progress lsp_progress.LspProgressObj +local function update_progress(client, progress) + local client_id = client.id + local client_name = client.name -- register client id if not exist _register_client(client_id, client_name) - local value = msg.value - local token = msg.token + local token = progress.token + local value = progress.value local cli = _get_client(client_id) if value.kind == "begin" then @@ -238,7 +233,37 @@ local function progress_handler(err, msg, ctx) event.emit() end ---- @param option Configs? +--- @param err string? +--- @param msg table +--- @param ctx table +local function method_handler(err, msg, ctx) + local client = vim.lsp.get_client_by_id(ctx.client_id) --[[@as table]] + update_progress(client, msg) +end + +local function _is_lsp_client_obj(c) + return type(c) == "table" and c.id and type(c.name) == "string" +end + +local function _is_lsp_progress_obj(p) + return type(p) == "table" and p.token and type(p.value) == "table" +end + +local function event_handler() + local lsp_clients = vim.lsp.get_active_clients() + for _, client in ipairs(lsp_clients) do + if _is_lsp_client_obj(client) and type(client.progress) == "table" then + for progress in client.progress do + -- logger.debug("|setup| v0.10 progress:%s", vim.inspect(progress)) + if _is_lsp_progress_obj(progress) then + update_progress(client, progress) + end + end + end + end +end + +--- @param option lsp_progress.Configs? --- @return string? local function progress(option) option = vim.tbl_deep_extend("force", vim.deepcopy(Configs), option or {}) @@ -285,8 +310,7 @@ local function progress(option) return content end ---- @param option table ---- @return nil +--- @param option lsp_progress.Configs local function setup(option) -- setup config Configs = defaults.setup(option) @@ -313,17 +337,24 @@ local function setup(option) -- init client require("lsp-progress.client").setup(Configs.client_format, Configs.spinner) - if not Registered then - if vim.lsp.handlers["$/progress"] then - local old_handler = vim.lsp.handlers["$/progress"] - vim.lsp.handlers["$/progress"] = function(...) - old_handler(...) - progress_handler(...) + if vim.fn.has("nvim-0.10") > 0 then + -- see: + -- https://github.com/neovim/neovim/blob/582d7f47905d82f315dc852a9d2937cd5b655e55/runtime/doc/news.txt#L44 + -- https://github.com/neovim/neovim/blob/582d7f47905d82f315dc852a9d2937cd5b655e55/runtime/lua/vim/lsp/util.lua#L348 + vim.api.nvim_create_autocmd("LspProgress", { callback = event_handler }) + else + if not Registered then + if vim.lsp.handlers["$/progress"] then + local old_handler = vim.lsp.handlers["$/progress"] + vim.lsp.handlers["$/progress"] = function(...) + old_handler(...) + method_handler(...) + end + else + vim.lsp.handlers["$/progress"] = method_handler end - else - vim.lsp.handlers["$/progress"] = progress_handler + Registered = true end - Registered = true end end diff --git a/lua/lsp-progress/client.lua b/lua/lsp-progress/client.lua index bc575c3..8b31855 100644 --- a/lua/lsp-progress/client.lua +++ b/lua/lsp-progress/client.lua @@ -1,25 +1,28 @@ local logger = require("lsp-progress.logger") ---- @alias ClientFormatResult string|any|nil ---- @alias ClientFormat fun(client_name:string,spinner:string,series_messages:string[]|table[]):ClientFormatResult ---- @type ClientFormat? +--- @alias lsp_progress.ClientFormatResult string|any|nil +--- @alias lsp_progress.ClientFormat fun(client_name:string,spinner:string,series_messages:string[]|table[]):lsp_progress.ClientFormatResult +--- @type lsp_progress.ClientFormat? local ClientFormat = nil --- @type string[]|nil local Spinner = nil ---- @class Client ---- @field client_id integer|nil +---@alias lsp_progress.ClientId integer +---@alias lsp_progress.SeriesToken integer|string +--- +--- @class lsp_progress.Client +--- @field client_id lsp_progress.ClientId? --- @field client_name string|nil --- @field spin_index integer ---- @field serieses table map: key => SeriesObject. ---- @field private _format_cache ClientFormatResult ---- @field private _deduped_tokens table map: title+message => token. +--- @field serieses table map series token => series object. +--- @field private _format_cache lsp_progress.ClientFormatResult +--- @field private _deduped_tokens table map: title+message => token. local Client = {} ---- @param client_id integer +--- @param client_id lsp_progress.ClientId --- @param client_name string ---- @return Client +--- @return lsp_progress.Client function Client:new(client_id, client_name) local o = { client_id = client_id, @@ -38,7 +41,7 @@ function Client:new(client_id, client_name) return o end ---- @param token string +--- @param token lsp_progress.SeriesToken --- @return boolean function Client:has_series(token) return self.serieses[token] ~= nil @@ -63,7 +66,7 @@ end --- @package --- @param title string --- @param message string ---- @param token string +--- @param token lsp_progress.SeriesToken function Client:_set_dedup_token(title, message, token) self._deduped_tokens[_get_dedup_key(title, message)] = token end @@ -78,12 +81,12 @@ end --- @package --- @param title string --- @param message string ---- @return string token +--- @return lsp_progress.SeriesToken function Client:_get_dedup_token(title, message) return self._deduped_tokens[_get_dedup_key(title, message)] end ---- @param token string +--- @param token lsp_progress.SeriesToken function Client:remove_series(token) if self:has_series(token) then local series = self:get_series(token) @@ -102,14 +105,14 @@ function Client:remove_series(token) self:format() end ---- @param token string ---- @return Series +--- @param token lsp_progress.SeriesToken +--- @return lsp_progress.Series function Client:get_series(token) return self.serieses[token] end ---- @param token string ---- @param series Series +--- @param token lsp_progress.SeriesToken +--- @param series lsp_progress.Series function Client:add_series(token, series) self:_set_dedup_token(series.title, series.message, token) self.serieses[token] = series @@ -135,18 +138,19 @@ function Client:increase_spin_index() self:format() end +--- @return string function Client:get_spin_index() assert(Spinner ~= nil, "Spinner cannot be nil") assert(#Spinner > 0, "Spinner length must greater than 0") return Spinner[self.spin_index + 1] end ---- @return ClientFormatResult +--- @return lsp_progress.ClientFormatResult function Client:format() - --- @type SeriesFormatResult[] + --- @type lsp_progress.SeriesFormatResult[] local series_messages = {} - --- @type table + --- @type table local visited_tokens = {} for dedup_key, token in pairs(self._deduped_tokens) do @@ -188,14 +192,13 @@ function Client:format() return self._format_cache end ---- @return ClientFormatResult +--- @return lsp_progress.ClientFormatResult function Client:format_result() return self._format_cache end ---- @param client_format ClientFormat +--- @param client_format lsp_progress.ClientFormat --- @param spinner string[] ---- @return nil local function setup(client_format, spinner) ClientFormat = client_format Spinner = spinner diff --git a/lua/lsp-progress/defaults.lua b/lua/lsp-progress/defaults.lua index f0640e8..1d65b82 100644 --- a/lua/lsp-progress/defaults.lua +++ b/lua/lsp-progress/defaults.lua @@ -1,5 +1,5 @@ ---- @alias Configs table ---- @type Configs +--- @alias lsp_progress.Configs table +--- @type lsp_progress.Configs local Defaults = { -- Spinning icons. -- @@ -52,7 +52,7 @@ local Defaults = { -- * https://github.com/linrongbin16/lsp-progress.nvim/issues/50 -- * https://neovim.io/doc/user/builtin.html#mode() -- - --- @type DisableEventOpt[] + --- @type lsp_progress.DisableEventOpt[] disable_events_opts = { { mode = "i", @@ -72,7 +72,7 @@ local Defaults = { --- Progress in percentage numbers: 0-100. --- @param done boolean --- Indicate whether this series is the last one in progress. - --- @return SeriesFormatResult + --- @return lsp_progress.SeriesFormatResult --- The returned value will be passed to function `client_format` as --- one of the `series_messages` array, or ignored if return nil. series_format = function(title, message, percentage, done) @@ -109,7 +109,7 @@ local Defaults = { --- Spinner icon. --- @param series_messages string[]|table[] --- Messages array. - --- @return ClientFormatResult + --- @return lsp_progress.ClientFormatResult --- The returned value will be passed to function `format` as one of the --- `client_messages` array, or ignored if return nil. client_format = function(client_name, spinner, series_messages) @@ -131,7 +131,8 @@ local Defaults = { --- @return string --- The returned value will be returned as the result of `progress` API. format = function(client_messages) - local sign = " LSP" -- nf-fa-gear \uf013 + -- icon: nf-fa-gear \uf013 + local sign = " LSP" if #client_messages > 0 then return sign .. " " .. table.concat(client_messages, " ") end @@ -165,8 +166,8 @@ local Defaults = { file_log_name = "lsp-progress.log", } ---- @param option Configs ---- @return Configs +--- @param option lsp_progress.Configs +--- @return lsp_progress.Configs local function setup(option) local config = vim.tbl_deep_extend("force", vim.deepcopy(Defaults), option or {}) @@ -174,7 +175,7 @@ local function setup(option) end --- @package ---- @return Configs +--- @return lsp_progress.Configs local function _get_defaults() return Defaults end diff --git a/lua/lsp-progress/event.lua b/lua/lsp-progress/event.lua index d1b30b2..097028e 100644 --- a/lua/lsp-progress/event.lua +++ b/lua/lsp-progress/event.lua @@ -1,6 +1,6 @@ local logger = require("lsp-progress.logger") ---- @type Configs +--- @type lsp_progress.Configs local Configs = { --- @type string? name = nil, @@ -12,7 +12,7 @@ local Configs = { emit = false, } ---- @class DisableEventOpt +--- @class lsp_progress.DisableEventOpt --- @field mode string? --- @field filetype string? local DisableEventOpt = { @@ -21,8 +21,8 @@ local DisableEventOpt = { } --- @package ---- @param opts Configs ---- @return DisableEventOpt +--- @param opts lsp_progress.Configs +--- @return lsp_progress.DisableEventOpt function DisableEventOpt:new(opts) local o = { mode = opts.mode, @@ -57,15 +57,15 @@ function DisableEventOpt:match() return mode_match and filetype_match end ---- @class DisableEventOptsManager ---- @field disable_event_opts DisableEventOpt[] +--- @class lsp_progress.DisableEventOptsManager +--- @field disable_event_opts lsp_progress.DisableEventOpt[] local DisableEventOptsManager = { disable_event_opts = {}, } --- @package ---- @param opts Configs[]? ---- @return DisableEventOptsManager +--- @param opts lsp_progress.Configs[]? +--- @return lsp_progress.DisableEventOptsManager function DisableEventOptsManager:new(opts) local disable_event_opts = {} if type(opts) == "table" then @@ -92,7 +92,7 @@ function DisableEventOptsManager:match() return false end ---- @type DisableEventOptsManager? +--- @type lsp_progress.DisableEventOptsManager? local GlobalDisabledEventOptsManager = nil --- @package @@ -128,8 +128,7 @@ end --- @param event_name string --- @param event_update_time_limit integer --- @param internal_regular_update_time integer ---- @param disable_events_opts Configs[]? ---- @return nil +--- @param disable_events_opts lsp_progress.Configs[]? local function setup( event_name, event_update_time_limit, @@ -145,7 +144,6 @@ local function setup( regular_update() end ---- @type table local M = { setup = setup, emit = emit, diff --git a/lua/lsp-progress/logger.lua b/lua/lsp-progress/logger.lua index 0d173fc..d95040f 100644 --- a/lua/lsp-progress/logger.lua +++ b/lua/lsp-progress/logger.lua @@ -1,3 +1,6 @@ +local uv = (vim.fn.has("nvim-0.10") > 0 and vim.uv ~= nil) and vim.uv + or vim.loop + local PATH_SEPARATOR = (vim.fn.has("win32") > 0 or vim.fn.has("win64") > 0) and "\\" or "/" @@ -27,7 +30,7 @@ local LogHighlights = { [4] = "ErrorMsg", } ---- @type Configs +--- @type lsp_progress.Configs local Configs = { level = LogLevels.INFO, console_log = true, @@ -39,7 +42,6 @@ local Configs = { --- @param console_log boolean --- @param file_log boolean --- @param file_log_name string ---- @return nil local function setup(level, console_log, file_log, file_log_name) Configs.level = LogLevels[level] Configs.console_log = console_log @@ -76,10 +78,12 @@ local function log(level, msg) local fp = io.open(Configs.file_name, "a") if fp then for _, line in ipairs(msg_lines) do + local secs, ms = uv.gettimeofday() fp:write( string.format( - "%s [%s]: %s\n", - os.date("%Y-%m-%d %H:%M:%S"), + "%s.%03d [%s]: %s\n", + os.date("%Y-%m-%d %H:%M:%S", secs), + math.floor(ms / 1000), LogLevelNames[level], line ) diff --git a/lua/lsp-progress/series.lua b/lua/lsp-progress/series.lua index 486dbf2..ca25268 100644 --- a/lua/lsp-progress/series.lua +++ b/lua/lsp-progress/series.lua @@ -1,22 +1,22 @@ local logger = require("lsp-progress.logger") ---- @alias SeriesFormatResult string|any|nil ---- @alias SeriesFormat fun(title:string?,message:string?,percentage:integer?,done:boolean):SeriesFormatResult ---- @type SeriesFormat? +--- @alias lsp_progress.SeriesFormatResult string|any|nil +--- @alias lsp_progress.SeriesFormat fun(title:string?,message:string?,percentage:integer?,done:boolean):lsp_progress.SeriesFormatResult +--- @type lsp_progress.SeriesFormat? local SeriesFormat = nil ---- @class Series +--- @class lsp_progress.Series --- @field title string? --- @field message string? --- @field percentage integer? --- @field done boolean ---- @field private _format_cache SeriesFormatResult +--- @field private _format_cache lsp_progress.SeriesFormatResult local Series = {} --- @param title string? --- @param message string? --- @param percentage integer? ---- @return Series +--- @return lsp_progress.Series function Series:new(title, message, percentage) local o = { title = title, @@ -36,7 +36,7 @@ function Series:new(title, message, percentage) end --- @package ---- @return SeriesFormatResult +--- @return lsp_progress.SeriesFormatResult function Series:_format() assert(SeriesFormat ~= nil, "SeriesFormat cannot be null") @@ -92,12 +92,12 @@ function Series:finish(message) -- logger.debug("|series - Series:finish| finish: %s", vim.inspect(self)) end ---- @return SeriesFormatResult +--- @return lsp_progress.SeriesFormatResult function Series:format_result() return self._format_cache end ---- @param series_format SeriesFormat +--- @param series_format lsp_progress.SeriesFormat local function setup(series_format) SeriesFormat = series_format end