refactor(command-system): replace legacy CommandSystem with SourceViewCommandSystem
- Remove CommandSystem and CommandSystemMixin - Introduce SourceViewCommandSystem and shared libs/command_system - Update CommandsController to use new command system - Adjust package exports accordingly feat(lsp): clean up and normalize LSP configurations - Fix invalid JSON in Godot LSP config (processId -> null, formatting) - Remove embedded jedi-language-server config from main Python LSP config - Add separate jedi-lsp-server-config.json refactor(markers): rename move_word -> move_along_word for clarity - Update all usages in MarkerManager chore: minor formatting and whitespace fixes
This commit is contained in:
50
src/libs/command_system.py
Normal file
50
src/libs/command_system.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# Python imports
|
||||
import types
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from .event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
|
||||
|
||||
class CommandSystem:
|
||||
def __init__(self, commands: dict | types.ModuleType):
|
||||
super(CommandSystem, self).__init__()
|
||||
|
||||
self.commands: dict | types.ModuleType = commands
|
||||
self.data: tuple = ()
|
||||
|
||||
|
||||
def set_data(self, *args, **kwargs):
|
||||
self.data = (args, kwargs)
|
||||
|
||||
def exec(self, command: str) -> any:
|
||||
"""
|
||||
The 'exec' method passes the default 'self.data' to commands where custom args are not needed.
|
||||
Ex: The 'code' widget has many internally created commands that
|
||||
only need 'source_view' and so 'set_data' is called to set that.
|
||||
"""
|
||||
if not hasattr(self.commands, command): return
|
||||
method = getattr(self.commands, command)
|
||||
|
||||
args, kwargs = self.data
|
||||
return method.execute(*args, **kwargs)
|
||||
|
||||
def exec_with_args(self, command: str, *args, **kwargs) -> any:
|
||||
"""
|
||||
The 'exec_with_args' method passes custom args with the understanding
|
||||
that the recipient has proper method signature to accept it- whether
|
||||
*args or **kwargs or something else entirely.
|
||||
"""
|
||||
if not hasattr(self.commands, command): return
|
||||
|
||||
method = getattr(self.commands, command)
|
||||
return method.execute(*args, **kwargs)
|
||||
|
||||
def add_command(self, command_name: str, command: callable):
|
||||
setattr(self.commands, command_name, command)
|
||||
|
||||
def remove_command(self, command_name: str, command: callable):
|
||||
if hasattr(self.commands, command_name):
|
||||
delattr(self.commands, command_name)
|
||||
Reference in New Issue
Block a user