LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Add setting to disable global rename confirmation prompt

Open jonpalmisc opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. I've been doing a lot of refactoring lately and have found the "Rename N occurrences across N files" prompt to be very annoying.

Describe the solution you'd like It would be nice to be able to disable this prompt via a setting.

Describe alternatives you've considered I have considered trying to be more accepting of the dialog. It is trying its best.

Additional context N/A

jonpalmisc avatar Dec 24 '21 23:12 jonpalmisc

I've actually tried adding this myself before filing this issue and I hit a wall — any guidance is welcome and I'll happily submit a PR to address this.

I uninstalled LSP package via package control then cloned the repo into my packages folder with Git. I made these changes, which I expected to be sufficient:

diff --git a/LSP.sublime-settings b/LSP.sublime-settings
index 5903f32..869f714 100644
--- a/LSP.sublime-settings
+++ b/LSP.sublime-settings
@@ -10,6 +10,9 @@
   // "settings" section of project files.
   "lsp_format_on_save": false,
 
+  // Confirm rename operations that will affect more than one file.
+  "confirm_global_rename": true,
+
   // A dictionary of code action identifiers that should be triggered on save.
   //
   // Code action identifiers are not officially standardized so refer to specific
diff --git a/plugin/rename.py b/plugin/rename.py
index 39ed5ad..75c4ae8 100644
--- a/plugin/rename.py
+++ b/plugin/rename.py
@@ -122,11 +122,12 @@ class LspSymbolRenameCommand(LspTextCommand):
 
     def on_rename_result(self, response: Any) -> None:
         window = self.view.window()
+        settings = self.view.settings()
         if window:
             if response:
                 changes = parse_workspace_edit(response)
                 file_count = len(changes.keys())
-                if file_count > 1:
+                if file_count > 1 and settings.get('confirm_global_rename'):
                     total_changes = sum(map(len, changes.values()))
                     message = "Replace {} occurrences across {} files?".format(total_changes, file_count)
                     choice = sublime.yes_no_cancel_dialog(message, "Replace", "Dry Run")

There's probably something I'm missing here, but after editing my LSP settings to include "confirm_global_rename": false, I still get the warning prompt.

jonpalmisc avatar Dec 24 '21 23:12 jonpalmisc

Your diff doesn't work because the setting value is set in the LSP.sublime-settings file, but later you try to read it from the settings of the current view. It should work like this (untested):

diff --git a/LSP.sublime-settings b/LSP.sublime-settings
index 5903f32..869f714 100644
--- a/LSP.sublime-settings
+++ b/LSP.sublime-settings
@@ -10,6 +10,9 @@
   // "settings" section of project files.
   "lsp_format_on_save": false,
 
+  // Confirm rename operations that will affect more than one file.
+  "confirm_global_rename": true,
+
   // A dictionary of code action identifiers that should be triggered on save.
   //
   // Code action identifiers are not officially standardized so refer to specific
diff --git a/plugin/core/types.py b/plugin/core/types.py
index 0963bc6..1a1d195 100644
--- a/plugin/core/types.py
+++ b/plugin/core/types.py
@@ -184,6 +184,7 @@ def read_list_setting(settings_obj: sublime.Settings, key: str, default: list) -
 class Settings:
 
     # This is only for mypy
+    confirm_global_rename = None  # type: bool
     diagnostics_additional_delay_auto_complete_ms = None  # type: int
     diagnostics_delay_ms = None  # type: int
     diagnostics_gutter_marker = None  # type: str
@@ -223,6 +224,7 @@ class Settings:
             val = s.get(name)
             setattr(self, name, val if isinstance(val, default.__class__) else default)
 
+        r("confirm_global_rename", True)
         r("diagnostics_additional_delay_auto_complete_ms", 0)
         r("diagnostics_delay_ms", 0)
         r("diagnostics_gutter_marker", "dot")
diff --git a/plugin/rename.py b/plugin/rename.py
index 39ed5ad..17a0de6 100644
--- a/plugin/rename.py
+++ b/plugin/rename.py
@@ -8,6 +8,7 @@ from .core.protocol import Request
 from .core.registry import get_position
 from .core.registry import LspTextCommand
 from .core.registry import windows
+from .core.settings import userprefs
 from .core.types import PANEL_FILE_REGEX, PANEL_LINE_REGEX
 from .core.typing import Any, Optional, Dict, List
 from .core.views import first_selection_region, range_to_region, get_line
@@ -126,7 +127,7 @@ class LspSymbolRenameCommand(LspTextCommand):
             if response:
                 changes = parse_workspace_edit(response)
                 file_count = len(changes.keys())
-                if file_count > 1:
+                if file_count > 1 and userprefs().confirm_global_rename:
                     total_changes = sum(map(len, changes.values()))
                     message = "Replace {} occurrences across {} files?".format(total_changes, file_count)
                     choice = sublime.yes_no_cancel_dialog(message, "Replace", "Dry Run")

jwortmann avatar Dec 24 '21 23:12 jwortmann

Your suggestion worked perfectly; thank you for the guidance @jwortmann.

jonpalmisc avatar Dec 25 '21 01:12 jonpalmisc