Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even more fixes for matching up buffers with URIs #1782

Merged
merged 4 commits into from
Jul 5, 2021
Merged
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
15 changes: 10 additions & 5 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,8 @@ def session_buffers_async(self) -> Generator[SessionBufferProtocol, None, None]:
yield from self._session_buffers

def get_session_buffer_for_uri_async(self, uri: DocumentUri) -> Optional[SessionBufferProtocol]:
scheme, parsed = parse_uri(uri)
scheme, path = parse_uri(uri)
if scheme == "file":
if not os.path.exists(parsed):
return None

def compare_by_samefile(sb: Optional[SessionBufferProtocol]) -> bool:
if not sb:
Expand All @@ -938,13 +936,20 @@ def compare_by_samefile(sb: Optional[SessionBufferProtocol]) -> bool:
if not isinstance(candidate, str):
return False
candidate_scheme, candidate_path = parse_uri(candidate)
return candidate_scheme == "file" and os.path.samefile(parsed, candidate_path)
if candidate_scheme != "file":
return False
if path == candidate_path:
return True
try:
return os.path.samefile(path, candidate_path)
except FileNotFoundError:
return False

predicate = compare_by_samefile
else:

def compare_by_string(sb: Optional[SessionBufferProtocol]) -> bool:
return sb.get_uri() == parsed if sb else False
return sb.get_uri() == path if sb else False

predicate = compare_by_string
return next(filter(predicate, self.session_buffers_async()), None)
Expand Down