@@ -153,18 +153,22 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
153
153
end
154
154
155
155
def_before =
156
- cond do
157
- Regex . match? ( ~r/ (defdelegate|defp?)\s *#{ Regex . escape ( prefix ) } $/ u , text_before_cursor ) ->
158
- :def
159
-
160
- Regex . match? (
161
- ~r/ (defguardp?|defmacrop?)\s *#{ Regex . escape ( prefix ) } $/ u ,
162
- text_before_cursor
163
- ) ->
164
- :defmacro
165
-
166
- true ->
167
- nil
156
+ try do
157
+ cond do
158
+ Regex . match? ( ~r/ (defdelegate|defp?)\s *#{ Regex . escape ( prefix ) } $/ u , text_before_cursor ) ->
159
+ :def
160
+
161
+ Regex . match? (
162
+ ~r/ (defguardp?|defmacrop?)\s *#{ Regex . escape ( prefix ) } $/ u ,
163
+ text_before_cursor
164
+ ) ->
165
+ :defmacro
166
+
167
+ true ->
168
+ nil
169
+ end
170
+ rescue
171
+ Regex.CompileError -> nil
168
172
end
169
173
170
174
container_cursor_quoted =
@@ -221,15 +225,29 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
221
225
222
226
line_indent = String . length ( line_text ) - String . length ( String . trim_leading ( line_text ) )
223
227
228
+ pipe_before? =
229
+ try do
230
+ Regex . match? ( ~r/ \| >\s *#{ Regex . escape ( prefix ) } $/ u , text_before_cursor )
231
+ rescue
232
+ Regex.CompileError -> false
233
+ end
234
+
235
+ capture_before? =
236
+ try do
237
+ Regex . match? ( ~r/ &#{ Regex . escape ( prefix ) } $/ u , text_before_cursor )
238
+ rescue
239
+ Regex.CompileError -> false
240
+ end
241
+
224
242
context = % {
225
243
container_cursor_to_quoted: container_cursor_quoted ,
226
244
text_before_cursor: text_before_cursor ,
227
245
text_after_cursor: text_after_cursor ,
228
246
prefix: prefix ,
229
247
remote_calls?: match? ( { :dot , _ , _ } , NormalizedCode.Fragment . cursor_context ( prefix ) ) ,
230
248
def_before: def_before ,
231
- pipe_before?: Regex . match? ( ~r / \| > \s * #{ Regex . escape ( prefix ) } $ / u , text_before_cursor ) ,
232
- capture_before?: Regex . match? ( ~r / & #{ Regex . escape ( prefix ) } $ / u , text_before_cursor ) ,
249
+ pipe_before?: pipe_before? ,
250
+ capture_before?: capture_before? ,
233
251
scope: scope ,
234
252
module: env . module ,
235
253
line: line ,
0 commit comments