Skip to content
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
6 changes: 5 additions & 1 deletion pylsp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def find_parents(root, path, names):
# Split the relative by directory, generate all the parent directories, then check each of them.
# This avoids running a loop that has different base-cases for unix/windows
# e.g. /a/b and /a/b/c/d/e.py -> ['/a/b', 'c', 'd']
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
try:
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
except ValueError:
log.warning("Path %r not in %r", path, root)
return []

# Search each of /a/b/c, /a/b, /a
while dirs:
Expand Down
14 changes: 14 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2021- Python Language Server Contributors.

import multiprocessing
import ntpath
import os
import sys
import time
Expand Down Expand Up @@ -197,6 +198,19 @@ def test_find_parents(tmpdir) -> None:
]


def test_find_parents_handles_cross_mount_paths(monkeypatch) -> None:
monkeypatch.setattr(_utils.os, "path", ntpath)

assert (
_utils.find_parents(
r"\\server\share1",
r"\\server\share2\path.py",
["test.cfg"],
)
== []
)


def test_merge_dicts() -> None:
assert _utils.merge_dicts(
{"a": True, "b": {"x": 123, "y": {"hello": "world"}}},
Expand Down