diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 78e178edc..91cd4070c 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -27,8 +27,9 @@ // "source.organizeImports": true, }, - // The amount of time the code actions on save are allowed to run for. - "code_action_on_save_timeout_ms": 2000, + // The amount of time the save tasks (like code actions on save, + // formatting or WillSaveWaitUntil) are each allowed to run for. + "on_save_task_timeout_ms": 2000, // Open the diagnostics panel automatically on save when diagnostics level is // equal to or less than: diff --git a/plugin/code_actions.py b/plugin/code_actions.py index cb3772fa2..a3a567927 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -235,9 +235,6 @@ def _get_code_actions_on_save(cls, view: sublime.View) -> Dict[str, bool]: allowed_code_actions[key] = value return allowed_code_actions - def get_task_timeout_ms(self) -> int: - return userprefs().code_action_on_save_timeout_ms - def run_async(self) -> None: super().run_async() self._request_code_actions_async() diff --git a/plugin/core/types.py b/plugin/core/types.py index 27d33cf03..49fdd3b58 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -130,7 +130,6 @@ def read_list_setting(settings_obj: sublime.Settings, key: str, default: list) - class Settings: # This is only for mypy - code_action_on_save_timeout_ms = None # type: int diagnostics_additional_delay_auto_complete_ms = None # type: int diagnostics_delay_ms = None # type: int diagnostics_gutter_marker = None # type: str @@ -144,6 +143,7 @@ class Settings: log_server = None # type: List[str] lsp_code_actions_on_save = None # type: Dict[str, bool] lsp_format_on_save = None # type: bool + on_save_task_timeout_ms = None # type: int only_show_lsp_completions = None # type: bool popup_max_characters_height = None # type: int popup_max_characters_width = None # type: int @@ -167,7 +167,6 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None: val = s.get(name) setattr(self, name, val if isinstance(val, default.__class__) else default) - r("code_action_on_save_timeout_ms", 2000) r("diagnostics_additional_delay_auto_complete_ms", 0) r("diagnostics_delay_ms", 0) r("diagnostics_gutter_marker", "dot") @@ -178,6 +177,7 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None: r("log_max_size", 8 * 1024) r("lsp_code_actions_on_save", {}) r("lsp_format_on_save", False) + r("on_save_task_timeout_ms", 2000) r("only_show_lsp_completions", False) r("popup_max_characters_height", 1000) r("popup_max_characters_width", 120) @@ -225,6 +225,11 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None: if not diagnostics_highlight_style: self.show_diagnostics_highlights = False + # Backwards-compatible with "code_action_on_save_timeout_ms" + code_action_on_save_timeout_ms = s.get("code_action_on_save_timeout_ms") + if isinstance(code_action_on_save_timeout_ms, int): + self.on_save_task_timeout_ms = code_action_on_save_timeout_ms + set_debug_logging(self.log_debug) def document_highlight_style_region_flags(self) -> Tuple[int, int]: diff --git a/plugin/save_command.py b/plugin/save_command.py index 0b498aa74..3e01f88f3 100644 --- a/plugin/save_command.py +++ b/plugin/save_command.py @@ -1,4 +1,5 @@ from .core.registry import LspTextCommand +from .core.settings import userprefs from .core.typing import Callable, List, Type from abc import ABCMeta, abstractmethod import sublime @@ -12,8 +13,6 @@ class SaveTask(metaclass=ABCMeta): Note: The whole task runs on the async thread. """ - DEFAULT_TASK_TIMEOUT = 1000 - @classmethod @abstractmethod def is_applicable(cls, view: sublime.View) -> bool: @@ -28,7 +27,7 @@ def __init__(self, task_runner: LspTextCommand, on_done: Callable[[], None]): def run_async(self) -> None: self._erase_view_status() - sublime.set_timeout_async(self._on_timeout, self.get_task_timeout_ms()) + sublime.set_timeout_async(self._on_timeout, userprefs().on_save_task_timeout_ms) def _on_timeout(self) -> None: if not self._completed and not self._cancelled: @@ -36,9 +35,6 @@ def _on_timeout(self) -> None: self._cancelled = True self._on_done() - def get_task_timeout_ms(self) -> int: - return self.DEFAULT_TASK_TIMEOUT - def cancel(self) -> None: self._cancelled = True diff --git a/sublime-package.json b/sublime-package.json index b7323f8b3..53f1be2a8 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -185,7 +185,12 @@ "code_action_on_save_timeout_ms": { "type": "integer", "default": 2000, - "markdownDescription": "The amount of time the code actions on save are allowed to run for." + "deprecationMessage": "Use the \"on_save_task_timeout_ms\" setting instead." + }, + "on_save_task_timeout_ms": { + "type": "integer", + "default": 2000, + "markdownDescription": "The amount of time the save tasks (like code actions on save, formatting or WillSaveWaitUntil) are each allowed to run for." }, "show_diagnostics_panel_on_save": { "type": "integer",