1
- use crate :: { documents:: Document , session:: Session , utils:: apply_document_changes} ;
1
+ use crate :: {
2
+ diagnostics:: LspError , documents:: Document , session:: Session , utils:: apply_document_changes,
3
+ } ;
2
4
use anyhow:: Result ;
3
5
use pg_lsp_converters:: from_proto:: text_range;
4
6
use pg_workspace:: workspace:: {
@@ -47,13 +49,15 @@ pub(crate) async fn did_open(
47
49
pub ( crate ) async fn did_change (
48
50
session : & Session ,
49
51
params : lsp_types:: DidChangeTextDocumentParams ,
50
- ) -> Result < ( ) > {
52
+ ) -> Result < ( ) , LspError > {
53
+ tracing:: info!( "did_change: {:#?}" , params) ;
54
+
51
55
let url = params. text_document . uri ;
52
56
let version = params. text_document . version ;
53
57
54
58
let pglsp_path = session. file_path ( & url) ?;
55
59
56
- // we need to keep the documents here too for the line index
60
+ let old_doc = session . document ( & url ) ? ;
57
61
let old_text = session. workspace . get_file_content ( GetFileContentParams {
58
62
path : pglsp_path. clone ( ) ,
59
63
} ) ?;
@@ -71,23 +75,21 @@ pub(crate) async fn did_change(
71
75
& params. content_changes [ start..] ,
72
76
) ;
73
77
74
- let new_doc = Document :: new ( version, & text) ;
75
-
76
78
session. workspace . change_file ( ChangeFileParams {
77
79
path : pglsp_path,
78
80
version,
79
81
changes : params. content_changes [ start..]
80
82
. iter ( )
81
83
. map ( |c| ChangeParams {
82
84
range : c. range . and_then ( |r| {
83
- text_range ( & new_doc . line_index , r, session. position_encoding ( ) ) . ok ( )
85
+ text_range ( & old_doc . line_index , r, session. position_encoding ( ) ) . ok ( )
84
86
} ) ,
85
87
text : c. text . clone ( ) ,
86
88
} )
87
89
. collect ( ) ,
88
90
} ) ?;
89
91
90
- session. insert_document ( url. clone ( ) , new_doc ) ;
92
+ session. insert_document ( url. clone ( ) , Document :: new ( version , & text ) ) ;
91
93
92
94
if let Err ( err) = session. update_diagnostics ( url) . await {
93
95
error ! ( "Failed to update diagnostics: {}" , err) ;
0 commit comments