Skip to content

Conversation

@cat-pat
Copy link

@cat-pat cat-pat commented Oct 1, 2024

Adds a configurable default static port instead of having it be random on each launch, useful for having a bookmark you can quickly refer to when in use

Default is set to a random but memorable 32423 which can be changed to any other port by the user using the markdown.preview.port config options

@El-Wumbus
Copy link

El-Wumbus commented Dec 2, 2025

How would the port be changed if the aurelius::Server is bound to the default port prior to receiving the updated configuration? At first, settings is set to Default::default(), and is only updated later by the LSP client. The server would need to be restarted after the configuration changed, which I don't see happening here.

I've implemented a fix by restarting the server upon a port change:

// fn handle_notification(...) {
//...

info!("changed configuration: {:?}", settings);

let old_auto_setting = self.settings.auto;
let restart_server = self.settings.port != settings.port;                  

self.settings = settings;

if restart_server {
    match aurelius::Server::bind(format!("localhost:{}", self.settings.port)) {
        Ok(server) => {
            // NOTE: `Drop`ing `aurelius::Server` is enough to close everything.
            *self.markdown_server.lock().unwrap() = server;   
            info!("Restarted markdown server on localhost:{}", self.settings.port);
        }
        Err(e) => {
            error!("Failed to restart markdown server on localhost:{}: {}", self.settings.port, e);
        }
    }
}

// ...

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