VS Code 디버깅

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

설정

아래의 예제는 rails-webrails-background-jobs에 대한 런치 구성을 포함합니다.

  1. gitlab 폴더 내에서 gem install debug를 실행하여 debug gem을 설치합니다.

  2. VS Code Ruby rdbg 디버거 확장을 설치하여 VS Code에 rdbg 디버거 타입 지원을 추가합니다.

  3. GitLab 및 관련 Ruby Rails/Sidekiq 프로세스를 자동으로 중지하고 시작하려면 다음 VS Code 작업을 .vscode/tasks.json 파일의 구성에 추가할 수 있습니다:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "start rdbg for rails-web",
          "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\\.\\.\\.)$"
            }
          }
        },
        {
          "label": "start rdbg for rails-background-jobs",
          "type": "shell",
          "command": "gdk stop rails-background-jobs && rdbg --open -c bundle exec sidekiq",
          "isBackground": true,
          "problemMatcher": {
            "owner": "sidekiq",
            "pattern": {
              "regexp": "^(DEBUGGER: wait for debugger connection\\.\\.\\.)$"
            },
            "background": {
              "activeOnStart": false,
              "beginsPattern": "^(ok: down:).*$",
              "endsPattern": "^(DEBUGGER: wait for debugger connection\\.\\.\\.)$"
            }
          }
        }
      ]
    }
    
  4. 다음 구성을 .vscode/launch.json 파일에 추가합니다:

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "rdbg",
          "name": "Attach rails-web with rdbg",
          "request": "attach",
    
          // 다음 "preLaunchTask" 제거하면 VS Code를 통해 GitLab을 중지하고 시작하지 않고
          // 별도의 터미널에서 수동으로 수행할  있습니다.
          "preLaunchTask": "start rdbg for rails-web"
        },
        {
          "type": "rdbg",
          "name": "Attach rails-background-jobs with rdbg",
          "request": "attach",
    
          // 다음 "preLaunchTask" 제거하면 VS Code를 통해 GitLab을 중지하고 시작하지 않고
          // 별도의 터미널에서 수동으로 수행할  있습니다.
          "preLaunchTask": "start rdbg for rails-background-jobs"
        }
      ]
    }
    
caution

VS Code Ruby 확장이 올바른 Ruby 설치 및 적절한 rdbg 명령을 찾는 데 문제가 있을 수 있습니다. 이 경우, 상기의 런치 구성을 수정하여 "rdbgPath": "/home/user/.asdf/shims/ (asdf의 경우)를 추가하세요.

디버깅

전제 조건

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

디버깅을 시작하려면 다음 중 하나를 실행하세요:

  • F5를 누릅니다.

  • Debug: Start Debugging 명령을 실행합니다.

  • 실행 및 디버그 보기를 열고, 실행 프로필 중 하나를 선택한 다음 Play ( )를 선택합니다.