Skip to content

Commit edce2fc

Browse files
committed
utils: prefer parent uri when matching uri
1 parent bc1095f commit edce2fc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pylsp/_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import docstring_to_markdown
1717
import jedi
1818

19+
from pylsp import IS_WIN
20+
1921
JEDI_VERSION = jedi.__version__
2022

2123
# Eol chars accepted by the LSP protocol
@@ -134,9 +136,23 @@ def match_uri_to_workspace(uri, workspaces):
134136
if len(workspace_parts) > len(path):
135137
continue
136138
match_len = 0
139+
is_parent = True
137140
for workspace_part, path_part in zip(workspace_parts, path):
141+
# filename match is case insensitive on windows
142+
# also, uris._normalize_win_path() lowercases the drive letter
143+
if IS_WIN:
144+
workspace_part = workspace_part.lower()
145+
path_part = path_part.lower()
138146
if workspace_part == path_part:
139147
match_len += 1
148+
else:
149+
# give up, any subsequent match is no longer relevant
150+
is_parent = False
151+
break
152+
# prefer a match that is actually a parent of uri
153+
# otherwise fall back to longest matching non-parent
154+
if is_parent and match_len > 0:
155+
match_len += 1000
140156
if match_len > 0:
141157
if match_len > max_len:
142158
max_len = match_len

0 commit comments

Comments
 (0)