@@ -88,6 +88,7 @@ def pylsp_completions(config, document, position):
8888 include_params = include_params if c .type in ["class" , "function" ] else False ,
8989 resolve = resolve_eagerly ,
9090 resolve_label_or_snippet = (i < max_to_resolve ),
91+ snippet_support = snippet_support ,
9192 )
9293 for i , c in enumerate (completions )
9394 ]
@@ -102,6 +103,7 @@ def pylsp_completions(config, document, position):
102103 include_params = False ,
103104 resolve = resolve_eagerly ,
104105 resolve_label_or_snippet = (i < max_to_resolve ),
106+ snippet_support = snippet_support ,
105107 )
106108 completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
107109 completion_dict ["label" ] += " object"
@@ -116,6 +118,7 @@ def pylsp_completions(config, document, position):
116118 include_params = False ,
117119 resolve = resolve_eagerly ,
118120 resolve_label_or_snippet = (i < max_to_resolve ),
121+ snippet_support = snippet_support ,
119122 )
120123 completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
121124 completion_dict ["label" ] += " object"
@@ -226,6 +229,7 @@ def _format_completion(
226229 include_params = True ,
227230 resolve = False ,
228231 resolve_label_or_snippet = False ,
232+ snippet_support = False ,
229233):
230234 completion = {
231235 "label" : _label (d , resolve_label_or_snippet ),
@@ -240,16 +244,20 @@ def _format_completion(
240244 # Adjustments for file completions
241245 if d .type == "path" :
242246 path = os .path .normpath (d .name )
243- path = path .replace ("\\ " , "\\ \\ " )
244- path = path .replace ("/" , "\\ /" )
245247
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.
248250 if d .name .endswith (os .sep ):
249251 if os .name == "nt" :
250- path = path + "\\ \\ "
252+ path = path + "\\ "
251253 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 ("/" , "\\ /" )
253261
254262 completion ["insertText" ] = path
255263
0 commit comments