@@ -123,29 +123,35 @@ defmodule ElixirLS.LanguageServer.Parser do
123
123
state =
124
124
update_in ( state . debounce_refs [ uri ] , fn
125
125
nil ->
126
+ # schedule parse with debounce timeout
126
127
{ Process . send_after ( self ( ) , { :parse_file , uri } , @ debounce_timeout ) , current_version }
127
128
128
- { old_ref , ^ current_version } ->
129
+ { old_ref , old_version } when old_version >= current_version ->
130
+ # already parsing this or newer version - ignore this request
129
131
{ old_ref , current_version }
130
132
131
133
{ old_ref , old_version } when old_version < current_version ->
134
+ # cancel previous parse and schedule new one with debounce timeout
132
135
Process . cancel_timer ( old_ref , info: false )
133
136
{ Process . send_after ( self ( ) , { :parse_file , uri } , @ debounce_timeout ) , current_version }
134
137
end )
135
138
136
139
state =
137
140
update_in ( state . files [ uri ] , fn
138
141
nil ->
142
+ # add new file
139
143
% Context {
140
144
source_file: source_file ,
141
145
path: get_path ( uri )
142
146
}
143
147
144
148
% Context { source_file: % SourceFile { version: old_version } } = old_file
145
149
when current_version > old_version ->
150
+ # replace updated file with new version
146
151
% Context { old_file | source_file: source_file }
147
152
148
153
% Context { } = old_file ->
154
+ # ignore this request - this or newer version already in state
149
155
old_file
150
156
end )
151
157
0 commit comments