Skip to content

noahlias/nc_view_idea

Repository files navigation

NC Viewer IntelliJ Port

This sub-project is a prototype port of the VS Code “NC Viewer” extension into an IntelliJ Platform plugin that targets IntelliJ IDEA (and other 2024.2+ IDEs). It embeds the existing Three.js-based web viewer inside a JCEF panel and mirrors the VS Code messaging contract so caret changes and file edits stay in sync with the 3D preview.

Requirements

  • IntelliJ Platform: 2024.2 Community Edition (or newer) since the Gradle IntelliJ plugin is pinned to that build.
  • JDK: 17 (JetBrains Runtime ships with the IDE; point Gradle to it to skip toolchain downloads).
  • Gradle: Wrapper is included (gradlew / gradlew.bat), so no global install required.

Directory Layout

  • src/main/resources/ncviewer/media — bundled Three.js viewer assets copied directly from the VS Code project.
  • src/main/kotlin/com/ncviewer/idea/ui/NcViewerPanel.kt — hosts the viewer inside a JBCefBrowser and bridges messages.
  • src/main/kotlin/com/ncviewer/idea/actions/OpenNcViewerAction.kt — editor action that opens the tool window for .nc/.gcode/.cnc files.
  • src/main/kotlin/com/ncviewer/idea/service/NcViewerProjectService.kt — project-level service that wires actions and the tool window.
  • src/main/resources/META-INF/plugin.xml — IntelliJ plugin metadata, action registrations, and tool window declaration.

Build & Run

cd nc_viewer_idea
./gradlew build        # compiles Kotlin + packages plugin zip under build/distributions
./gradlew runIde       # launches a sandboxed IntelliJ IDEA with the plugin installed

If you need Windows command prompts, substitute gradlew.bat for ./gradlew.

Common Gradle Tasks

  • ./gradlew test — runs Kotlin/JVM tests (currently placeholder).
  • ./gradlew verifyPlugin — JetBrains plugin validation (signatures, descriptors, etc.).
  • ./gradlew clean buildPlugin — produces the distributable archive you can install manually.

Reuse Existing IntelliJ & JDK (faster builds)

By default the Gradle IntelliJ plugin downloads the target IDE + JetBrains Runtime. You can instead point the build to your already-installed IntelliJ IDEA and its bundled JBR:

  1. Opt-in by editing nc_viewer_idea/gradle.properties (or ~/.gradle/gradle.properties) and setting:
    idea.local.path=/path/to/idea-IC-242.23726.103/IntelliJ IDEA CE.app/Contents
    org.gradle.java.home=/path/to/idea-IC-242.23726.103/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home
    
    Use an IntelliJ build whose Resources/product-info.json reports the same major version (2024.2) and whose lib/modules directory contains version-suffixed jars (Toolbox installs auto-updated to 2025.x omit these and will fail to resolve dependencies).
  2. Alternatively, pass the overrides per build:
    ./gradlew build -Didea.local.path="/path/to/idea-IC-242.23726.103/IntelliJ IDEA CE.app/Contents" \
                    -Dorg.gradle.java.home="/path/to/idea-IC-242.23726.103/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home"

If the properties are left empty or point to an incompatible install, the build automatically falls back to downloading the matching IntelliJ distribution.

Development Notes

  1. Web Assets: The viewer expects the same relative file paths as the VS Code extension. Copy updates from the root media/ folder into src/main/resources/ncviewer/media to keep them in sync.
  2. Message Bridge: Instead of relying on JBCefJSQuery, the viewer now talks to the host over a local http://127.0.0.1:<port>/ncbridge loopback server. Kotlin pushes loadGCode/contentChanged payloads into the server, and the Three.js page polls + posts JSON so the contract (loadGCode, cursorPositionChanged, contentChanged, highlightLine, bridgeDebug) stays unchanged but is far more reliable. The webview also auto-syncs its light/dark palette to prefers-color-scheme (or any data-theme override injected by the host) so it blends into the IDE theme automatically.

Verbose bridge logging is automatically enabled when -Didea.is.internal=true; for production builds leave it unset (or pass -Dncviewer.verboseLog=false) to suppress per-message log spam. 3. Settings: NcViewerSettings stores the excludeCodes array. A UI is not implemented yet; values can be tweaked via the NcViewerSettings service for now. 4. IDE Compatibility: Because the tool window uses JBCefBrowser, the target IDE must ship with JCEF (true for 2020.3+ builds). Stick to 2024.2+ until we broaden testing.

Next Steps / TODO

  • Add a proper Settings/Preferences page to edit exclude-code lists.

Continuous Delivery

Pushes to main/master run checks, while annotated tags trigger the release pipeline defined in .github/workflows/build.yml. On tag builds the workflow now:

  1. Builds the plugin ZIP via ./gradlew buildPlugin.
  2. Publishes the artifact to the JetBrains Marketplace via ./gradlew publishPlugin.
  3. Uploads the same ZIP to the GitHub release for convenience.

To enable Marketplace publishing, create a permanent token in your JetBrains Marketplace profile and add it as the repository secret JETBRAINS_MARKETPLACE_TOKEN. Optionally define JETBRAINS_MARKETPLACE_CHANNELS (comma-delimited; defaults to default) to steer which channel receives the upload.

About

NC viewer port of IDEA

Resources

License

Stars

Watchers

Forks

Contributors