@@ -15,14 +15,22 @@ use std::time::Duration;
1515
1616use anyhow:: Result ;
1717use lsp_server:: { Connection , Message , RequestId , Response , ResponseError } ;
18- use lsp_types:: notification:: { DidOpenTextDocument , Exit , Initialized , Notification } ;
19- use lsp_types:: request:: { Initialize , Request , Shutdown , WorkspaceConfiguration } ;
18+ use lsp_types:: notification:: {
19+ DidChangeTextDocument , DidChangeWatchedFiles , DidCloseTextDocument , DidOpenTextDocument , Exit ,
20+ Initialized , Notification ,
21+ } ;
22+ use lsp_types:: request:: {
23+ DocumentDiagnosticRequest , Initialize , Request , Shutdown , WorkspaceConfiguration ,
24+ } ;
2025use lsp_types:: {
2126 ClientCapabilities , ConfigurationParams , DiagnosticClientCapabilities ,
22- DidChangeWatchedFilesClientCapabilities , FileEvent , InitializeParams , InitializeResult ,
23- InitializedParams , PublishDiagnosticsClientCapabilities , RegistrationParams ,
24- TextDocumentClientCapabilities , TextDocumentContentChangeEvent , Url ,
25- WorkspaceClientCapabilities , WorkspaceFolder ,
27+ DidChangeTextDocumentParams , DidChangeWatchedFilesClientCapabilities ,
28+ DidChangeWatchedFilesParams , DidCloseTextDocumentParams , DidOpenTextDocumentParams ,
29+ DocumentDiagnosticParams , DocumentDiagnosticReportResult , FileEvent , InitializeParams ,
30+ InitializeResult , InitializedParams , PartialResultParams , PublishDiagnosticsClientCapabilities ,
31+ RegistrationParams , TextDocumentClientCapabilities , TextDocumentContentChangeEvent ,
32+ TextDocumentIdentifier , TextDocumentItem , Url , VersionedTextDocumentIdentifier ,
33+ WorkDoneProgressParams , WorkspaceClientCapabilities , WorkspaceFolder ,
2634} ;
2735use ruff_db:: system:: { InMemorySystem , SystemPath , TestSystem } ;
2836use serde:: de:: DeserializeOwned ;
@@ -289,7 +297,6 @@ impl TestServer {
289297 /// The caller should ensure that the server is expected to send this notification type. It
290298 /// will keep polling the server for notifications up to 10 times before giving up. It can
291299 /// return an error if the notification is not received within `recv_timeout` duration.
292- #[ expect( dead_code) ]
293300 pub ( crate ) fn get_notification < N : Notification > ( & mut self ) -> Result < N :: Params > {
294301 for _ in 0 ..10 {
295302 self . receive ( ) ?;
@@ -474,14 +481,17 @@ impl TestServer {
474481 }
475482
476483 /// Send a `textDocument/didOpen` notification
477- #[ expect( dead_code) ]
478- pub ( crate ) fn open_text_document ( & mut self , uri : Url , content : String ) -> Result < ( ) > {
479- let params = lsp_types:: DidOpenTextDocumentParams {
480- text_document : lsp_types:: TextDocumentItem {
481- uri,
484+ pub ( crate ) fn open_text_document (
485+ & mut self ,
486+ path : impl AsRef < SystemPath > ,
487+ content : & impl ToString ,
488+ ) -> Result < ( ) > {
489+ let params = DidOpenTextDocumentParams {
490+ text_document : TextDocumentItem {
491+ uri : Url :: from_file_path ( path. as_ref ( ) ) . expect ( "Path must be a valid URL" ) ,
482492 language_id : "python" . to_string ( ) ,
483493 version : self . next_document_version ( ) ,
484- text : content,
494+ text : content. to_string ( ) ,
485495 } ,
486496 } ;
487497 self . send_notification :: < DidOpenTextDocument > ( params)
@@ -491,33 +501,52 @@ impl TestServer {
491501 #[ expect( dead_code) ]
492502 pub ( crate ) fn change_text_document (
493503 & mut self ,
494- uri : Url ,
504+ path : impl AsRef < SystemPath > ,
495505 changes : Vec < TextDocumentContentChangeEvent > ,
496506 ) -> Result < ( ) > {
497- let params = lsp_types :: DidChangeTextDocumentParams {
498- text_document : lsp_types :: VersionedTextDocumentIdentifier {
499- uri,
507+ let params = DidChangeTextDocumentParams {
508+ text_document : VersionedTextDocumentIdentifier {
509+ uri : Url :: from_file_path ( path . as_ref ( ) ) . expect ( "Path must be a valid URL" ) ,
500510 version : self . next_document_version ( ) ,
501511 } ,
502512 content_changes : changes,
503513 } ;
504- self . send_notification :: < lsp_types :: notification :: DidChangeTextDocument > ( params)
514+ self . send_notification :: < DidChangeTextDocument > ( params)
505515 }
506516
507517 /// Send a `textDocument/didClose` notification
508518 #[ expect( dead_code) ]
509- pub ( crate ) fn close_text_document ( & mut self , uri : Url ) -> Result < ( ) > {
510- let params = lsp_types:: DidCloseTextDocumentParams {
511- text_document : lsp_types:: TextDocumentIdentifier { uri } ,
519+ pub ( crate ) fn close_text_document ( & mut self , path : impl AsRef < SystemPath > ) -> Result < ( ) > {
520+ let params = DidCloseTextDocumentParams {
521+ text_document : TextDocumentIdentifier {
522+ uri : Url :: from_file_path ( path. as_ref ( ) ) . expect ( "Path must be a valid URL" ) ,
523+ } ,
512524 } ;
513- self . send_notification :: < lsp_types :: notification :: DidCloseTextDocument > ( params)
525+ self . send_notification :: < DidCloseTextDocument > ( params)
514526 }
515527
516528 /// Send a `workspace/didChangeWatchedFiles` notification with the given file events
517529 #[ expect( dead_code) ]
518530 pub ( crate ) fn did_change_watched_files ( & mut self , events : Vec < FileEvent > ) -> Result < ( ) > {
519- let params = lsp_types:: DidChangeWatchedFilesParams { changes : events } ;
520- self . send_notification :: < lsp_types:: notification:: DidChangeWatchedFiles > ( params)
531+ let params = DidChangeWatchedFilesParams { changes : events } ;
532+ self . send_notification :: < DidChangeWatchedFiles > ( params)
533+ }
534+
535+ /// Send a `textDocument/diagnostic` request for the document at the given path.
536+ pub ( crate ) fn document_diagnostic_request (
537+ & mut self ,
538+ path : impl AsRef < SystemPath > ,
539+ ) -> Result < DocumentDiagnosticReportResult > {
540+ let uri = Url :: from_file_path ( path. as_ref ( ) ) . expect ( "Path must be a valid URL" ) ;
541+ let params = DocumentDiagnosticParams {
542+ text_document : TextDocumentIdentifier { uri } ,
543+ identifier : Some ( "ty" . to_string ( ) ) ,
544+ previous_result_id : None ,
545+ work_done_progress_params : WorkDoneProgressParams :: default ( ) ,
546+ partial_result_params : PartialResultParams :: default ( ) ,
547+ } ;
548+ let id = self . send_request :: < DocumentDiagnosticRequest > ( params) ?;
549+ self . get_response :: < DocumentDiagnosticReportResult > ( id)
521550 }
522551}
523552
@@ -581,7 +610,6 @@ impl TestServerBuilder {
581610 }
582611
583612 /// Enable or disable pull diagnostics capability
584- #[ expect( dead_code) ]
585613 pub ( crate ) fn with_pull_diagnostics ( mut self , enabled : bool ) -> Self {
586614 self . client_capabilities
587615 . text_document
0 commit comments