From 7564775fc17a83d1ce86ebdd4043a36a8eb9b139 Mon Sep 17 00:00:00 2001 From: linhongkuan Date: Thu, 25 Jun 2026 10:39:47 +0800 Subject: [PATCH] Handle cross-mount paths in find_parents --- pylsp/_utils.py | 6 +++++- test/test_utils.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pylsp/_utils.py b/pylsp/_utils.py index c9eb6fb1..f7a182bb 100644 --- a/pylsp/_utils.py +++ b/pylsp/_utils.py @@ -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: diff --git a/test/test_utils.py b/test/test_utils.py index 7ed6214f..fcd603ac 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -2,6 +2,7 @@ # Copyright 2021- Python Language Server Contributors. import multiprocessing +import ntpath import os import sys import time @@ -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"}}},