@@ -88,6 +88,7 @@ def pylsp_completions(config, document, position):
88
88
include_params = include_params if c .type in ["class" , "function" ] else False ,
89
89
resolve = resolve_eagerly ,
90
90
resolve_label_or_snippet = (i < max_to_resolve ),
91
+ snippet_support = snippet_support ,
91
92
)
92
93
for i , c in enumerate (completions )
93
94
]
@@ -102,6 +103,7 @@ def pylsp_completions(config, document, position):
102
103
include_params = False ,
103
104
resolve = resolve_eagerly ,
104
105
resolve_label_or_snippet = (i < max_to_resolve ),
106
+ snippet_support = snippet_support ,
105
107
)
106
108
completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
107
109
completion_dict ["label" ] += " object"
@@ -116,6 +118,7 @@ def pylsp_completions(config, document, position):
116
118
include_params = False ,
117
119
resolve = resolve_eagerly ,
118
120
resolve_label_or_snippet = (i < max_to_resolve ),
121
+ snippet_support = snippet_support ,
119
122
)
120
123
completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
121
124
completion_dict ["label" ] += " object"
@@ -226,6 +229,7 @@ def _format_completion(
226
229
include_params = True ,
227
230
resolve = False ,
228
231
resolve_label_or_snippet = False ,
232
+ snippet_support = False ,
229
233
):
230
234
completion = {
231
235
"label" : _label (d , resolve_label_or_snippet ),
@@ -240,16 +244,20 @@ def _format_completion(
240
244
# Adjustments for file completions
241
245
if d .type == "path" :
242
246
path = os .path .normpath (d .name )
243
- path = path .replace ("\\ " , "\\ \\ " )
244
- path = path .replace ("/" , "\\ /" )
245
247
246
- # If the completion ends with os.sep, it means it's a directory. So we add an escaped os.sep
247
- # at the end to ease additional file completions.
248
+ # If the completion ends with os.sep, it means it's a directory. So we add os.sep at the end
249
+ # to ease additional file completions.
248
250
if d .name .endswith (os .sep ):
249
251
if os .name == "nt" :
250
- path = path + "\\ \\ "
252
+ path = path + "\\ "
251
253
else :
252
- path = path + "\\ /"
254
+ path = path + "/"
255
+
256
+ # Escape to prevent conflicts with the code snippets grammer
257
+ # See also https://github.com/python-lsp/python-lsp-server/issues/373
258
+ if snippet_support :
259
+ path = path .replace ("\\ " , "\\ \\ " )
260
+ path = path .replace ("/" , "\\ /" )
253
261
254
262
completion ["insertText" ] = path
255
263
0 commit comments