Skip to content

Commit

Permalink
Escape Jedi path completions (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
andfoy authored Mar 18, 2020
1 parent f6df42c commit e20bf30
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pyls/plugins/jedi_completion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
import os.path as osp
import parso
from pyls import hookimpl, lsp, _utils

Expand All @@ -22,6 +23,7 @@
'builtinfunction': lsp.CompletionItemKind.Function,
'module': lsp.CompletionItemKind.Module,
'file': lsp.CompletionItemKind.File,
'path': lsp.CompletionItemKind.Text,
'xrange': lsp.CompletionItemKind.Class,
'slice': lsp.CompletionItemKind.Class,
'traceback': lsp.CompletionItemKind.Class,
Expand Down Expand Up @@ -130,6 +132,12 @@ def _format_completion(d, include_params=True):
'insertText': d.name
}

if d.type == 'path':
path = osp.normpath(d.name)
path = path.replace('\\', '\\\\')
path = path.replace('/', '\\/')
completion['insertText'] = path

if (include_params and hasattr(d, 'params') and d.params and
not is_exception_class(d.name)):
positional_args = [param for param in d.params if '=' not in param.description]
Expand Down

0 comments on commit e20bf30

Please sign in to comment.