Change init.lua, such that you can directly call the livepreview api#315
Change init.lua, such that you can directly call the livepreview api#315Ren-B-7 wants to merge 15 commits intobrianhuster:mainfrom Ren-B-7:main
Conversation
Made it such that calling require("livepreview").start() has the same effect as :LivePreview start
Making outcomes more uniform, and enabling easier forming keymaps
|
Fixed the luacheck error. Added more fail safes where i was able to force uncaught errors, made the lua command for start operate the same as the vim command, without affecting any of its usual operations (we can potentially remove the now redundant code in the auto command for :LivePreview start). Also worked on one of your todo statements. I have more commits and changes in the pipeline. |
Ren-B-7
left a comment
There was a problem hiding this comment.
The port = port or 5000 should be 5500 to align with the LivePreview way, or potentially be related to the default config.
|
Added port options and changed the default 5000 to 5500 (My mistake) |
|
Done |
|
There is one edge case that doesnt get properly handled and throws an error In the rare case where using |
True, I think I have never attempted to support that use case. You can open another issue |
|
Pull request can be closed then, will work on the improvement to path |
|
Just realized that first commit is absolute garbage, all i did was add more checks, it doesnt mean that Also will have to make a small change to the Luckily it doesnt break anything and merging is still safe, but yeah i didnt test properly and the commit message is a fraud. Apologies. |
|
I dont feel like adding more commits to this pull request. As it is in a working state. And next changes will be related to a different part of the live-preview system. Recommend merging and closing. Further changes will be on a different pull-request. |
| utils.get_relative_path("/home/user/.config/nvim/lua/livepreview/utils.lua", "/home/user/.config/nvim/") | ||
| assert(relative_path == "lua/livepreview/utils.lua", "should return the relative path") | ||
| relative_path = utils.get_relative_path("/home/user/project/file.lua", "/home/user/project/file.lua") | ||
| assert(relative_path == "home/user/project/file.lua", "should return the fullpath when full_path == parent_path") |
There was a problem hiding this comment.
Sorry, I don't understand what the point of this is. Why should it return full path?
| LivePreview = { | ||
| config = vim.deepcopy(config.default), | ||
| } | ||
| local LivePreview = {} |
There was a problem hiding this comment.
LivePreview is intended to be global (see the doc)
| ---@param port number: port to run the server on | ||
| ---@return boolean? | ||
| function M.start(filepath, port) | ||
| filepath = filepath or vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":p") |
There was a problem hiding this comment.
I don't understand the point of this, doesn't nvim_buf_get_name() return full path by default? Why use yet another modifier that just convert path to full path?
|
Sorry, but after reviewing it many times, I can't understand what the point of this PR is. It seems like you are trying to bring many changes that are unrelated to each other, to a single PR, which makes it much harder for me to review. |
|
Agreed this is a few too many unrelated commits that was undocumented. Will restructure and comment reasons for changes. |
Made it such that calling require("livepreview").start() has the same effect as :LivePreview start
Making outcomes more uniform, and enabling easier forming keymaps
Now calling start(filename, 5000) is allowed along with start()