Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Escapes percentages in LSP progress messages #95

Merged
merged 1 commit into from
Nov 7, 2023
Merged

fix: Escapes percentages in LSP progress messages #95

merged 1 commit into from
Nov 7, 2023

Conversation

cuducos
Copy link
Contributor

@cuducos cuducos commented Nov 6, 2023

A trio I use (Ruby LSP, Solargraph and RuboCop) is sending messages through LSP progress triggering an error like E539: Illegal character < >.

I did some debugging and found out when the message in the series_format contains a % it needs to be escaped.

For example, when in the series_format, if the message is 100% completed, the space right afer the % triggers the E539: Illegal character < > because the end result sent to Neovim would be:

%#lualine_a_normal# NORMAL %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  sdp-migration/low-install-checks-to-prod %#lualine_transitional_lualine_b_normal_to_lualine_c_filetype_DevIconRb_normal#%<%#lualine_c_filetype_DevIconRb_normal# %#lualine_c_normal# ruby %#lualine_c_normal#%#lualine_c_normal#  app/jobs/trust_automation/install_check_ingestion_job.rb %#lualine_c_normal#%=%#lualine_c_normal#  LSP [ruby_ls] ⣟ Ruby LSP: indexing files 100% completed (100%%) - done %#lualine_c_normal#  %#lualine_c_normal# utf-8 %#lualine_transitional_lualine_a_normal_to_lualine_c_normal#%#lualine_a_normal#   1:1  %#lualine_a_normal# Top 

Notice that in Ruby LSP: indexing files 100% completed (100%%) the second % is escaped, but the first one is not.

This should help get Ruby LSP going, as well as other LSP that uses % in the messages themselves.

@linrongbin16 linrongbin16 changed the title Escapes percentages in LSP progress messages fix: Escapes percentages in LSP progress messages Nov 6, 2023
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
lua/lsp-progress/defaults.lua 92.50% <100.00%> (+0.19%) ⬆️

📢 Thoughts on this report? Let us know!

@linrongbin16
Copy link
Owner

hi @cuducos, thanks to your PR, please also update default_spec.lua to pass the unit tests.

@cuducos
Copy link
Contributor Author

cuducos commented Nov 6, 2023

Thanks for the quick response! I'm on that right now : )

Also… thanks for the great plugin and for being really active over here 💜

@linrongbin16
Copy link
Owner

linrongbin16 commented Nov 6, 2023

I am not in front of my keyboard, would you please help check what is the version of vim.pesc?

If nvim-0.6 don't have this API, we may need to consider other implementations, or update the minimal required nvim version.

@cuducos
Copy link
Contributor Author

cuducos commented Nov 6, 2023

Great catch! Probably it is newer. I see it as part of this discussion neovim/neovim#23242 which dates from April (I couldn't find yet when it was actually added). Probably it's a 0.9+ thing. I'll go for an alternate implementation.

@cuducos
Copy link
Contributor Author

cuducos commented Nov 6, 2023

Updating for the records: vim.pesc() apparently has an undocumented side-effect on older Neovim versions.

This snippet:

local text = "42%"
local cleaned = vim.pesc(text)
print(vim.pesc(text))
print(cleaned)

In 0.9.1 results in:

42%%                                                                                                                                                                               
42%%

In 0.4.4, though, results in:

42%% 1                                                                                                                                                                            
42%%

Based on that, it looks like just storing the result o vim.pesc in a variable might mitigate the error in older versions. Changing the PR in a minute.

cuducos added a commit to cuducos/dotfiles that referenced this pull request Nov 7, 2023
@linrongbin16
Copy link
Owner

linrongbin16 commented Nov 7, 2023

Yeah, I search this API in helpful.vim, it shows it's from nvim-0.4.

image

Should be good then.


Update: tested in my local machine with lua_ls, works good. Merged into main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants