Skip to content

Commit

Permalink
Rename code_action_on_save_timeout_ms to on_save_task_timeout_ms (#1728)
Browse files Browse the repository at this point in the history
Make it apply to all save tasks.

Resolves #1719
  • Loading branch information
rchl authored Jun 8, 2021
1 parent 9e748e3 commit 1c125bd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 3 additions & 2 deletions LSP.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions plugin/code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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]:
Expand Down
8 changes: 2 additions & 6 deletions plugin/save_command.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -28,17 +27,14 @@ 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:
self._set_view_status('LSP: Timeout processing {}'.format(self.__class__.__name__))
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

Expand Down
7 changes: 6 additions & 1 deletion sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1c125bd

Please sign in to comment.