feat(add port options): Adding port options and file options to start and pick#322
feat(add port options): Adding port options and file options to start and pick#322Ren-B-7 wants to merge 3 commits intobrianhuster:mainfrom
Conversation
… and pick command
| end | ||
|
|
||
| vim.g.loaded_livepreview = true | ||
| local PORT_PREFIX = "++port=" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
LuaCAT doesn't have constant annotation, but maybe this hack works
---@type "++port="
local port_prefix = "++port="Haven't tested though
| if numb then | ||
| port = numb | ||
| else | ||
| vim.notify("Error: LivePreview couldnt parse ++port option. Invalid Number.", vim.log.levels.WARN) |
There was a problem hiding this comment.
Why does "Error" use "WARN" highlight?
There was a problem hiding this comment.
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.
Adding the ability to change port and files to the
:LivePreview startand:LivePreview pickcommand.pickhas port as an optionstarthas filename and port as option in any order