-
Notifications
You must be signed in to change notification settings - Fork 238
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(prisma-fmt): use UTF-16 offset in the response for the schema that contains multi-byte characters #4815
Conversation
CodSpeed Performance ReportMerging #4815 will not alter performanceComparing Summary
|
There are warnings about dead_code for many functions in |
@key-moon this happens because the module is included twice in both the library crate and the binary crate. I see that some existing modules in this package follow this pattern too but it's not really the best way to do it. Aside from leading to problems like the one you encountered, it will also lead to compiling the same code twice and potentially bloating the binary (for us maybe there's no binary size impact because The way it's normally done in Rust is you only include such modules in the library crate (i.e. in |
Understood. I am new to Rust, so your help with the basics was very helpful. While applying the suggested fix, I ran into a problem caused by the fact that This could be solved by not including Edit: I just pushed the fix that was described above. I'm not sure whether this fix was the right way to do it. |
The error caused by the conflict has been resolved. It took some time to resolve, but now this PR is back to a problem-free state. |
Is there anything you are having trouble with for the merge? If there is, I will work towards resolving it. |
Any updates? |
I would like to highlight the importance, as it seems the significance of this pull request might not be fully understood. While this pull request may appear to address an odd bug involving strange prisma files with emojis for you, it is actually a highly troublesome bug for those of us using languages represented by multibyte characters. This bug prevents us from using basic features like red underlines and quick fixes when we use our native language in comments. Could you please consider reviewing this pull request? Simply merging this PR will greatly improve the development experience for thousands of developers in regions where multibyte characters are used. |
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.
Hey @key-moon, thanks for the PR and sorry it wasn't reviewed yet. I'm not too familiar with this part of the codebase but to me the changes look good and make sense.
I left a few comments: first of all, there are new changes present on main
that are lost here because of moving the code and need to be integrated to offsets.rs
— this is more critical, and secondly, there's a suggestion for better performance / algorithmic complexity — take a look if it makes sense but it's not critical.
prisma-fmt/src/lint.rs
Outdated
start: offset_to_lsp_offset(err.span().start, db.source(err.span().file_id)), | ||
end: offset_to_lsp_offset(err.span().end, db.source(err.span().file_id)), |
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.
Should we have a function that takes a span and returns a pair of LSP offsets to avoid traversing the document in O(n) twice?
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 have implemented the span_to_range
function. Additionally, I replaced a function with the same name and role in offset.rs
(see https://github.com/prisma/prisma-engines/pull/4815/files#diff-557db087b8d611a0049284a4b38c817f1868a1dde965a9fa904c2dcaad576eb0R198). Since the order of arguments was different, I modified the usage accordingly. For consistency, I also adjusted the order of arguments for the range_after_span
function. Since this is an internally used function, I believe there should be no issues.
@Druue this is the fix for prisma/language-tools#1308 |
I apologize for any urgency I may have caused. I really appreciate your prompt review. Additionally, I have replied to the comment that was made. Thank you very much. |
Hey! Thank you so much for the PR and sorry for the delay. I've pulled this on and will see about finding some time to review this :) Some initial thoughts are if you can revert the function arg orderings to what they were to minimise the number of changes to read through |
Thank you for reviewing! Since the function signatures in There are only three places where these functions are used, so I don't think the review will be a significant effort. |
I realized that just implementing Additionally, with the implementation of |
We generally prefer to include contextual args first (e.g. the schema / document) and spans after / at the end.
I genuinely don't know what you're talking about here. There is only one I will say that this looks good though, thank you. I'm not going to block this on the above. Screen.Recording.2024-06-18.at.13.36.09.mov |
Thank you for your review 🙇 I created the Once again, thank you for the review! |
The current Prisma's LSP cannot handle schemas containing multibyte characters correctly.
This is because the offsets returned by prisma-fmt are calculated based on the number of bytes in UTF-8 encoding. In the LSP protocol, text offsets should be represented by the length in UTF-16 unless otherwise specified.
This pull request includes changes to the
offset_to_position
andposition_to_offset
functions, as well as the implementation of theoffset_to_lsp_offset
function and its usage withinlint::run
.This fixes the above issue.
fixes prisma/language-tools#1308