From b13d9c239733c6439dc4c9159291e6902e3cec2c Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 4 Apr 2026 14:21:58 -0500 Subject: [PATCH] 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 --- .../config/jedi-lsp-server-config.json | 100 +++++++++++++++ .../config/lsp-server-config.json | 39 +----- .../widgets/code/command_system/__init__.py | 2 +- .../code/command_system/command_system.py | 120 ------------------ .../source_view_command_system.py} | 17 ++- .../code/controllers/commands_controller.py | 4 +- .../states/source_view_multi_insert_state.py | 1 + src/libs/command_system.py | 50 ++++++++ 8 files changed, 171 insertions(+), 162 deletions(-) create mode 100644 plugins/code/language_server_clients/python_lsp_client/config/jedi-lsp-server-config.json delete mode 100644 src/core/widgets/code/command_system/command_system.py rename src/core/widgets/code/{mixins/command_system_mixin.py => command_system/source_view_command_system.py} (79%) create mode 100644 src/libs/command_system.py diff --git a/plugins/code/language_server_clients/python_lsp_client/config/jedi-lsp-server-config.json b/plugins/code/language_server_clients/python_lsp_client/config/jedi-lsp-server-config.json new file mode 100644 index 0000000..2aeb1cc --- /dev/null +++ b/plugins/code/language_server_clients/python_lsp_client/config/jedi-lsp-server-config.json @@ -0,0 +1,100 @@ +{ + "info": "https://github.com/python-lsp/python-lsp-server", + "command": "lsp-ws-proxy -- pylsp", + "alt-command": "pylsp", + "alt-command2": "lsp-ws-proxy --listen 4114 -- pylsp", + "alt-command3": "pylsp --ws --port 4114", + "socket": "ws://127.0.0.1:9999/python", + "socket-two": "ws://127.0.0.1:9999/?name=pylsp", + "initialization-options": { + "pylsp": { + "rope": { + "ropeFolder": "{user.home}/.config/newton/lsps/ropeproject" + }, + "plugins": { + "ruff": { + "enabled": true, + "extendSelect": ["I"], + "lineLength": 80 + }, + "pycodestyle": { + "enabled": false + }, + "pyflakes": { + "enabled": false + }, + "pylint": { + "enabled": true + }, + "mccabe": { + "enabled": false + }, + "pylsp_rope": { + "rename": false + }, + "rope_rename": { + "enabled": false + }, + "rope_autoimport": { + "enabled": true + }, + "rope_completion": { + "enabled": false, + "eager": false + }, + "jedi_rename": { + "enabled": true + }, + "jedi_completion": { + "enabled": true, + "include_class_objects": true, + "include_function_objects": true, + "fuzzy": false + }, + "jedi": { + "root_dir": "file://{workspace.folder}", + "extra_paths": [ + "{user.home}/Portable_Apps/py-venvs/pylsp-venv/venv/lib/python3.10/site-packages" + ] + } + } + } + } +}, +"python - jedi-language-server": { + "hidden": true, + "info": "https://pypi.org/project/jedi-language-server/", + "command": "jedi-language-server", + "alt-command": "lsp-ws-proxy --listen 3030 -- jedi-language-server", + "socket": "ws://127.0.0.1:9999/python", + "socket-two": "ws://127.0.0.1:9999/?name=jedi-language-server", + "initialization-options": { + "jediSettings": { + "autoImportModules": [], + "caseInsensitiveCompletion": true, + "debug": false + }, + "completion": { + "disableSnippets": false, + "resolveEagerly": false, + "ignorePatterns": [] + }, + "markupKindPreferred": "markdown", + "workspace": { + "extraPaths": [ + "{user.home}/Portable_Apps/py-venvs/pylsp-venv/venv/lib/python3.10/site-packages" + ], + "environmentPath": "{user.home}/Portable_Apps/py-venvs/gtk-apps-venv/venv/bin/python", + "symbols": { + "ignoreFolders": [ + ".nox", + ".tox", + ".venv", + "__pycache__", + "venv" + ], + "maxSymbols": 20 + } + } + } +} diff --git a/plugins/code/language_server_clients/python_lsp_client/config/lsp-server-config.json b/plugins/code/language_server_clients/python_lsp_client/config/lsp-server-config.json index 2aeb1cc..5b81dc4 100644 --- a/plugins/code/language_server_clients/python_lsp_client/config/lsp-server-config.json +++ b/plugins/code/language_server_clients/python_lsp_client/config/lsp-server-config.json @@ -60,41 +60,4 @@ } } } -}, -"python - jedi-language-server": { - "hidden": true, - "info": "https://pypi.org/project/jedi-language-server/", - "command": "jedi-language-server", - "alt-command": "lsp-ws-proxy --listen 3030 -- jedi-language-server", - "socket": "ws://127.0.0.1:9999/python", - "socket-two": "ws://127.0.0.1:9999/?name=jedi-language-server", - "initialization-options": { - "jediSettings": { - "autoImportModules": [], - "caseInsensitiveCompletion": true, - "debug": false - }, - "completion": { - "disableSnippets": false, - "resolveEagerly": false, - "ignorePatterns": [] - }, - "markupKindPreferred": "markdown", - "workspace": { - "extraPaths": [ - "{user.home}/Portable_Apps/py-venvs/pylsp-venv/venv/lib/python3.10/site-packages" - ], - "environmentPath": "{user.home}/Portable_Apps/py-venvs/gtk-apps-venv/venv/bin/python", - "symbols": { - "ignoreFolders": [ - ".nox", - ".tox", - ".venv", - "__pycache__", - "venv" - ], - "maxSymbols": 20 - } - } - } -} +} \ No newline at end of file diff --git a/src/core/widgets/code/command_system/__init__.py b/src/core/widgets/code/command_system/__init__.py index bd5eb3b..b10a930 100644 --- a/src/core/widgets/code/command_system/__init__.py +++ b/src/core/widgets/code/command_system/__init__.py @@ -2,4 +2,4 @@ Code Command System Package """ -from .command_system import CommandSystem +from .source_view_command_system import SourceViewCommandSystem diff --git a/src/core/widgets/code/command_system/command_system.py b/src/core/widgets/code/command_system/command_system.py deleted file mode 100644 index a723f46..0000000 --- a/src/core/widgets/code/command_system/command_system.py +++ /dev/null @@ -1,120 +0,0 @@ -# Python imports - -# Lib imports - -# Application imports -from libs.event_factory import Event_Factory, Code_Event_Types - -from ..mixins.command_system_mixin import CommandSystemMixin -from ..source_view import SourceView - -from . import commands - - - -class CommandSystem(CommandSystemMixin): - def __init__(self): - super(CommandSystem, self).__init__() - - self.data: list = () - - - def set_data(self, *args, **kwargs): - self.data = (args, kwargs) - - def exec(self, command: str) -> any: - if not hasattr(commands, command): return - method = getattr(commands, command) - - args, kwargs = self.data - return method.execute(*args, **kwargs) - - def exec_with_args(self, command: str, *args, **kwargs) -> any: - if not hasattr(commands, command): return - - method = getattr(commands, command) - return method.execute(*args, **kwargs) - - def add_command(self, command_name: str, command: callable): - setattr(commands, command_name, command) - - def remove_command(self, command_name: str, command: callable): - if hasattr(commands, command_name): - delattr(commands, command_name) - - - def emit(self, event: Code_Event_Types.CodeEvent): - """ Monkey patch 'emit' from command controller... """ - ... - - def emit_to(self, controller: str, event: Code_Event_Types.CodeEvent): - """ Monkey patch 'emit_to' from command controller... """ - ... - - -# def filter_out_loaded_files(self, uris: list[str]): -# event = Event_Factory.create_event( -# "filter_out_loaded_files", -# uris = uris -# ) -# -# self.emit_to("files", event) -# -# return event.response -# -# def set_info_labels(self, data: tuple[str]): -# event = Event_Factory.create_event( -# "set_info_labels", -# info = data -# ) -# -# self.emit_to("plugins", event) -# -# def get_file(self, view: SourceView): -# event = Event_Factory.create_event( -# "get_file", -# view = view, -# buffer = view.get_buffer() -# ) -# -# self.emit_to("files", event) -# -# return event.response -# -# def get_swap_file(self, view: SourceView): -# event = Event_Factory.create_event( -# "get_swap_file", -# view = view, -# buffer = view.get_buffer() -# ) -# -# self.emit_to("files", event) -# -# return event.response -# -# def new_file(self, view: SourceView): -# event = Event_Factory.create_event("add_new_file", view = view) -# -# self.emit_to("files", event) -# -# return event.response -# -# def remove_file(self, view: SourceView): -# event = Event_Factory.create_event( -# "remove_file", -# view = view, -# buffer = view.get_buffer() -# ) -# -# self.emit_to("files", event) -# -# return event.response -# -# def request_completion(self, view: SourceView): -# event = Event_Factory.create_event( -# "request_completion", -# view = view, -# buffer = view.get_buffer() -# ) -# -# self.emit_to("completion", event) \ No newline at end of file diff --git a/src/core/widgets/code/mixins/command_system_mixin.py b/src/core/widgets/code/command_system/source_view_command_system.py similarity index 79% rename from src/core/widgets/code/mixins/command_system_mixin.py rename to src/core/widgets/code/command_system/source_view_command_system.py index 6dd7804..4eb4df5 100644 --- a/src/core/widgets/code/mixins/command_system_mixin.py +++ b/src/core/widgets/code/command_system/source_view_command_system.py @@ -4,12 +4,19 @@ # Application imports from libs.event_factory import Event_Factory, Code_Event_Types +from libs.command_system import CommandSystem from ..source_view import SourceView +from . import commands + + + +class SourceViewCommandSystem(CommandSystem): + def __init__(self): + super(SourceViewCommandSystem, self).__init__(commands) -class CommandSystemMixin: def toggle_plugins_ui(self): event = Event_Factory.create_event( "toggle_plugins_ui" ) @@ -81,3 +88,11 @@ class CommandSystemMixin: ) self.emit_to("completion", event) + + def emit(self, event: Code_Event_Types.CodeEvent): + """ Monkey patch 'emit' from command controller... """ + ... + + def emit_to(self, controller: str, event: Code_Event_Types.CodeEvent): + """ Monkey patch 'emit_to' from command controller... """ + ... diff --git a/src/core/widgets/code/controllers/commands_controller.py b/src/core/widgets/code/controllers/commands_controller.py index 532bb07..780b66c 100644 --- a/src/core/widgets/code/controllers/commands_controller.py +++ b/src/core/widgets/code/controllers/commands_controller.py @@ -7,7 +7,7 @@ from libs.controllers.controller_base import ControllerBase from libs.event_factory import Code_Event_Types -from ..command_system import CommandSystem +from ..command_system import SourceViewCommandSystem @@ -21,7 +21,7 @@ class CommandsController(ControllerBase, list): event.response = self.get_new_command_system() def get_new_command_system(self): - command_system = CommandSystem() + command_system = SourceViewCommandSystem() command_system.emit = self.emit command_system.emit_to = self.emit_to diff --git a/src/core/widgets/code/controllers/views/states/source_view_multi_insert_state.py b/src/core/widgets/code/controllers/views/states/source_view_multi_insert_state.py index c8b5f1e..1df1a82 100644 --- a/src/core/widgets/code/controllers/views/states/source_view_multi_insert_state.py +++ b/src/core/widgets/code/controllers/views/states/source_view_multi_insert_state.py @@ -59,6 +59,7 @@ class SourceViewsMultiInsertState(SourceViewsBaseState): buffer.insert(start_itr, text, -1) self.marker_manager.apply_to_marks(buffer, replace_word) + return True def move_cursor( diff --git a/src/libs/command_system.py b/src/libs/command_system.py new file mode 100644 index 0000000..221c2b3 --- /dev/null +++ b/src/libs/command_system.py @@ -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)