Skip to content

[ty] publish settings diagnostics#19335

Merged
Gankra merged 1 commit intomainfrom
gankra/global-err
Jul 17, 2025
Merged

[ty] publish settings diagnostics#19335
Gankra merged 1 commit intomainfrom
gankra/global-err

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Jul 14, 2025

No description provided.

@Gankra Gankra added the server Related to the LSP server label Jul 14, 2025
@Gankra Gankra added ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels Jul 14, 2025
@AlexWaygood AlexWaygood removed their request for review July 14, 2025 16:50
@Gankra
Copy link
Contributor Author

Gankra commented Jul 14, 2025

Diagnostics now properly show up like this:

Screenshot 2025-07-14 at 12 50 09 PM

And clear out whenever the issue is fixed.

@Gankra
Copy link
Contributor Author

Gankra commented Jul 14, 2025

Oh boy micha really merge conflicted me bad h'ok...

/// notification].
///
/// [publish diagnostics notification]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics
pub(super) fn publish_settings_diagnostics(session: &mut Session, client: &Client) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should change this method to take a &mut Project instead. It should be unlikely that a user changes all projects at once. It's more likely that they changed a setting for a specific project.

This would also ensure that we don't publish diagnostics for the default database (it should never have setting diagnostics but initializing it isn't entirely free)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, really? the default project really can't have any settings diagnostics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also the current signature is "required" by the design of DidChangeWatchedFiles which processes random changes to random databases all together, producing only a single project_changed boolean. I could indeed make this more granular if we tracked project_changed per-project (but it's not clear to me it's worth the effort?).

Copy link
Member

Choose a reason for hiding this comment

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

did_change_watched_files does group all files by database and then calls apply_changes exacltly once per database. See this loop where root maps to the root of a database:

for (root, changes) in events_by_db {
tracing::debug!("Applying changes to `{root}`");
let result = session.apply_changes(&AnySystemPath::System(root), changes);
project_changed |= result.project_changed();
}

This should allow you to make publish_settings_diagnostics per database.

@MichaReiser
Copy link
Member

Oh boy micha really merge conflicted me bad h'ok...

Lol sorry. But not all of the merge conflicts are because of me. Some are because of Dhruv ;)

@Gankra Gankra force-pushed the gankra/global-err branch from ca1f1b4 to 84608c0 Compare July 14, 2025 17:11
@Gankra
Copy link
Contributor Author

Gankra commented Jul 14, 2025

Rebased

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser
Copy link
Member

I'll do a full review tomorrow as it's late here.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

This overall looks good.

We should remove the publish_settings_diagnostics calls in did_change and did_open because they're unnecessary. Instead, we should call publish_settings_diagnostics in Session::initialize_workspaces

I'd also recommend making publish_settings_diagnostics to take a specific project instead of iterating over all projects.

/// notification].
///
/// [publish diagnostics notification]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics
pub(super) fn publish_settings_diagnostics(session: &mut Session, client: &Client) {
Copy link
Member

Choose a reason for hiding this comment

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

did_change_watched_files does group all files by database and then calls apply_changes exacltly once per database. See this loop where root maps to the root of a database:

for (root, changes) in events_by_db {
tracing::debug!("Applying changes to `{root}`");
let result = session.apply_changes(&AnySystemPath::System(root), changes);
project_changed |= result.project_changed();
}

This should allow you to make publish_settings_diagnostics per database.

}
}

publish_settings_diagnostics(session, client);
Copy link
Member

Choose a reason for hiding this comment

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

We should skip calling publish_settings_diagnostics if the client uses workspace diagnostics as it is unnecessary

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 moved the check inside the call so each callsite doesn't need to think about it.

db,
untracked_files_with_pushed_diagnostics: untracked,
},
);
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 we need to call into publish_settings_diagnostics here to ensure the server pushes the diagnostics on initiale load.

@sharkdp sharkdp removed their request for review July 16, 2025 06:14
@Gankra Gankra force-pushed the gankra/global-err branch from caf9092 to d4fbb20 Compare July 17, 2025 14:39
@Gankra
Copy link
Contributor Author

Gankra commented Jul 17, 2025

Review addressed, should be ready to land.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

@Gankra Gankra merged commit 35f33d9 into main Jul 17, 2025
37 checks passed
@Gankra Gankra deleted the gankra/global-err branch July 17, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants