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

Add notebook support. #268

Closed
wants to merge 4 commits into from
Closed

Add notebook support. #268

wants to merge 4 commits into from

Conversation

gibbz00
Copy link
Contributor

@gibbz00 gibbz00 commented Oct 7, 2023

Will conflict with #266 depending on which gets merged first.
Depends on #266.

@nayeemrmn
Copy link

Closes #269.

Copy link

@zebreus zebreus left a comment

Choose a reason for hiding this comment

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

I compared the PR to the specification for notebook document synchronization and commented all spots where it did not match up.

src/notebook.rs Outdated Show resolved Hide resolved
src/notebook.rs Outdated Show resolved Hide resolved
src/notebook.rs Outdated
Comment on lines 210 to 216
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum NotebookDocumentFilter {
ByType(NotebookDocumentFilterByType),
ByScheme(NotebookDocumentFilterByScheme),
ByPattern(NotebookDocumentFilterByPattern),
}
Copy link

Choose a reason for hiding this comment

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

The specification defines NotebookDocumentFilter basically as a struct with three optional fields but one of them needs to be set. In the past the specification has "hidden" types like this, by specifying the type as a struct with optional fields and noting in the text, that one field must be set for it to be valid. For example DocumentFilter has the following note:

Please note that for a document filter to be valid at least one of the properties for language, scheme, or pattern must be set. To keep the type definition simple all properties are marked as optional.

For these other cases lsp-types uses structs with optional fields. It would be more consistent and usable if we did the same for NotebookDocumentFilter and NotebookSelector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm, I see where you're coming from, but I'm not entirely convinced that this should simply use optional fields. You might be correct in that optional fields might be more usable than the other, but more so for those well versed with the spec.

I still think one should try to leverage the type system as much as possible when it comes to defining the domain. The current solution is one way of doing so. Silent errors and unpleasant surprises are pretty easy to introduce if not.

I'm nonetheless open to changing this as suggested, but I think I would like to receive some input from others before deciding on anything. (If that's even up to me.) 😊

Copy link

Choose a reason for hiding this comment

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

I agree with you, but think that the interface of NotebookDocumentFilter should be consistent with DocumentFilter, because they are basically the same thing. So we should either change this PR or change the interface of DocumentFilter.

Maybe @Marwes or @ebkalderon can help us decide.

Copy link

Choose a reason for hiding this comment

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

I feel like the patch as is captures the specification better than having 3 optional fields.
The only thing I would consider is since the spec doesn't define the NotebookDocumentFilterBy* types,
you could consider inlining those structures into the enum variants themselves like:

enum NotebookDocumentFilter {
  ByType{notebook_type: String, scheme: Option<String>, pattern: Option<String>},
  ...
}

I feel like the DocumentFilter case is different, since there the spec is actually defining it as a single struct with 3 optional fields, but NetworkDocumentFilter defines it differently, as one of any 3 structs each with 1 required field, and 2 optional fields... enum captures that latter definition better than struct.

I'm overall not very opinionated on whether its worthwhile to eliminate these intermediate types,
and while I do use the library, I haven't really contributed to this library before so my opinion shouldn't really hold much weight honestly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can totally get behind inlining the variants! Great idea :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like how df3eeea captures things, as I also agree that the spec itself differs from how it presents NotebookDocumentFilter and DocumentFilter 🤗

Copy link
Member

Choose a reason for hiding this comment

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

Inlining it seems like the right trade-off for now. Ideally the LSP spec should homogenize how it defines these two types though (and we should as well), but for now having them be different seems fine, we might be able to find out which is preferred by hearing from people who use both.

src/notebook.rs Outdated Show resolved Hide resolved
src/notebook.rs Outdated Show resolved Hide resolved
@gibbz00
Copy link
Contributor Author

gibbz00 commented Nov 18, 2023

I compared the PR to the specification for notebook document synchronization and commented all spots where it did not match up.

Thanks for the review. I went ahead and resolved all the rename suggestions.

@zebreus
Copy link

zebreus commented Nov 18, 2023

I did not notice it earlier, but all fields in the new structs should be pub, otherwise they cannot be set.

@gibbz00
Copy link
Contributor Author

gibbz00 commented Nov 18, 2023

Omg 🙈 of course, thanks. I suspect the reason for this sloppy implementation is that I just needed the structs to exist when I was experimenting with enum based lsp services (over dyn dispatch), my apologies.

@bartlomieju
Copy link

Hey, Bartek from the Deno team here 🖐️

This patch is quite important to us and blocking us on adding LSP support for Jupyter notebooks. Is there anything we can do to help and expedite landing of this PR?

@snowsignal
Copy link

Hi, this is Jane from the Astral team 👋

Adding on to what @bartlomieju said, this is an important PR that's blocking support for Jupyter notebooks in our new language server. We plan on using this PR (or a potential fork of it) as a git dependency until this gets merged. If there's anything we can do to help get this PR merged, please let us know.

@ple1n
Copy link

ple1n commented May 16, 2024

any update

@ple1n
Copy link

ple1n commented May 17, 2024

@Marwes
Copy link
Member

Marwes commented May 17, 2024

Released as 0.96. Sorry for losing track of this.

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.

9 participants