Ejemplo n.º 1
0
 def _apply_auto_complete_triggers(
     self,
     settings: sublime.Settings,
     trigger_chars: List[str],
     registration_id: Optional[str] = None
 ) -> None:
     """This method actually modifies the auto_complete_triggers entries for the view."""
     if not userprefs().register_trigger_chars:
         return
     selector = self.session.config.auto_complete_selector
     if not selector:
         # If the user did not set up an auto_complete_selector for this server configuration, fallback to the
         # "global" auto_complete_selector of the view.
         selector = str(settings.get("auto_complete_selector"))
     trigger = {
         "selector": selector,
         # This key is not used by Sublime, but is used as a "breadcrumb" to figure out what needs to be removed
         # from the auto_complete_triggers array once the session is stopped.
         "server": self.session.config.name
     }
     if trigger_chars:
         trigger["characters"] = "".join(trigger_chars)
     if isinstance(registration_id, str):
         # This key is not used by Sublime, but is used as a "breadcrumb" as well, for dynamic registrations.
         trigger["registration_id"] = registration_id
     triggers = settings.get(self.AC_TRIGGERS_KEY) or []  # type: List[Dict[str, str]]
     triggers.append(trigger)
     settings.set(self.AC_TRIGGERS_KEY, triggers)
Ejemplo n.º 2
0
def temporary_setting(settings: sublime.Settings, key: str, val: Any) -> Generator[None, None, None]:
    prev_val = None
    has_prev_val = settings.has(key)
    if has_prev_val:
        prev_val = settings.get(key)
    settings.set(key, val)
    yield
    settings.erase(key)
    if has_prev_val and settings.get(key) != prev_val:
        settings.set(key, prev_val)
Ejemplo n.º 3
0
    def _migrate_obsolete_settings(self, settings: sublime.Settings):
        """
        Migrates setting with a root `client` key to flattened structure.
        Receives a `sublime.Settings` object.

        Returns True if settings were migrated.
        """
        client = settings.get('client')  # type: Dict
        if client:
            settings.erase('client')
            # Migrate old keys
            for key, value in client.items():
                settings.set(key, value)
            return True
        return False
Ejemplo n.º 4
0
 def on_settings_read_internal(cls, settings: sublime.Settings) -> None:
     languages = settings.get('languages', None)  # type: Optional[List[LanguagesDict]]
     if languages:
         settings.set('languages', cls._upgrade_languages_list(languages))
Ejemplo n.º 5
0
 def _clear_auto_complete_triggers(self, settings: sublime.Settings) -> None:
     '''Remove all of our modifications to the view's "auto_complete_triggers"'''
     triggers = settings.get(self.AC_TRIGGERS_KEY)
     if isinstance(triggers, list):
         triggers = [t for t in triggers if self.session.config.name != t.get("server", "")]
         settings.set(self.AC_TRIGGERS_KEY, triggers)