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

Can offset_encoding for Ruff be configured in Neovim? #14483

Closed
Shinzu opened this issue Nov 20, 2024 · 6 comments
Closed

Can offset_encoding for Ruff be configured in Neovim? #14483

Shinzu opened this issue Nov 20, 2024 · 6 comments
Labels
question Asking for support or clarification server Related to the LSP server

Comments

@Shinzu
Copy link

Shinzu commented Nov 20, 2024

Hello,

is it possible to configure the offset_enconding for ruff in neovim?

Background:

by default ruff has configured utf-8, when you use it together with pyright which is default to utf-16 neovim will produce a warning:

warning: multiple different client offset_encodings detected for buffer, this is not supported yet
@MichaReiser
Copy link
Member

I'm a bit confused by this warning because ruff isn't a client but a server. Ruff also negotiates the encoding with the client. That makes me suspect that another server doesn't support the position encoding negotiation and always enforces utf16 (in which case the previously negotiated utf8 encoding with ruff is outdated). But that seems like a neovim issue. Ideally neovim would re-negotiate with ruff if that happens

I found a related neovim issue neovim/nvim-lspconfig#2184

It seems that setting the position encoding to the one encoding supported by all servers fix the warning

@dhruvmanila
Copy link
Member

It seems that Neovim added support for UTF-8 and UTF-32 quite recently (last week) neovim/neovim#31209 which means that you must be running nightly Neovim. I think this is the reason that Ruff will select UTF-8 because the client now supports it:

fn find_best_position_encoding(client_capabilities: &ClientCapabilities) -> PositionEncoding {
client_capabilities
.general
.as_ref()
.and_then(|general_capabilities| general_capabilities.position_encodings.as_ref())
.and_then(|encodings| {
encodings
.iter()
.filter_map(|encoding| PositionEncoding::try_from(encoding).ok())
.max() // this selects the highest priority position encoding
})
.unwrap_or_default()
}

@dhruvmanila
Copy link
Member

@Shinzu Can you try running the latest nightly version of Neovim? I don't see any warnings on the latest master branch. In the buffer, Ruff is using UTF-8 and Pyright is using UTF-16.

@dhruvmanila dhruvmanila added question Asking for support or clarification server Related to the LSP server labels Nov 21, 2024
@dhruvmanila dhruvmanila changed the title [Question] Can offset_encoding for ruff be configured in neovim? Can offset_encoding for Ruff be configured in Neovim? Nov 21, 2024
@dhruvmanila
Copy link
Member

dhruvmanila commented Nov 21, 2024

The function has been deprecated where the warning is being raised (https://github.com/neovim/neovim/blob/01026ba47ba8a656bb5cd09afbb25b4b33c0b752/runtime/lua/vim/lsp/util.lua#L1889-L1920) and the offset_encoding parameter is now a required parameter to be passed in to various LSP functions (https://github.com/neovim/neovim/blob/01026ba47ba8a656bb5cd09afbb25b4b33c0b752/runtime/lua/vim/lsp/util.lua#L1876-L1882).

It's marked as a breaking change (neovim/neovim#31249), so you might want to update your dotfiles and / or wait for the ecosystem to catch up (plugins).

@Shinzu
Copy link
Author

Shinzu commented Nov 21, 2024

Thank you both for your answers.

Yes i'm running nightly. I will just wait. :)

@MichaReiser
Copy link
Member

I'll close this issue because I understand that this is an issue with neovim. Let me know if there's something that's left unanswered or if there's something we could do on our side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification server Related to the LSP server
Projects
None yet
Development

No branches or pull requests

3 participants