Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make path separator escape configurable (#373) #611

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This server can be configured using the `workspace/didChangeConfiguration` metho
| `pylsp.plugins.jedi.env_vars` | `object` | Define environment variables for jedi.Script and Jedi.names. | `null` |
| `pylsp.plugins.jedi.environment` | `string` | Define environment for jedi.Script and Jedi.names. | `null` |
| `pylsp.plugins.jedi_completion.enabled` | `boolean` | Enable or disable the plugin. | `true` |
| `pylsp.plugins.jedi_completion.escape_path_sep` | `boolean` | Force path separators to be escaped in file path completions. | `true` |
| `pylsp.plugins.jedi_completion.include_params` | `boolean` | Auto-completes methods and classes with tabstops for each parameter. | `true` |
| `pylsp.plugins.jedi_completion.include_class_objects` | `boolean` | Adds class objects as a separate completion item. | `false` |
| `pylsp.plugins.jedi_completion.include_function_objects` | `boolean` | Adds function objects as a separate completion item. | `false` |
Expand Down
12 changes: 7 additions & 5 deletions pylsp/plugins/jedi_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ def pylsp_completions(config, document, position):
and use_snippets(document, position)
)

escape_path_sep = settings.get("escape_path_sep", snippet_support)

ready_completions = [
_format_completion(
c,
markup_kind=preferred_markup_kind,
include_params=include_params if c.type in ["class", "function"] else False,
resolve=resolve_eagerly,
resolve_label_or_snippet=(i < max_to_resolve),
snippet_support=snippet_support,
escape_path_sep=escape_path_sep,
)
for i, c in enumerate(completions)
]
Expand All @@ -102,7 +104,7 @@ def pylsp_completions(config, document, position):
include_params=False,
resolve=resolve_eagerly,
resolve_label_or_snippet=(i < max_to_resolve),
snippet_support=snippet_support,
escape_path_sep=escape_path_sep,
)
completion_dict["kind"] = lsp.CompletionItemKind.TypeParameter
completion_dict["label"] += " object"
Expand All @@ -117,7 +119,7 @@ def pylsp_completions(config, document, position):
include_params=False,
resolve=resolve_eagerly,
resolve_label_or_snippet=(i < max_to_resolve),
snippet_support=snippet_support,
escape_path_sep=escape_path_sep,
)
completion_dict["kind"] = lsp.CompletionItemKind.TypeParameter
completion_dict["label"] += " object"
Expand Down Expand Up @@ -227,7 +229,7 @@ def _format_completion(
include_params=True,
resolve=False,
resolve_label_or_snippet=False,
snippet_support=False,
escape_path_sep=False,
):
completion = {
"label": _label(d, resolve_label_or_snippet),
Expand All @@ -253,7 +255,7 @@ def _format_completion(

# Escape to prevent conflicts with the code snippets grammer
# See also https://github.com/python-lsp/python-lsp-server/issues/373
if snippet_support:
if escape_path_sep:
path = path.replace("\\", "\\\\")
path = path.replace("/", "\\/")

Expand Down