Skip to content

Commit f6542bf

Browse files
committed
utils: prefer parent uri when matching uri
1 parent 89265cd commit f6542bf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pylsp/_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,17 @@ def match_uri_to_workspace(uri, workspaces):
134134
if len(workspace_parts) > len(path):
135135
continue
136136
match_len = 0
137+
is_parent = True
137138
for workspace_part, path_part in zip(workspace_parts, path):
138139
if workspace_part == path_part:
139140
match_len += 1
141+
else:
142+
is_parent = False
143+
break
144+
# prefer a match that is actually a parent of uri
145+
# otherwise fall back to longest matching non-parent
146+
if is_parent and match_len > 0:
147+
match_len += 1000
140148
if match_len > 0:
141149
if match_len > max_len:
142150
max_len = match_len

0 commit comments

Comments
 (0)