Skip to content

Commit 016a32f

Browse files
committed
fix a rare parser crash
1 parent 3008da3 commit 016a32f

File tree

1 file changed

+7
-1
lines changed
  • apps/language_server/lib/language_server

1 file changed

+7
-1
lines changed

apps/language_server/lib/language_server/parser.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,35 @@ defmodule ElixirLS.LanguageServer.Parser do
123123
state =
124124
update_in(state.debounce_refs[uri], fn
125125
nil ->
126+
# schedule parse with debounce timeout
126127
{Process.send_after(self(), {:parse_file, uri}, @debounce_timeout), current_version}
127128

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
129131
{old_ref, current_version}
130132

131133
{old_ref, old_version} when old_version < current_version ->
134+
# cancel previous parse and schedule new one with debounce timeout
132135
Process.cancel_timer(old_ref, info: false)
133136
{Process.send_after(self(), {:parse_file, uri}, @debounce_timeout), current_version}
134137
end)
135138

136139
state =
137140
update_in(state.files[uri], fn
138141
nil ->
142+
# add new file
139143
%Context{
140144
source_file: source_file,
141145
path: get_path(uri)
142146
}
143147

144148
%Context{source_file: %SourceFile{version: old_version}} = old_file
145149
when current_version > old_version ->
150+
# replace updated file with new version
146151
%Context{old_file | source_file: source_file}
147152

148153
%Context{} = old_file ->
154+
# ignore this request - this or newer version already in state
149155
old_file
150156
end)
151157

0 commit comments

Comments
 (0)