Skip to content

Conversation

@erroris3
Copy link
Contributor

  • Remove polling for port when its not found the opencode to randomly assign a free port and return
  • Made its all async now its no more UI lag.

BUT i giveup on finding the process cwd on windows so skip the check for that. Checking the parent should be enough (?).

Copilot AI review requested due to automatic review settings October 25, 2025 15:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the server port detection mechanism by adding asynchronous operations and automatic port finding capabilities. The changes eliminate UI lag by replacing synchronous io.popen calls with vim.system, and introduce automatic free port detection when no opencode server is found.

Key changes:

  • Converted all system command executions from synchronous to asynchronous using vim.system
  • Added automatic free port detection in the range 4096-5096 when no server is found
  • Implemented Windows support with PowerShell commands (though CWD checking is skipped on Windows)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lua/opencode/config.lua Updated on_opencode_not_found callback to accept a port parameter and append it to terminal command
lua/opencode/cli/server.lua Replaced synchronous exec with async exec_async, added Windows-specific server finding logic, implemented free port detection, and converted all port finding operations to async callbacks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@erroris3 erroris3 force-pushed the auto-port branch 3 times, most recently from b2b6bc4 to 104e9f0 Compare October 25, 2025 15:21
@erroris3
Copy link
Contributor Author

I have fix all the copilot suggest

@NickvanDyke
Copy link
Owner

Thanks @erroris3 ! I can check this out later today I think.

Remove polling for port when its not found the opencode to randomly assign a free port and return

I wonder if we should add a special option to opts.port for this, like "random"? I believe this approach won't find external opencodes, so perhaps it should be opt-in (and the default on Windows).

@erroris3
Copy link
Contributor Author

It nice to have but this PR is already done that automatically

@erroris3
Copy link
Contributor Author

I found out that test_port need to be in schedule. It should be fixed now

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.

2 participants