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

refactor: track too large files inside workspace server #4738

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented Dec 15, 2024

Summary

As the workspace server will become responsible for scanning projects, we also need to move the check for too large files into the server. Because there will be a disconnect between the initiation of the scanning and the pulling of diagnostics, we need to persist the FileTooLarge diagnostics. This PR implements a minimum version of this.

Later, I want to implement a pull_diagnostics_multiple() workspace method that can pull diagnostics for a scanned project as a whole. At that point, the persisted FileTooLarge will serve so we can return the right diagnostic at that point. Do you foresee any issues with this approach, @ematipico ?

Test Plan

Added a test case.

@arendjr arendjr requested a review from a team December 15, 2024 10:18
@github-actions github-actions bot added the A-Project Area: project label Dec 15, 2024
@@ -75,7 +75,7 @@ pub(crate) struct Document {
pub(crate) file_source_index: usize,

/// The result of the parser (syntax tree + diagnostics).
pub(crate) syntax: AnyParse,
pub(crate) syntax: Result<AnyParse, FileTooLarge>,
Copy link
Member

Choose a reason for hiding this comment

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

I think at this point we should start thinking about splitting WorkspaceError into two types:

  • WorkspaceError: actual errors that can occur during the call of a workspace API (missing method, serialisation mistakes, failing to call the server, etc.
  • WorkspaceDiagnostics: a new type, where we collect all diagnostics during the lifecycle of an API (parsing errors, file too large, file ignored, etc.). These diagnostics aren't errors and shouldn't abruptly stop an API call, contrary to WorkspaceError

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agreed, that’s a good suggestion 👍 Only reason I didn’t yet is because we only have a single kind for now, but if we need to have multiple diagnostics I’ll do it like this.

@@ -75,7 +75,7 @@ pub(crate) struct Document {
pub(crate) file_source_index: usize,

/// The result of the parser (syntax tree + diagnostics).
pub(crate) syntax: AnyParse,
pub(crate) syntax: Result<AnyParse, FileTooLarge>,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the document can have a new field called diagnostics instead. This could be useful to collect more than one diagnostic related to this document (file size, ignored, unknown document, etc.

Copy link
Contributor Author

@arendjr arendjr Dec 15, 2024

Choose a reason for hiding this comment

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

Unlike parser errors, of which there can be multiple in a document, I think there will be only one reason (at a time) that would prevent parsing altogether. That’s why I went for a Result type, since it clearly communicates we bailed out before we even got to the parsing.

In theory we could use a Vec of diagnostics in the Err variant, and if we ever need to it’s an easy change. I’m just not convinced yet we will need to.

Copy link
Contributor Author

@arendjr arendjr Dec 15, 2024

Choose a reason for hiding this comment

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

On second consideration, maybe an Either could communicate the semantics even slightly clearer than a Result. After all, it wasn't an error of the parser; instead, we either parse or store a diagnostic. But it's still an error of some kind, so I wonder if this subtle semantic difference is worth the extra dependency 😅

@arendjr arendjr force-pushed the arendjr/track-too-large-files branch from 1d0ef4a to b90cbe3 Compare December 15, 2024 16:56
@arendjr arendjr requested a review from ematipico December 15, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Project Area: project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants