Add Jupyter Notebook document change snapshot test (#11944)

## Summary

Closes #11914.

This PR introduces a snapshot test that replays the LSP requests made
during a document formatting request, and confirms that the notebook
document is updated in the expected way.
This commit is contained in:
Jane Lewis 2024-06-20 22:29:27 -07:00 committed by GitHub
parent 927069c12f
commit 3ab7a8da73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 921 additions and 20 deletions

View file

@ -8,15 +8,16 @@ use crate::edit::{DocumentKey, DocumentVersion, NotebookDocument};
use crate::{PositionEncoding, TextDocument};
pub(crate) use self::capabilities::ResolvedClientCapabilities;
pub(crate) use self::index::DocumentQuery;
pub(crate) use self::settings::{AllSettings, ClientSettings};
pub use self::index::DocumentQuery;
pub(crate) use self::settings::AllSettings;
pub use self::settings::ClientSettings;
mod capabilities;
mod index;
mod settings;
/// The global state for the LSP
pub(crate) struct Session {
pub struct Session {
/// Used to retrieve information about open documents and settings.
index: index::Index,
/// The global position encoding, negotiated during LSP initialization.
@ -29,7 +30,7 @@ pub(crate) struct Session {
/// An immutable snapshot of `Session` that references
/// a specific document.
pub(crate) struct DocumentSnapshot {
pub struct DocumentSnapshot {
resolved_client_capabilities: Arc<ResolvedClientCapabilities>,
client_settings: settings::ResolvedClientSettings,
document_ref: index::DocumentQuery,
@ -37,7 +38,7 @@ pub(crate) struct DocumentSnapshot {
}
impl Session {
pub(crate) fn new(
pub fn new(
client_capabilities: &ClientCapabilities,
position_encoding: PositionEncoding,
global_settings: ClientSettings,
@ -53,12 +54,12 @@ impl Session {
})
}
pub(crate) fn key_from_url(&self, url: Url) -> DocumentKey {
pub fn key_from_url(&self, url: Url) -> DocumentKey {
self.index.key_from_url(url)
}
/// Creates a document snapshot with the URL referencing the document to snapshot.
pub(crate) fn take_snapshot(&self, url: Url) -> Option<DocumentSnapshot> {
pub fn take_snapshot(&self, url: Url) -> Option<DocumentSnapshot> {
let key = self.key_from_url(url);
Some(DocumentSnapshot {
resolved_client_capabilities: self.resolved_client_capabilities.clone(),
@ -98,7 +99,7 @@ impl Session {
///
/// The document key must point to a notebook document or cell, or this will
/// throw an error.
pub(crate) fn update_notebook_document(
pub fn update_notebook_document(
&mut self,
key: &DocumentKey,
cells: Option<NotebookDocumentCellChange>,
@ -112,7 +113,7 @@ impl Session {
/// Registers a notebook document at the provided `url`.
/// If a document is already open here, it will be overwritten.
pub(crate) fn open_notebook_document(&mut self, url: Url, document: NotebookDocument) {
pub fn open_notebook_document(&mut self, url: Url, document: NotebookDocument) {
self.index.open_notebook_document(url, document);
}
@ -175,7 +176,7 @@ impl DocumentSnapshot {
&self.client_settings
}
pub(crate) fn query(&self) -> &index::DocumentQuery {
pub fn query(&self) -> &index::DocumentQuery {
&self.document_ref
}