From f6542bfe0a1a774908df78aa65dd8d60869da9a4 Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Sat, 25 Oct 2025 21:35:23 +0200 Subject: [PATCH] utils: prefer parent uri when matching uri --- pylsp/_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pylsp/_utils.py b/pylsp/_utils.py index dfe84b14..1267fd83 100644 --- a/pylsp/_utils.py +++ b/pylsp/_utils.py @@ -134,9 +134,17 @@ def match_uri_to_workspace(uri, workspaces): if len(workspace_parts) > len(path): continue match_len = 0 + is_parent = True for workspace_part, path_part in zip(workspace_parts, path): if workspace_part == path_part: match_len += 1 + else: + is_parent = False + break + # prefer a match that is actually a parent of uri + # otherwise fall back to longest matching non-parent + if is_parent and match_len > 0: + match_len += 1000 if match_len > 0: if match_len > max_len: max_len = match_len