Skip to content

Auto port switch#22

Merged
Jason2866 merged 4 commits into
mainfrom
auto_port
Apr 9, 2026
Merged

Auto port switch#22
Jason2866 merged 4 commits into
mainfrom
auto_port

Conversation

@Jason2866
Copy link
Copy Markdown
Owner

@Jason2866 Jason2866 commented Apr 8, 2026

  • New Features
    • Integrates with the IDE upload lifecycle to manage serial handling during uploads.
    • Adds controls to temporarily release and later reacquire the selected serial port.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eac34317-d851-4ba6-b9f3-9d7afba532d0

📥 Commits

Reviewing files that changed from the base of the PR and between b2b8d13 and 95978c0.

📒 Files selected for processing (2)
  • src/extension.ts
  • src/serialPortManager.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/serialPortManager.ts

📝 Walkthrough

Walkthrough

Adds integration with the pioarduino.pioarduino-ide extension to suspend serial monitoring before uploads and to retry re-establishing the serial connection after uploads, plus helpers to normalize and compare macOS-style serial device paths.

Changes

Cohort / File(s) Summary
Upload lifecycle integration
src/extension.ts
Adds typed PioarduinoApi usage and subscribeToPioarduinoEvents(...) called from activate; subscribes to onWillUpload/onDidUpload; on will-upload conditionally waits on serial.releasePort() when target matches selected (with macOS /dev/cu.* vs /dev/tty.* normalization); on did-upload triggers reacquireWithRetry(...). Adds isSameSerialPort() and normalizePortPath() and new error paths for missing API.
Serial port suspension/resume
src/serialPortManager.ts
Adds releasePort() and reacquirePort() to snapshot/restore selected path and baud rate and to disconnect/reconnect; introduces _suspendedPath/_suspendedBaudRate state and alters disconnect() to reject on port close errors.

Sequence Diagram

sequenceDiagram
    participant IDE as pioarduino IDE
    participant Ext as Extension
    participant SPM as SerialPortManager
    participant Port as Serial Port

    IDE->>Ext: onWillUpload(targetPort)
    activate Ext
    Ext->>Ext: normalize target & selected (macOS /dev/cu.* vs /dev/tty.*)
    alt target matches selected or target undefined
        Ext->>SPM: releasePort()
        activate SPM
        SPM->>SPM: save suspended path & baud
        SPM->>Port: disconnect()
        deactivate SPM
    else target differs
        Note over Ext: do not release port
    end
    deactivate Ext

    IDE->>IDE: upload proceeds

    IDE->>Ext: onDidUpload(exitCode)
    activate Ext
    Ext->>Ext: reacquireWithRetry() with backoff
    loop retry attempts
        Ext->>SPM: reacquirePort()
        activate SPM
        SPM->>SPM: restore suspended path & baud
        SPM->>Port: connect()
        deactivate SPM
    end
    deactivate Ext
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I paused the hum, then hopped away,

Let uploads dance while wires stay,
When beeps return and retries sing,
I nudge the port — reconnecting spring,
A tiny hop, and circuits play.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Auto port switch' is vague and does not clearly describe the actual implementation—which adds pioarduino extension integration with port release/reacquire logic for upload handling. Clarify the title to reflect the main change, such as 'Integrate pioarduino extension for auto port management during uploads' or 'Add port release/reacquire logic for Arduino uploads'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auto_port

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/extension.ts`:
- Around line 472-475: The normalizePortPath function currently only swaps
/dev/cu. to /dev/tty. but leaves casing intact, causing case-sensitive
mismatches (e.g., COM3 vs com3); modify normalizePortPath to also normalize case
(e.g., call toLowerCase or toLocaleLowerCase on the returned path) so port-path
comparisons are case-insensitive, and update any code that compares ports to use
normalizePortPath(port) on both sides (refer to normalizePortPath).

In `@src/serialPortManager.ts`:
- Around line 236-245: reacquirePort currently ignores a failed reconnect
because it awaits this.connect() (which can resolve to false) but always
resolves successfully; change reacquirePort so it surfaces connect() failures by
capturing the result of await this.connect() and either (a) return a boolean
success flag (change signature to Promise<boolean>) and return the connect()
result, or (b) throw an error when connect() returns false so callers can retry;
update any callers of reacquirePort accordingly. Ensure you reference the
existing symbols: method reacquirePort, the call to this.connect(), and the
suspended state fields (_suspendedPath, _suspendedBaudRate) when implementing
the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da2a9fb8-2ce4-4085-bee4-8b97743bbc80

📥 Commits

Reviewing files that changed from the base of the PR and between 2b75e92 and a9fb7be.

📒 Files selected for processing (2)
  • src/extension.ts
  • src/serialPortManager.ts

Comment thread src/extension.ts
Comment thread src/serialPortManager.ts
@Jason2866
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

✅ Actions performed

Full review triggered.

@Jason2866
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/extension.ts`:
- Around line 450-455: In the catch block handling reconnect attempts (the
try/catch that uses baseDelayMs, attempt, maxAttempts and calls log.appendLine),
avoid logging "retrying" and awaiting the backoff when attempt === maxAttempts;
instead, when attempt === maxAttempts, log a final failure message (or
rethrow/return) and skip the setTimeout so no extra sleep happens — only call
log.appendLine with the retrying message and await the delay when attempt <
maxAttempts.

In `@src/serialPortManager.ts`:
- Around line 221-229: The releasePath for uploads currently swallows port close
failures: update disconnect() so it propagates/throws when serial port.close()
reports an error instead of resolving silently, and ensure releasePort() (method
releasePort) awaits disconnect() and does not catch or convert that rejection
into a success; specifically, in disconnect()/SerialPortManager where you call
port.close(), remove or rework any try/catch that masks the error and rethrow
the close error (or return a rejected promise), and keep releasePort()'s await
this.disconnect() so callers of waitUntil(...) will receive the rejection and
abort/retry the upload.
- Around line 236-249: reacquirePort currently calls connect() which will
disconnect an already active session; to avoid tearing down a user-reconnected
session, add an early check in reacquirePort: after verifying
this._suspendedPath exists, if this._isConnected is true then clear
this._suspendedPath and this._suspendedBaudRate and return without touching
this._selectedPath or calling connect(); otherwise proceed with the existing
logic (set this._selectedPath/this._baudRate and call connect(), and only clear
the suspended snapshot after a successful connection).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b35046e-1a88-42b9-83e3-a205cff3fd47

📥 Commits

Reviewing files that changed from the base of the PR and between 2b75e92 and b2b8d13.

📒 Files selected for processing (2)
  • src/extension.ts
  • src/serialPortManager.ts

Comment thread src/extension.ts
Comment thread src/serialPortManager.ts
Comment thread src/serialPortManager.ts
@Jason2866 Jason2866 merged commit 3a2c3e8 into main Apr 9, 2026
3 checks passed
@Jason2866 Jason2866 deleted the auto_port branch April 30, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant