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
feat(lsp): add lsp.util.split_lines and lsp.util.split_lines_iter #16286
Conversation
14e73c5
to
194f91e
Compare
194f91e
to
14923f7
Compare
runtime/lua/vim/lsp.lua
Outdated
---@param bufnr (number) | ||
---@returns (string) | ||
local function buf_get_line_ending(bufnr) | ||
return format_line_ending[nvim_buf_get_option(bufnr, 'fileformat')] or '\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what scenario do we need the fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simply written defensively, AFAIK it is impossible to set fileformat to an invalid value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to think more about these. get_buf_text
is the only thing I think is 100% necessary or correct.
The issue with \r
is internally, we can have \r
without a properly tracked newline split. (so we can have midline \r
unlike other editors)
--- | ||
---@see |vim.lsp.util.split_lines_iter()| | ||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocuments | ||
function M.split_lines(text, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we don't internally handle \r
according to the specification, I'm not sure this is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about the function or the usages of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm talking about we shouldn't be splitting lines on \r before sending to the server
@mjlbach Alright, I give up. I'll undo the changes to usages of |
Do any Language Servers return CRLF newlines in textEdits? Asking for whether |
14923f7
to
24f6313
Compare
Nevermind, you can just |
\n
24f6313
to
112131b
Compare
\n
112131b
to
24f6313
Compare
@mjlbach What do we do with this PR? (Ref: #16277 (comment)) |
WDYM what do we do? I need to think about some of the thing's bjorn said about our endline handling, a lot of my internal justification for maintaining the line ending when communicating with the language server is undermined by the fact we save the buffer to disk as utf-8 |
Well, I mean, should I make it a PR with just a fix for #16231 and move split_lines to a different PR, or keep both in this PR, or something else? I have undone the changes to usage of split_lines because I couldn't find a server which reports back CR or CRLF line endings on hover, signature help, diagnostics or something of that matter, i.e. unrelated to file content tracking. |
24f6313
to
300d562
Compare
Moved the |
Closing this because it conflicts with #25272 and the functions added aren't used by other lsp components |
How do I generate documentation for
lsp.util.split_lines
andlsp.util.split_lines_iter
?