Skip to content

VSCode Stubs Setup

Thomas Thomassen edited this page May 16, 2019 · 2 revisions
autoauto- [Setting Up the API Stubs](#setting-up-the-api-stubs)auto - [Requirements](#requirements)auto - [Standalone Ruby](#standalone-ruby)auto - [Visual Studio Code](#visual-studio-code)auto - [Ruby](#ruby)auto - [Ruby Solargraph](#ruby-solargraph)auto - [Gems](#gems)auto - [Project Setup](#project-setup)autoauto

Setting Up the API Stubs

This assumes you have the extension source code in it's own project directory and that you have configured SketchUp to load the extension directly from that location.

Requirements

Standalone Ruby

You will also need a standalone version of Ruby installed on your system.

For Windows the easiest way is to use the Ruby Windows Installer from rubyinstaller.org.

Mac comes with a version of Ruby installed, but it's usually an older version that require sudo to install gems. To get an up to date version of Ruby running on mac use RVM.

Visual Studio Code

Next we can set up Visual Studio Code.

Before continuing, make sure you have the following VSCode extension installed.

Ruby

Ruby Solargraph

Gems

From the command line you need to install a couple of gems to your standalone installation of Ruby:

gem install yard
gem install solargraph
gem install sketchup-api-stubs
yard gems sketchup-api-stubs

Project Setup

Start with opening the VSCode settings for your current project.

File » Settings (Ctrl+,) (Make sure to select Workspace Settings)

Set solargraph.diagnostics to true:

.vscode/settings.json

{
  "solargraph.diagnostics": true
}

Then create a .solargraph.yml file in the root of your project:

.solargraph.yml

# To allow solargraph to resolve the require paths correctly, add the path
# to the Tools directory of one of your SketchUp installations.
# You also want to add the path to where you have the extension's sources.
# (In this example it would be in a `src` directory relative to .solargraph.yml)
require_paths:
- "C:/Program Files/SketchUp/SketchUp 2018/Tools"
- src

# This will load the stubs for the SketchUp API.
require:
- sketchup-api-stubs

# Exclude files that doesn't need to be parsed. Avoids noise and improve performance.
exclude:
- /build/**/*
- /ThirdParty/**/*

If everything is set up correctly then you should now get auto-complete assistance for the SketchUp Ruby API. Solargraph will use YARD comments to help infer the type of method arguments.