-
Notifications
You must be signed in to change notification settings - Fork 203
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
Parse YAPF diffs into TextEdits (instead of sending the full doc) #136
Conversation
Thanks for starting this work! The tests are failing on CI - it looks like they need updating to match the changes in 341732d:
|
6303e3d
to
b1e3447
Compare
@krassowski the tests pass locally now if you wanna run the workflow. |
I remember doing this and running tests!
0bb73cc
to
2dbf392
Compare
Actually fixed now. Ran |
Weird, I'm not getting these lint issues locally. Will look into it |
Will merge main after #134 is merged |
@masad-frost, now that #134 is merged, you can fix the merge conflicts here so we can merge 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.
Hey @masad-frost, thanks for patience with this! Last comment, then this should be ready.
Also, please fix the merge conflicts that this PR has now.
return text_edits | ||
|
||
|
||
def ensure_eof_new_line(document, eol_chars, text_edits): |
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.
This is a bit of a hack, see: google/yapf#1008
@ccordoba12 lint issues seem to be unrelated from this branch. |
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 @masad-frost, thanks for the updates! I think you're really close to finish this one.
I'll help with that after you solve my comments. |
thanks, quick fixes esp with the suggestions! |
Just the lints are left! Let me know if there's anything else I can address. If you have more test cases in mind or something |
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.
Thanks for your hard on this @masad-frost! I think it's finally ready.
Changes: * The `test_numpy_completion` test is currently broken - see davidhalter/jedi#1864 * The test flags were moved from setup.cfg to pyproject.toml - see python-lsp/python-lsp-server#207 * A dependency on `whatthepatch` was added for yapf - see python-lsp/python-lsp-server#136
Currently formatting with YAPF sends back the full document as a range, it's not great because:
To support this feature I used YAPF's unified diff output option. I took the output and passed it to
whatthepatch
to produce a parsed result, the format is outlined in the library's readme. We iterate over lines in the diff and createTextEdit
s. Left some comments around the code to make it more readable.To be able to test without strictly matching
TextEdit
s I also added a function to theworkspace
module calledapply_text_edits
which takes aDocument
instance andTextEdit
s and returns a new source/string with the text edits applied. I wrote tests for this function based on the tests in the vscode language server repo. This function is now only used for testing, but I imagine it being useful for anyone working with text edits