Skip to content

Commit

Permalink
Refactor command to take WorkspaceEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Mar 7, 2024
1 parent 3d0ee6a commit 7a66743
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .plugin.documents import DocumentSyncListener
from .plugin.documents import TextChangeListener
from .plugin.edit import LspApplyDocumentEditCommand
from .plugin.edit import LspApplyWorkspaceChangesCommand
from .plugin.edit import LspApplyWorkspaceEditCommand
from .plugin.execute_command import LspExecuteCommand
from .plugin.folding_range import LspFoldAllCommand
from .plugin.folding_range import LspFoldCommand
Expand Down
11 changes: 6 additions & 5 deletions plugin/edit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .core.edit import parse_range
from .core.edit import WorkspaceChanges
from .core.edit import parse_workspace_edit
from .core.logging import debug
from .core.protocol import TextEdit
from .core.protocol import WorkspaceEdit
from .core.registry import LspWindowCommand
from .core.typing import List, Optional, Any, Generator, Iterable, Tuple
from contextlib import contextmanager
Expand All @@ -27,14 +28,14 @@ def temporary_setting(settings: sublime.Settings, key: str, val: Any) -> Generat
settings.set(key, prev_val)


class LspApplyWorkspaceChangesCommand(LspWindowCommand):
class LspApplyWorkspaceEditCommand(LspWindowCommand):

def run(self, session_name: str, workspace_changes: WorkspaceChanges) -> None:
def run(self, session_name: str, edit: WorkspaceEdit) -> None:
session = self.session_by_name(session_name)
if not session:
debug('Could not find session', session_name)
debug('Could not find session', session_name, 'required to apply WorkspaceEdit')
return
session.apply_parsed_workspace_edits(workspace_changes)
session.apply_parsed_workspace_edits(parse_workspace_edit(edit))


class LspApplyDocumentEditCommand(sublime_plugin.TextCommand):
Expand Down
7 changes: 4 additions & 3 deletions plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _on_rename_result_async(self, session: Session, response: Optional[Workspace
if choice == sublime.DIALOG_YES:
session.apply_parsed_workspace_edits(changes)
elif choice == sublime.DIALOG_NO:
self._render_rename_panel(changes, total_changes, file_count, session.config.name)
self._render_rename_panel(response, changes, total_changes, file_count, session.config.name)

def _on_prepare_result(self, pos: int, response: Optional[PrepareRenameResult]) -> None:
if response is None:
Expand Down Expand Up @@ -234,6 +234,7 @@ def _get_relative_path(self, file_path: str) -> str:

def _render_rename_panel(
self,
workspace_edit: WorkspaceEdit,
changes_per_uri: WorkspaceChanges,
total_changes: int,
file_count: int,
Expand Down Expand Up @@ -302,8 +303,8 @@ def _render_rename_panel(
apply=sublime.command_url('chain', {
'commands': [
[
'lsp_apply_workspace_changes',
{'session_name': session_name, 'workspace_changes': changes_per_uri}
'lsp_apply_workspace_edit',
{'session_name': session_name, 'edit': workspace_edit}
],
[
'hide_panel',
Expand Down

0 comments on commit 7a66743

Please sign in to comment.