Skip to content

feat(add port options): Adding port options and file options to start and pick#322

Open
Ren-B-7 wants to merge 3 commits intobrianhuster:mainfrom
Ren-B-7:port-options
Open

feat(add port options): Adding port options and file options to start and pick#322
Ren-B-7 wants to merge 3 commits intobrianhuster:mainfrom
Ren-B-7:port-options

Conversation

@Ren-B-7
Copy link
Copy Markdown
Contributor

@Ren-B-7 Ren-B-7 commented Aug 1, 2025

Adding the ability to change port and files to the :LivePreview start and :LivePreview pick command.

pick has port as an option
start has filename and port as option in any order

Comment thread plugin/livepreview.lua
Comment thread plugin/livepreview.lua
end

vim.g.loaded_livepreview = true
local PORT_PREFIX = "++port="
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why use uppercase letters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the lua JIT, there are no constant types. Thus naming convention must be used to indicate when something is a constant. In this case the prefix is a constant.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Lua 5.1 doesn't have any convention for constant, and there is no need to invent one. Not to say that using uppercase letter for local constant is a bad idea, because you won't get LuaLS diagnostic if you mistype it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using capital letters for constants is a well-established convention in many programming languages (including C, C++, Rust, Python, Java, and JavaScript) to make them immediately distinguishable from variables whose values may change.

This improves readability and makes the intent explicit, especially in collaborative codebases. It’s not inventing a new convention, it’s applying a long standing one.

If i want to i can probably find examples in lua codebases as well.

While Lua doesn’t have an officially standardized convention for constants, borrowing this approach is not a bad idea.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not to say that using uppercase letter for local constant is a bad idea, because you won't get LuaLS diagnostic if you mistype it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LuaCAT doesn't have constant annotation, but maybe this hack works

---@type "++port="
local port_prefix = "++port="

Haven't tested though

Comment thread plugin/livepreview.lua Outdated
Comment thread plugin/livepreview.lua
if numb then
port = numb
else
vim.notify("Error: LivePreview couldnt parse ++port option. Invalid Number.", vim.log.levels.WARN)
Copy link
Copy Markdown
Owner

@brianhuster brianhuster Aug 13, 2025

Choose a reason for hiding this comment

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

Why does "Error" use "WARN" highlight?

Copy link
Copy Markdown
Contributor Author

@Ren-B-7 Ren-B-7 Aug 13, 2025

Choose a reason for hiding this comment

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

So in my head i thaught it would have fallback to the basic port option, and still open on the default port if it isnt in use. Which means its not an error, since the program didnt have to terminate early.

But when typing it out my head defaulted to Error: ...

It is your call on which you would prefer to change. Either the notification header from error to warning or the log level from vim.log.levels.WARN to ERROR in which case we would also have to think of stopping the command from executing.

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