Skip to content

Commit

Permalink
Workaround for bug in urllib
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Nov 11, 2023
1 parent 301d0cc commit 0fe2350
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugin/core/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .logging import printf
from .types import ClientConfig
from .typing import Generator, List, Optional, Set, Dict, Deque
from .url import parse_uri
from .workspace import enable_in_project, disable_in_project
from abc import ABCMeta
from abc import abstractmethod
Expand Down Expand Up @@ -51,7 +52,7 @@ def match_view(self, view: sublime.View, include_disabled: bool = False) -> Gene
uri = view.settings().get("lsp_uri")
if not isinstance(uri, str):
return
scheme = urllib.parse.urlparse(uri).scheme
scheme = parse_uri(uri)[0]
for config in self.all.values():
if config.match_view(view, scheme) and (config.enabled or include_disabled):
yield config
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def __call__(self, view: sublime.View) -> bool:
return False
if self.scheme:
uri = view.settings().get("lsp_uri")
if isinstance(uri, str) and urllib.parse.urlparse(uri).scheme != self.scheme:
if isinstance(uri, str) and parse_uri(uri)[0] != self.scheme:
return False
if self.pattern:
if not globmatch(view.file_name() or "", self.pattern, flags=GLOBSTAR | BRACE):
Expand Down
3 changes: 3 additions & 0 deletions plugin/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def parse_uri(uri: str) -> Tuple[str, str]:
else:
return parsed.scheme, path
return parsed.scheme, path
elif parsed.scheme == '' and ':' in parsed.path:
# workaround for bug in urllib.parse.urlparse
return parsed.path.split(':')[0], uri
return parsed.scheme, uri


Expand Down
4 changes: 2 additions & 2 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _dequeue_listener_async(self) -> None:

def _publish_sessions_to_listener_async(self, listener: AbstractViewListener) -> None:
inside_workspace = self._workspace.contains(listener.view)
scheme = urllib.parse.urlparse(listener.get_uri()).scheme
scheme = parse_uri(listener.get_uri())[0]
for session in self._sessions:
if session.can_handle(listener.view, scheme, capability=None, inside_workspace=inside_workspace):
# debug("registering session", session.config.name, "to listener", listener)
Expand All @@ -200,7 +200,7 @@ def sessions(self, view: sublime.View, capability: Optional[str] = None) -> Gene
uri = view.settings().get("lsp_uri")
if not isinstance(uri, str):
return
scheme = urllib.parse.urlparse(uri).scheme
scheme = parse_uri(uri)[0]
for session in sessions:
if session.can_handle(view, scheme, capability, inside_workspace):
yield session
Expand Down
2 changes: 1 addition & 1 deletion plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def on_select(targets: List[str], idx: int) -> None:
position = {"line": row, "character": col_utf16} # type: Position
r = {"start": position, "end": position} # type: Range
sublime.set_timeout_async(partial(session.open_uri_async, uri, r))
elif urlparse(href).scheme.lower() not in ("", "http", "https"):
elif parse_uri(href)[0].lower() not in ("", "http", "https"):
sublime.set_timeout_async(partial(self.try_open_custom_uri_async, href))
else:
open_in_browser(href)
Expand Down

0 comments on commit 0fe2350

Please sign in to comment.