Skip to content

Commit

Permalink
no need for a global map!
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols committed Jun 22, 2021
1 parent f120b1c commit 63c3668
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
11 changes: 3 additions & 8 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,6 @@ def on_session_end_async(self) -> None:


_plugins = {} # type: Dict[str, Tuple[Type[AbstractPlugin], SettingsRegistration]]
_pending_uris_to_set = {} # type: Dict[str, DocumentUri]


def get_possible_uri_to_set(title: str) -> Optional[str]:
global _pending_uris_to_set
return _pending_uris_to_set.get(title)


def _register_plugin_impl(plugin: Type[AbstractPlugin], notify_listener: bool) -> None:
Expand Down Expand Up @@ -1138,9 +1132,10 @@ def open_uri_async(
result = Promise.packaged_task() # type: PackagedTask[bool]

def open_scratch_buffer(title: str, content: str, syntax: str) -> None:
global _pending_uris_to_set
_pending_uris_to_set[title] = uri
v = self.window.new_file(syntax=syntax, flags=flags)
# Note: the __init__ of ViewEventListeners is invoked in the next UI frame, so we can fill in the
# settings object here at our leisure.
v.settings().set("lsp_uri", uri)
v.set_scratch(True)
v.set_name(title)
v.run_command("append", {"characters": content})
Expand Down
6 changes: 2 additions & 4 deletions plugin/core/url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .typing import Any, Optional
from .typing import Any
from urllib.parse import quote
from urllib.parse import urljoin
from urllib.parse import urlparse
Expand All @@ -25,9 +25,7 @@ def filename_to_uri(file_name: str) -> str:
return urljoin("file:", path)


def view_to_uri(view: sublime.View, foreign_uri: Optional[str] = None) -> str:
if isinstance(foreign_uri, str):
return foreign_uri
def view_to_uri(view: sublime.View) -> str:
file_name = view.file_name()
if not file_name:
return "buffer://sublime/{}".format(view.buffer_id())
Expand Down
7 changes: 5 additions & 2 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .core.protocol import SignatureHelp
from .core.registry import best_session
from .core.registry import windows
from .core.sessions import get_possible_uri_to_set
from .core.sessions import Session
from .core.settings import userprefs
from .core.signature_help import SigHelp
Expand Down Expand Up @@ -154,7 +153,11 @@ def on_change() -> None:
this._on_settings_object_changed()

self._current_syntax = None
self.set_uri(view_to_uri(view, get_possible_uri_to_set(view.name())))
foreign_uri = view.settings().get("lsp_uri")
if isinstance(foreign_uri, str):
self._uri = foreign_uri
else:
self.set_uri(view_to_uri(view))
self._registration = SettingsRegistration(view.settings(), on_change=on_change)
self._setup()

Expand Down

0 comments on commit 63c3668

Please sign in to comment.