@@ -72,7 +72,7 @@ impl FileInfoAst {
7272
7373#[ derive( Debug ) ]
7474pub struct FileInfo {
75- pub version : i32 ,
75+ pub version : Option < i32 > ,
7676 pub uri : String ,
7777 pub valid : bool , // indicates if the file contains syntax error or not
7878 pub opened : bool ,
@@ -87,7 +87,7 @@ pub struct FileInfo {
8787impl FileInfo {
8888 fn new ( uri : String ) -> Self {
8989 Self {
90- version : 0 ,
90+ version : None ,
9191 uri,
9292 valid : true ,
9393 opened : false ,
@@ -112,18 +112,25 @@ impl FileInfo {
112112 // -100 can be given as version number to indicates that the file has not been opened yet, and that we have to load it ourself
113113 // See https://github.com/Microsoft/language-server-protocol/issues/177
114114 // Return true if the update has been done and not discarded
115- if let Some ( version) = version {
116- if version == -100 {
117- self . version = 1 ;
118- } else {
115+ match version {
116+ // -100, we set FileInfo to -100 if it was not opened yet. Otherwise, we do not change the version
117+ Some ( -100 ) => if !self . opened {
118+ self . version = Some ( -100 ) ;
119+ } else if !force { // If opened, with -100, we do not update
120+ return false ;
121+ } ,
122+ // normal version number, we update if higher, and set to opened anyway
123+ Some ( version) => {
119124 self . opened = true ;
120- if version <= self . version && !force {
125+ if self . version . map ( |v| version <= v) . unwrap_or ( false ) && !force {
126+ // If the version is not higher, we do not update the file
121127 return false ;
122128 }
123- self . version = version;
129+ self . version = Some ( version) ;
124130 }
125- } else if self . version != 0 && !force {
126- return false ;
131+ // no version provided, we update only if the file is not opened or on force
132+ None if self . version . is_some ( ) && !force => return false ,
133+ _ => { } ,
127134 }
128135 self . diagnostics . clear ( ) ;
129136 if let Some ( content) = content {
@@ -376,7 +383,7 @@ impl FileInfo {
376383 session. send_notification :: < PublishDiagnosticsParams > ( PublishDiagnostics :: METHOD , PublishDiagnosticsParams {
377384 uri : FileMgr :: pathname2uri ( & self . uri ) ,
378385 diagnostics : all_diagnostics,
379- version : Some ( self . version ) ,
386+ version : self . version ,
380387 } ) ;
381388 self . need_push = false ;
382389 }
0 commit comments