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

UTF-8 and UTF-32 position encoding support #375

Merged
merged 8 commits into from
Sep 24, 2023
Merged

UTF-8 and UTF-32 position encoding support #375

merged 8 commits into from
Sep 24, 2023

Conversation

tombh
Copy link
Collaborator

@tombh tombh commented Sep 11, 2023

This allows editors to use position encodings other than the default of UTF-16. This contributes to LSP 3.17 support. See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#positionEncodingKind

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

pygls/protocol.py Outdated Show resolved Hide resolved
@tombh tombh force-pushed the tombh/utf8 branch 2 times, most recently from e8e4717 to 1ae014c Compare September 15, 2023 00:06
@tombh tombh marked this pull request as ready for review September 15, 2023 00:07
@tombh tombh force-pushed the tombh/utf8 branch 2 times, most recently from 90d4734 to 25150a1 Compare September 15, 2023 00:16
@tombh tombh requested a review from alcarney September 15, 2023 00:20
Copy link
Collaborator

@alcarney alcarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on the actual implementation of UTf-8 and UTF-32 support, but overall the approach looks fine to me.

Just added some notes around maintaining backwards compatibility

pygls/protocol.py Outdated Show resolved Hide resolved
pygls/workspace/position.py Show resolved Hide resolved
@karthiknadig
Copy link
Contributor

@tombh I published a build of lsprotocol with the fix for PositionEncodingKind

@tombh
Copy link
Collaborator Author

tombh commented Sep 20, 2023

Thanks Karthik, I did see that, thank you so much. I've just been busy and haven't had a chance to update this PR yet.

Once this is merged we can make a new release with LSP 3.17 support!

This commit is only for supporting sending preferred position encoding
from the client during startup. Even though this commit introduces the
server's ability to choose from the client's list of supported position
encodings, it doesn't actually support any other encoding from the
existing UTF-16.
Still no actual support for client encodings apart from UTF-16
@tombh
Copy link
Collaborator Author

tombh commented Sep 23, 2023

@alcarney I've pushed those changes. Also, because I'm trying to follow strict typing from now on, I made a change to the Server, LanguageServer classes, just moving the lsp field. I think it was to do with the converter work you did. Basically it was to better reflect that JsonRPCProtocol takes LanguageServer not Server. I isolated the change in the chore: move Server.lsp to LanguageServer.lsp commit, does that look ok?

@tombh tombh requested a review from alcarney September 23, 2023 02:21
@alcarney
Copy link
Collaborator

I've pushed those changes.

Thanks, they look great!

it was to better reflect that JsonRPCProtocol takes LanguageServer not Server

Does it have to though? Ideally, there shouldn't be anything in JsonRPCProtocol that depends on LanguageServer directly, since we have the LanguageServerProtocol class to hold the details specific to LSP.

I'm sure that is not the reality though! Otherwise you wouldn't have had to update the type annotations! 😄
But IMO if we have to change anything we should be trying to move to a place where JsonRPCProtocol can be paried with Server, just as LanguageServerProtocol is paired with LanguageServer.

Otherwise that base Server class is quite useless on it's own 😅


Sort of related I've been meaning to post some thoughts in #334 on how we apply what we've learned with the JsonRPCClient to the server side of pygls (e.g. autogenerated BaseLanguageServer class), move to the high level asyncio APIs and generally clean up all these little inconsistencies we're finding.

It'll be mid-longer term goal though (probably resulting in a v2?!) . Maybe I'll try and get something written down in the next few days so we have something concrete to discuss...

@tombh
Copy link
Collaborator Author

tombh commented Sep 23, 2023

Does it have to though? Ideally, there shouldn't be anything in JsonRPCProtocol that depends on LanguageServer directly, since we have the LanguageServerProtocol class to hold the details specific to LSP.

That totally makes sense. I've removed the commit for now and just ignored the type. I'll rejig it in the direction you mention another time. For the record these are the methods that need moving:

pygls/protocol.py:390: error: "Server" has no attribute "_report_server_error"  [attr-defined]
pygls/protocol.py:412: error: "Server" has no attribute "_report_server_error"  [attr-defined]
pygls/protocol.py:423: error: "Server" has no attribute "_report_server_error"  [attr-defined]
pygls/protocol.py:538: error: "Server" has no attribute "_report_server_error"  [attr-defined]
pygls/protocol.py:579: error: "Server" has no attribute "_report_server_error"  [attr-defined]
pygls/protocol.py:810: error: "Server" has no attribute "process_id"  [attr-defined]
pygls/protocol.py:812: error: "Server" has no attribute "_text_document_sync_kind"; maybe "text_document_sync_kind"?  [attr-defined]
pygls/protocol.py:813: error: "Server" has no attribute "_notebook_document_sync"  [attr-defined]

Sort of related I've been meaning to post some thoughts in #334 on how we apply what we've learned with the JsonRPCClient to the server side of pygls (e.g. autogenerated BaseLanguageServer class), move to the high level asyncio APIs and generally clean up all these little inconsistencies we're finding.

How interesting! That in emulating a client you've learnt how to improve the server. Really cool.

Copy link
Collaborator

@alcarney alcarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 😄

@alcarney
Copy link
Collaborator

For the record these are the methods that need moving:

Awesome thanks! They don't look too bad to fix, _report_server_error is generic enough that it could probably be moved into Server? - just with a non-LSP default reporting mechanism.
And the others look like a type annotation onserver here would be enough to fix them?

@tombh tombh merged commit 4f417c3 into main Sep 24, 2023
23 checks passed
@tombh tombh deleted the tombh/utf8 branch September 24, 2023 18:49
@tombh
Copy link
Collaborator Author

tombh commented Sep 24, 2023

Yeah, should be pretty easy (touch wood)

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.

3 participants