-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Initial support for notebook document sync methods #356
Conversation
28dbeba
to
a6e6851
Compare
This is probably good enough to merge now, I expect the best way to get some feedback is to get this out there in a release so people can try it out Any thoughts? |
pygls/server.py
Outdated
converter_factory: Callable[[], cattrs.Converter], | ||
loop: Optional[asyncio.AbstractEventLoop] = None, | ||
max_workers: int = 2, | ||
sync_kind: Optional[TextDocumentSyncKind] = None, |
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 this remain Incremental
?
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 think this will break servers. Many of the servers I have written assume this is set to Incremental by default.
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 should've been ok, since this is the base Server
class where I don't think this was really used.
It's also set by the LanguageServer constructor.
That said, I don't think we gain anything from changing this so I've rolled it back anyway 😄
3615dd7
to
12c63c2
Compare
Now that there is a distinction between text documents and notebook documents, this commit renames the methods which act on text documents accordingly. The previous method names will still work, but now emit deprecation warnings
In order to enable `notebookDocument/did*` messages from the client, a server must provide its chosen `NotebookDocumentSyncOptions` as part of its `ServerCapabilities`. This commit adds a new `notebook_document_sync` option to the `LanguageServer` constructor allowing this option to be set.
To stop type checkers like pyright complaining about the possibility of `self.workspace` being `None`, the workspace is now stored in `self._workspace` and accessed by via a property. This property performs the check for `None` and raises a RuntimeError accordingly
12c63c2
to
4774f52
Compare
Let's merge this then? Would be good to get the confirmation from Karthik, but sounds like you're happy Alex? |
Yes :) |
Description (e.g. "Related to ...", etc.)
This is a first pass at implementing support for the
notebookDocument/did*
group of messages from the LSP spec.This PR depends on a future version of
lsprotocol
that has some additional fixes(see Missing structure hook(s?) for notebook types microsoft/lsprotocol#228, Unable to structure
NotebookDocumentSyncOptions
microsoft/lsprotocol#259)Servers can advertise support for notebooks by passing an instance of
NotebookDocumentSyncOptions
to theLanguageServer
constructor. e.g. from theinlay_hints.py
serverNotebooks as a whole are represented using instances of the
NotebookDocument
class that comes fromlsprotocol
Like regular text documents, notebook cell contents are represented as instances of
pygls.workspace.TextDocument
(previously calledDocument
)Notebooks can be accessed from the
Workspace
using the newworkspace.get_notebook_document()
method eithernotebook_uri
of the notebook itself orcell_uri
of one of the text documents representing the contents of a cell in the notebookCurrently this is the only notebook specific method exposed to server authors - @karthiknadig let me know if you have anything specific you'd like
pygls
to handle/provideGeneric references to "document" have been renamed to "text_document" so that it's clear which kind of document a method/object is referring to. Old names still work, but emit deprecation warnings where possible - see 9034bdb
The example
inlays_hints.py
server has been updated to support notebooks.#
characters on a line on their own are annotated with the notebook's uri and index of the cell it resides in - let me know if you can think of a more interesting demonstration of the notebook support! 😅Closes #311
Code review checklist (for code reviewer to complete)