Move VSCode settings.json setup from Dockerfile to VSCode plugin initialization (#8192)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Xingyao Wang 2025-05-01 12:00:43 +08:00 committed by GitHub
parent 7ae3494ccc
commit 59fc0fe9db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View File

@ -1,7 +1,9 @@
import asyncio
import os
import shutil
import uuid
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
from 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')

View File

@ -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.json
RUN if [ -d /openhands/code/openhands ]; then rm -rf /openhands/code/openhands; fi
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
COPY ./code/openhands /openhands/code/openhands
RUN chmod a+rwx /openhands/code/openhands/__init__.py