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

Adding support NotebookDocumentClientCapabilities #308

Open
MrBago opened this issue Nov 28, 2022 · 9 comments
Open

Adding support NotebookDocumentClientCapabilities #308

MrBago opened this issue Nov 28, 2022 · 9 comments

Comments

@MrBago
Copy link

MrBago commented Nov 28, 2022

The LSP 3.17 specification added support for notebook documents via NotebookDocumentClientCapabilities. I'd love to have support for this capability in python-lsp-server and to be able to use the language server with Jupyter or other notebooks.

I'd like to understand what would be need and how much effort it would be to add support for notebook documents.

If there is interest in including this improvement and someone could help provide guidance on the work, I may have capacity to work on this and submit a patch.

@ccordoba12
Copy link
Member

Hey @MrBago, thanks for your interest in adding this feature! I think @krassowski is the right person to provide guidance here because he has worked a lot on integrating LSP features in notebooks.

@MrBago
Copy link
Author

MrBago commented Nov 29, 2022

@ccordoba12 Thanks for the response. I've reached out to @krassowski as well. The main guidance I need is around understanding how text syncing currently works. The NotebookDocumentClientCapability is structured on top of the text syncing capability where a notebook is a collection of text documents. To support the notebook we'd need to be able to have multiple text documents represent a single "unit" for static or error analysis.

Does the language server keep an internal copy of documents when handing text sync messages? Is the text sync capability written as a plugin?

@krassowski
Copy link
Contributor

The LSP 3.17 specification added support for notebook documents via NotebookDocumentClientCapabilities

It did indeed...

I'd love to have support for this capability in python-lsp-server and to be able to use the language server with Jupyter or other notebooks.

🎉. Happy to help.

I'd like to understand what would be need and how much effort it would be to add support for notebook documents.

I would naively say that this should should be rather straightforward.

Does the language server keep an internal copy of documents when handing text sync messages?

Yes.

Is the text sync capability written as a plugin?

No. textDocument/didChange is handled here:

def m_text_document__did_change(self, contentChanges=None, textDocument=None, **_kwargs):
workspace = self._match_uri_to_workspace(textDocument['uri'])
for change in contentChanges:
workspace.update_document(
textDocument['uri'],
change,
version=textDocument.get('version')
)
self.lint(textDocument['uri'], is_saved=False)

def update_document(self, doc_uri, change, version=None):
self._docs[doc_uri].apply_change(change)
self._docs[doc_uri].version = version

Briefly, update_document stores an in-memory cache of the source file and updates it as needed. However, some plugins (annoyingly) relay on the file existing on disk (and being up to date/saved), e.g.:

cmd.extend(['--from-stdin', document.path])

I think that we should rewrite such plugins and remove the document path from public API (maybe it is too drastic, but hiding behind underscore may make plugin developers think twice before they use it).

@rchl
Copy link
Contributor

rchl commented Dec 1, 2022

Briefly, update_document stores an in-memory cache of the source file and updates it as needed. However, some plugins (annoyingly) relay on the file existing on disk (and being up to date/saved), e.g.:

cmd.extend(['--from-stdin', document.path])

I think that we should rewrite such plugins and remove the document path from public API (maybe it is too drastic, but hiding behind underscore may make plugin developers think twice before they use it).

This particulate example doesn't rely on file being on disk though. It gets data from stdin. The path is passed because some linter rules might need the file path to be able to work.

@samrat
Copy link

samrat commented May 9, 2023

Are there any updates on this issue?

@ccordoba12
Copy link
Member

No, there aren't, sorry.

@tkrabel-db
Copy link
Contributor

Hey folks - picking this up from @MrBago. I got capacity to work on this the next two weeks. 🎉 Will add a comment later about my thoughts on this!

@tkrabel-db
Copy link
Contributor

tkrabel-db commented May 30, 2023

@krassowski I looked into the LSP specs regarding the NotebookDocument support and I am not 100% sure how things fit together. Do you have a clear idea how to implement notebook support from reading the specs?

Do you have time for a call to discuss this? Others are also happily invited!

To give you context, I have the following open questions:

  • I am not sure what notebookCellTextDocumentFilter is useful for.
  • In the specs, it says that cell contents can be synchronized to the server using the standard textDocument/did* notification. Assume we do that: how would the Language Server get the content of the other cells for hooks that need the full notebook content?
  • In general, I am thinking about how to add notebook support without adding regressions to the normal textDocument support. Maybe the notebookDocument/* notifications help...

@tkrabel-db
Copy link
Contributor

FYI: I have a draft PR open, see #389

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

No branches or pull requests

6 participants