Skip to content

feat: support port=0 for auto-assign free port - #371

Open
otakenz wants to merge 1 commit into
brianhuster:mainfrom
otakenz:feat/auto-assign-port
Open

feat: support port=0 for auto-assign free port#371
otakenz wants to merge 1 commit into
brianhuster:mainfrom
otakenz:feat/auto-assign-port

Conversation

@otakenz

@otakenz otakenz commented Jul 1, 2026

Copy link
Copy Markdown

What

Allows port = 0 in config to auto-assign any free port. When port is 0:

  • Skips the port-in-use check (meaningless for auto-assign)
  • Reads back the actual assigned port via uv_tcp_getsockname()
  • Uses the actual port in browser URLs instead of the config value

Changes

  • server/init.lua — call getsockname() after bind(), store self.port
  • lua/livepreview/init.lua — wrap port-in-use check in if port ~= 0, return actual port from start(), use it in pick()
  • plugin/livepreview.lua — use lp.serverObj.port for browser URL in :LivePreview start

Why

Currently if port 8080 (or any fixed port) is in use by another process, the only options are to kill that process or change to a different hardcoded port. With port = 0 the OS picks a free port automatically, no conflict ever.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your pull request! We appreciate your contribution. Please ensure that your changes are well documented and tested, and are formatted as noexpandtab.

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