Date Notes
2019-08-30 涵盖 Debug Go/Ruby 配置、设置、插件
2019-11-12 增加 Debug CocoaPods & 插件

Preface

VS Code(全称 Visual Studio Code),是微软推出的一款插件化编辑器。比 IDE 轻量,又比终端更容易上手,本文将罗列一些我在使用的设置、配置、插件等,也欢迎大家建言献策~

Debug

Settings

Name Effect
Auto Save 自动保存,防止意外
Format On Save 保存时自动进行代码格式化

Go

// launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Go Local File by king co s",
      "type": "go",
      "request": "launch",
      "mode": "auto",
      "program": "${fileDirname}",
      "env": {
        // 
        "GOPATH": "PATH/TO/GO",
        "GOROOT": "PATH/TO/GO/ROOT",
        "GOBIN": "PATH/TO/GO/BIN"
      }
    }
  ]
}

// settings.json
{
  // 
  "go.gopath": "/usr/local/Cellar/go/1.12.9/"
}

可在 VS Code 的 Terminal 输入 go env 查看当前的环境变量。

Ruby

// launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Ruby Local File by kingcos.me",
      "type": "Ruby",
      "request": "launch",
      "program": "${workspaceRoot}/${fileBasename}"
    }
  ]
}

CocoaPods / CocoaPods 插件

学习 CocoaPods 源码或者为 CocoaPods 开发插件时,也可以使用 VS Code 和 Bundler 来简单 Debug:

  1. VS Code 安装 rebornix.Ruby 插件

  2. 将需要 Debug 的本地 CocoaPods 插件目录放在与 iOS 工程中 Podfile 同一级目录下

  3. 将使用到的 CocoaPods 版本源码也放在上述同一级目录下

# clone 当前使用 CocoaPods 版本的源码至当前目录
➜  YourProject git clone -b `pod --version` https://github.com/CocoaPods/CocoaPods.git

# 一级目录结构
➜  YourProject tree -L 1
.
├── CocoaPods                       # CocoaPods 源码目录
├── Gemfile                         # Gem 依赖
├── Podfile                         # iOS 项目依赖
├── YourProject                     # iOS 项目目录
├── YourProject.xcodeproj
└── cocoapods-xcode-manual-settings # CocoaPods 插件源码目录

4 directories, 2 files
  1. 在 Gemfile 中通过相对路径引入 CocoaPods 以及插件,并引入 ruby-debug-ide & debase
gem "cocoapods", :path => "CocoaPods"
gem "cocoapods-xcode-manual-settings", :path => "cocoapods-xcode-manual-settings"

gem "ruby-debug-ide"
gem "debase"
  1. 配置 launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CocoaPods Plugin by kingcos.me",
      "type": "Ruby",
      "request": "launch",
      "useBundler": true, // 使 Bundler 
      "showDebuggerOutput": true, //  Debugger 便 Debug
      "cwd": "${workspaceRoot}", // 
      "program": "${workspaceRoot}/CocoaPods/bin/pod", // 
      "args": ["install"], //  pod install
      "env": {
        // 
        "PATH": "PATH",
        "GEM_HOME": "PATH/TO/GEM/HOME",
        "GEM_PATH": "PATH/TO/GEM/PATH"
      }
    }
  ]
}
  1. 即可使用「fn + F5」调试:

1

Plugin

markdownlint

Gitlens