Skip to content

The premier Visual Studio Code Extension for G-Code

License

Notifications You must be signed in to change notification settings

scottmwyant/vscode-gcode

Repository files navigation


icon


The premier Visual Studio Code extension for G-Code


Visual Studio Marketplace Version Visual Studio Marketplace Installs Visual Studio Marketplace Rating

✨ Features

Adaptive Syntax Highlighting

Ctrl+Shift+P >G-Code: Adapt to current theme

icon

CAD/CAM packages typically show the X-axis in red, the Y-axis in green, and the Z-Axis in blue. The G-Code extension follows that pattern. The adaptive syntax feature allows you to choose any of the supproted themes and get that familiar colorization. G-Code supports all of the themes that ship with VS Code, plus the GitHub theme and OneDark-Pro.

  • When VS Code starts and the extension activates, it will check the active theme and if the extension's syntax highlighting isn't already tailored to that theme, you will be prompted to allow the extension to rewrite the files that style the code.

  • Should you miss the prompt, you can use the G-Code: Adapt to current theme command to force the extension to adapt to the theme you're using (as long as it's supported).

Build your own dictionary

icon

You no longer need to memorize dozens of obscure G and M codes! The G-Code extension includes a mechanism for you to provide your own definitions for any number of codes. Definitions can even be provided inline with the code.

Using VS Code settings

Share definitions across multiple programs using VS Code's settings files. Take a look at VS Code Docs - User and Workspace Settings if you're not familiar VS Code configuration.

You need to add a gcode.definitions key to your settings.json file (user settings, workspace settings, or both). Here's an example of what it might look like:

"gcode.definitions": {
    "G90": "Positioning, absolute (modal)",
    "G91": "Positioning, relative (modal)",
    "M8": "Coolant On, External to Spindle",
    "M9": "Coolant Off",
    "M51": "Coolant On, Internal to Spindle",
}

Using inline definitions

An inline definition is a comment in your code that matches the following format. An inline definition has a code and a meaning seperated by : or =. There may be whitespace on either side of the seperator. The text on the right side of the seperator will show up as hover text in that file. See some examples of inline definitions below.

Note that after you add inline definitions to a file, they won't show up in a hover until the file is saved. This prevents the extension from needing to continuously scan your file for definitions.

Examples of inline definitions:

(G4:DWELL)
(G4: THIS IS A DWELL)
(G4 = DWELL, USE P TO SPECIFY TIME)

A word on leading zeros

When providing definitions, regardless of which method you use, don't use leading zeros. Provide a definition for G1 not G01. When you hover over a code like G01 the extension ignores the leading zero and returns a definition for G1.

Using the dictionary

Ctrl+Shift+P >G-Code: Show the dictionary

icon

You can use the command, G-Code: Show the dictionary, to get the definitions on screen, so you can see them alongside your code as you work. You can also see the definition for a particular code just by hovering over it.

Line Numbering

Ctrl+Shift+P >G-Code: Line Numbers (Add/Update)

Ctrl+Shift+P >G-Code: Line Numbers (Remove)

icon

Addding, updating, or removing line numbers are not tasks you should ever need to do manually. A robust G-Code editor should make this easy as possible so you can focus on more important things. The G-Code extension provides commands to carry out these tasks on the active file. Don't forget that you can map commands to a keyboard shortcut of your choice. See Key Bindings for Visual Studio Code.

Toggle Comments

Ctrl+Shift+P >G-Code: Toggle Comment

icon

VS Code ships with the ability to toggle comments. The built-in feature works by modifying one or more characters at the beginning of each selected line. Since it only affects the beginning of the line, it doesn't work for G-Code comments that need to be (in parentheses). The G-Code extension provides a command that will toggle parentheses at the start and end of each selected line.

📓 Release Notes

Documentation pertaining to a specific release can be found under releases, or in the project's changelog.

💻 Developers

VS Code Token Styles

Early on I realized I needed a way to see how each VS Code theme styles the various language tokens. My approach was to get data for each theme by using the Developer: Generate Color Theme From Current Settings command then use that data to render HTML. Since that work may be intersting outside of this project, I chose to save it in this gist.

Automated Deployment

Maintainers, here's how to publish the extension to the marketplace:

  1. Put the new version number in package.json. The version number must be higher than the version shown in the marketplace. Reference semver.org.
  2. Create an entry in the changelog. Reference keepachangelog.com.
  3. Push a new tag with the version number. The tag must start with a 'v', like this: v1.2.3.

As long as these requirements are met, the CD workflow should go smoothly. A release will be created, and the new version of the extension will be published to the marketplace (see ./github/workflows).