VS Code 디버깅

이 문서에서는 Visual Studio Code (VS Code)에서 GitLab Development Kit (GDK)를 사용하여 Rails 디버깅을 설정하는 방법에 대해 설명합니다.

설정

  1. gitlab 폴더 내에서 gem install debug를 실행하여 debug 젬을 설치합니다.
  2. VS Code Ruby rdbg Debugger 확장 프로그램을 설치하여 VS Code에서 rdbg 디버거 유형을 지원하도록 합니다.
  3. GitLab 및 관련된 Ruby Rails 서버를 자동으로 중지하고 시작하려는 경우, 다음과 같은 VS Code 작업을 .vscode/tasks.json 파일에 추가할 수 있습니다:
{
  "version": "2.0.0",
  "tasks": [
      {
        "label": "start rdbg",
        "type": "shell",
        "command": "gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true rdbg --open -c bin/rails server",
        "isBackground": true,
        "problemMatcher": {
          "owner": "rails",
          "pattern": {
            "regexp": "^.*$",
          },
          "background": {
            "activeOnStart": false,
            "beginsPattern": "^(ok: down:).*$",
            "endsPattern": "^(DEBUGGER: wait for debugger connection\\.\\.\\.)$"
          }
        }
      }
  ]
}
  1. .vscode/launch.json 파일에 다음 구성을 추가합니다:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "rdbg",
      "name": "Attach with rdbg",
      "request": "attach",
      
      // GitLab을 VS Code를 통해 중지하고 시작하지 않으려면 아래 "preLaunchTask" 제거합니다.
      "preLaunchTask": "start rdbg"
    }
  ]
}
caution
VS Code Ruby 확장 프로그램은 올바른 Ruby 설치 및 적절한 rdbg 명령을 찾는 데 문제가 있을 수 있습니다. 이 경우, 위의 런치 구성에 "rdbgPath": "/home/user/.asdf/shims/ (asdf의 경우)를 추가하십시오.

디버깅

사전 요구 사항

  • 실행 중인 GDK 인스턴스가 있어야 합니다.

디버깅을 시작하려면 다음 중 하나를 수행합니다:

  • F5를 누릅니다.
  • Debug: Start Debugging 명령을 실행합니다.