π OpenHands: AI-Driven Development
Move VSCode settings.json setup from Dockerfile to VSCode plugin initialization (#8192)
Xingyao Wang59fc0fe9dbad
diff --git a/openhands/runtime/plugins/vscode/__init__.py b/openhands/runtime/plugins/vscode/__init__.pyindex 852e0e3045..e583e2a107 100644--- a/openhands/runtime/plugins/vscode/__init__.py+++ b/openhands/runtime/plugins/vscode/__init__.py@@ -1,7 +1,9 @@import asyncioimport os+import shutilimport uuidfrom dataclasses import dataclass+from pathlib import Pathfrom typing import Optionalfrom openhands.core.logger import openhands_logger as logger@@ -33,6 +35,9 @@ class VSCodePlugin(Plugin):)return+ # Set up VSCode settings.json+ self._setup_vscode_settings()+self.vscode_port = int(os.environ['VSCODE_PORT'])self.vscode_connection_token = str(uuid.uuid4())assert check_port_available(self.vscode_port)@@ -67,6 +72,28 @@ class VSCodePlugin(Plugin):f'VSCode server started at port {self.vscode_port}. Output: {output}')+ def _setup_vscode_settings(self) -> None:+ """+ Set up VSCode settings by creating the .vscode directory in the workspace+ and copying the settings.json file there.+ """+ # Get the path to the settings.json file in the plugin directory+ current_dir = Path(__file__).parent+ settings_path = current_dir / 'settings.json'++ # Create the .vscode directory in the workspace if it doesn't exist+ vscode_dir = Path('/workspace/.vscode')+ vscode_dir.mkdir(parents=True, exist_ok=True)++ # Copy the settings.json file to the .vscode directory+ target_path = vscode_dir / 'settings.json'+ shutil.copy(settings_path, target_path)++ # Make sure the settings file is readable and writable by all users+ os.chmod(target_path, 0o666)++ logger.debug(f'VSCode settings copied to {target_path}')+async def run(self, action: Action) -> Observation:"""Run the plugin for a given action."""raise NotImplementedError('VSCodePlugin does not support run method')diff --git a/openhands/runtime/utils/runtime_templates/Dockerfile.j2 b/openhands/runtime/utils/runtime_templates/Dockerfile.j2index 610ce537ef..a381edc11a 100644--- a/openhands/runtime/utils/runtime_templates/Dockerfile.j2+++ b/openhands/runtime/utils/runtime_templates/Dockerfile.j2@@ -155,9 +155,6 @@ RUN \COPY ./code/pyproject.toml ./code/poetry.lock /openhands/code/-COPY ./code/openhands/runtime/plugins/vscode/settings.json /workspace/.vscode/settings.json-RUN chmod -R a+rwx /workspace/.vscode/settings.json-{{ install_dependencies() }}# ================================================================@@ -171,9 +168,6 @@ RUN chmod -R a+rwx /workspace/.vscode/settings.jsonRUN if [ -d /openhands/code/openhands ]; then rm -rf /openhands/code/openhands; fiCOPY ./code/pyproject.toml ./code/poetry.lock /openhands/code/-COPY ./code/openhands/runtime/plugins/vscode/settings.json /workspace/.vscode/settings.json-RUN chmod -R a+rwx /workspace/.vscode/settings.json-COPY ./code/openhands /openhands/code/openhandsRUN chmod a+rwx /openhands/code/openhands/__init__.py