Skip to content

Commit e20bf30

Browse files
authored
Escape Jedi path completions (#762)
1 parent f6df42c commit e20bf30

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pyls/plugins/jedi_completion.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
3+
import os.path as osp
34
import parso
45
from pyls import hookimpl, lsp, _utils
56

@@ -22,6 +23,7 @@
2223
'builtinfunction': lsp.CompletionItemKind.Function,
2324
'module': lsp.CompletionItemKind.Module,
2425
'file': lsp.CompletionItemKind.File,
26+
'path': lsp.CompletionItemKind.Text,
2527
'xrange': lsp.CompletionItemKind.Class,
2628
'slice': lsp.CompletionItemKind.Class,
2729
'traceback': lsp.CompletionItemKind.Class,
@@ -130,6 +132,12 @@ def _format_completion(d, include_params=True):
130132
'insertText': d.name
131133
}
132134

135+
if d.type == 'path':
136+
path = osp.normpath(d.name)
137+
path = path.replace('\\', '\\\\')
138+
path = path.replace('/', '\\/')
139+
completion['insertText'] = path
140+
133141
if (include_params and hasattr(d, 'params') and d.params and
134142
not is_exception_class(d.name)):
135143
positional_args = [param for param in d.params if '=' not in param.description]

0 commit comments

Comments
 (0)