Skip to content

Commit

Permalink
Add option to not echo the message
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed Feb 21, 2024
1 parent 2e89014 commit c46ead5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ Read the documentation of whatever you want to use.
## Usage

Just require and call setup and thats it.
**NOTE**: You dont need to provide the configuration, below is just default config, you can just
call setup with no arguments for default.

```lua
require("lspecho").setup()
require("lspecho").setup {
echo = true, -- Echo progress messages, if set to false you can use .message() to get the current message
}

```

## Similar projects
Expand Down
17 changes: 15 additions & 2 deletions lua/lspecho/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local M = {}

local series = {}
local last_message = ''

local function log(msg)
local client = msg.client or ''
Expand Down Expand Up @@ -38,7 +39,10 @@ local function log(msg)
end
end

vim.api.nvim_command(string.format('redraw | echo "%s"', string.sub(out, 1, vim.v.echospace)))
last_message = out
if M.config.echo then
vim.api.nvim_command(string.format('redraw | echo "%s"', string.sub(out, 1, vim.v.echospace)))
end
end

local function lsp_progress(err, progress, ctx)
Expand Down Expand Up @@ -85,7 +89,16 @@ local function lsp_progress(err, progress, ctx)
end
end

function M.setup()
M.config = {
echo = true, -- Echo progress messages, if set to false you can use .message() to get the current message
}

function M.message()
return last_message
end

function M.setup(config)
M.config = vim.tbl_deep_extend('force', M.config, config or {})
local old_handler = vim.lsp.handlers['$/progress']
vim.lsp.handlers['$/progress'] = function(...)
if old_handler then
Expand Down

0 comments on commit c46ead5

Please sign in to comment.