Repository: sublimelsp/LSP

Issue:
Error in console for res: URIs and diagnostics don't work
**Describe the bug**

Looks like the logic for non-file URIs doesn't work yet:
```
Error handling notification
Traceback (most recent call last):
  File "C:\Users\jwortmann\AppData\Roaming\Sublime Text\Packages\LSP\plugin\core\sessions.py", line 1506, in on_payload
    handler(result)
  File "C:\Users\jwortmann\AppData\Roaming\Sublime Text\Packages\LSP\plugin\core\sessions.py", line 1242, in m_textDocument_publishDiagnostics
    sb = self.get_session_buffer_for_uri_async(uri)
  File "C:\Users\jwortmann\AppData\Roaming\Sublime Text\Packages\LSP\plugin\core\sessions.py", line 949, in get_session_buffer_for_uri_async
    return next(filter(predicate, self.session_buffers_async()), None)
  File "C:\Users\jwortmann\AppData\Roaming\Sublime Text\Packages\LSP\plugin\core\sessions.py", line 940, in compare_by_samefile
    return os.path.samefile(parsed, candidate_path)
  File "./python3.3/ntpath.py", line 603, in samefile
OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: 'res://Packages%5CDefault%5Csymbol.py'
```

In the `compare_by_samefile` function, `parsed` is `"."` here, `candidate_isfile` is `"res"` (so it evaluates to "true") and `candidate_path` is `"res://Packages%5CDefault%5Csymbol.py"`.

**To Reproduce**
1. Open the command palette, choose "View Package File" and open a file from a .sublime-package, for example *Default/symbol.py*

**Expected behavior**
No error in console, diagnostics should work.

**Environment (please complete the following information):**
- OS: Windows 10
- Sublime Text version: 4107
- LSP version: 615e110
- Language servers used: LSP-pyright

**Additional information**

`os.path.samefile` needs the given paths to be existing files on disk and otherwise throws an error


Discussion:

Resolving patch:
diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py
--- a/plugin/core/sessions.py
+++ b/plugin/core/sessions.py
@@ -927,6 +927,9 @@ def session_buffers_async(self) -> Generator[SessionBufferProtocol, None, None]:
     def get_session_buffer_for_uri_async(self, uri: DocumentUri) -> Optional[SessionBufferProtocol]:
         scheme, parsed = parse_uri(uri)
         if scheme == "file":
+            if not os.path.exists(parsed):
+                debug("{}: path does not exist:".format(self.config.name), uri)
+                return None
 
             def compare_by_samefile(sb: Optional[SessionBufferProtocol]) -> bool:
                 if not sb:
@@ -934,10 +937,8 @@ def compare_by_samefile(sb: Optional[SessionBufferProtocol]) -> bool:
                 candidate = sb.get_uri()
                 if not isinstance(candidate, str):
                     return False
-                candidate_isfile, candidate_path = parse_uri(candidate)
-                if not candidate_isfile:
-                    return False
-                return os.path.samefile(parsed, candidate_path)
+                candidate_scheme, candidate_path = parse_uri(candidate)
+                return candidate_scheme == "file" and os.path.samefile(parsed, candidate_path)
 
             predicate = compare_by_samefile
         else:


Test patch: