Intellisense of Sketchup and code compilation with vscode

Hello everyone,

I come from a background in Python and Fusion 360 scripting, I’m now delving into Sketchup extension development. I’ve got my environment all set up with vscode and successfully ran the Hello cube example.

However, I’m encountering an issue with Intellisense. When I type ‘Sketchup’, no suggestions pop up, and I can’t navigate to the actual definition by using Ctrl+Click. It seems like I might have missed a step during setup. is there away to reference the actual Sketchup API.

I would greatly appreciate any guidance or insights based on your experience.

image

Thank you!

The code snippet you posted is incomplete.
It is however full of errors.
You do not need to access the API it’s built-in and correctly formatted code will work…

You cannot just add SketchUp in the middle of a method - it does nothing, and in Ruby it’s always Sketchup in any case.

Your line sketchup.active_model is also wrong as it does nothing, it’s again Sketchup NOT sketchup and model has already been defined anyway.

After that what you show is OK, but what happens next is anyone’s guess…
Please learn how to format you code snippets in your posts properly.
As it is we cannot interact with them…

You’d probably be better using Sketchup’s Ruby Console and understanding the basics of the API, before you jump in like this… There are hundreds of examples freely available…

PS: I fixed your posts title as it was full of typing errors - please use a spellchecker and proof read what you type…

In order for Intellisense to work you must have the stubs for the Ruby API.

GitHub - Stubs for the SketchUp Ruby API. Useful for IDE intellisense and auto-complete.

@tt_su packaged them into a gem, so you can likely install them into your stand alone Ruby setup.

The gem name is: "sketchup-api-stubs"

1 Like

Thank you for fixing the post and pointing out the mistakes. I will upload another image. The only reason for adding an image instead of code is that I would like to show that Intellisense is neither showing nor referencing the Sketchup API.

I have used the boiler sample project.
https://github.com/SketchUp/sketchup-extension-vscode-project

Thank you, @DanRathbun, for your response.

I believe I have the sketchup-api-stubs installed:

Please pardon me as I’m just starting with Ruby and SketchUp extension development. My approach to learning involves practical examples and navigating through code and definitions.

For instance, when attempting to obtain the definition of Sketchup or active_model, no definition is found.

image

I think by “definition” you really mean the Intellisense listing of methods and their argument’s ?

You will only obtain meaningful references inside SketchUp’s Ruby subprocess. The API stubs loaded into a standalone Ruby will just be “hollow” objects that do not really act like they would inside SketchUp.

Coming from Python, this guide may help you: To Ruby From Python


Let us try to stay on the topic of Intellisense in VSCode.

I do not use VSCode myself, so I defer to others here who do use it.

Most likely the problem is that you don’t have a properly configured solargraph.yml file to tell VSCode’s intellisense where to find the SketchUp Ruby API stubs. Consult this page for info on how to set up solargraph.

Edit: that page appears to be out of date? A skeleton for the file looks like this (at some point I got this from a page that @thomthom created, but I can’t find it right now…)

# 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:
# list paths to files here, with a - in front of each.  The most important one is
# to wherever you put the sketchup-api-stubs

# 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/**/*
1 Like

Here’s a link to the GitHub page about setting up VSCode for SketchUp.

I used the boiler project as is, .solargraph.yml. I only updated the SketchUp tools path.

require_paths:
  - "C:/Program Files/SketchUp/SketchUp 2022/Tools"
  - src

require:
  - sketchup-api-stubs

reporters:
  - rubocop

Where did you put that .solargraph.yml file?

Yes. And just to provide some context, for example: in my Python code for Fusion 360 in vscode, I get helpful pop-ups when I hover over Fusion 360 core API classes and methods. Additionally, when I use Ctrl+Click, it takes me directly to the actual definition of a class like ‘Application’.

Class Application definition:
image

Maybe this can’t be achieved in vscode with SketchUp API! I’m wondering if there’s an alternative way to navigate through the code and glean information from docstrings without constantly referring back to the official documentation website. It’d be helpful to have some context while programming, even if it’s just a glimpse of what a class or method is about.

It used to work I think. I have seen it working in the past.

See this tutorial …

solargraph version

Thank you @DanRathbun

I have followed this to set up.

Setting up was quite a challenge, taking about six hours to finally able to get it to work “a newbie”. The instructions provided are outdated, still referencing the Ruby vscode extension despite its deprecation. It’s been replaced with Ruby LSP, which completely disrupts the provided boiler project launch.json file. I posted about this issue in this forum yesterday, but unfortunately, no one has responded yet. I’ll share my findings once I have a chance.

Luckily I can run and debug in vscode… I am just trying to tune my dev environment now.

How are you connecting VSCode to the SketchUp process? Did you load the old Ruby VSCode extension, or have you found a way to make the new LSP connect? I haven’t!

The O

Yes. I had to install it manually into vscode.

Do you think maybe because I had Ruby LSP setup first and then uninstalled, it may somehow have residual settings impacting intellisense.

I worry that it may not be compatible with SketchUp 2024, which moved up to Ruby 3.2.2. Your forum profile says you are using 2023, is that still true? Where did you find the old extension to download?

I suppose that’s possible. I don’t understand enough about how VSCode extensions work to know.

don’t click the green Install button, it will take you to vscode and it won’t install (it will detect it as deprecated). Click Download Extension under Resources, save it locally then add it manually to vscode (Install from VSIX…).

What do you guys use for an IDE that works well with Sketchup API to get intellisense…

2 Likes

I use VSCode and am quite happy with it for Ruby code editing. I tried NetBeans and found it to be much heavier and more complex than I needed. When VSCode deprecated Peng Lv’s Ruby extension, I followed the advice and installed Ruby LSP. I have intellisense and rubocop working fine, though it seems like I have to put the yml files in every project folder despite statements they will search up the folder hierarchy until they find one. But, the real disappointment is that, so far as I have been able to discover, there is no other Ruby VSCode extension that supports the debug interface that SketchUp uses. Back to infinitely tedious puts statements.