-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle automatically moving the server executable to nvim's dat…
…a directory
- Loading branch information
Showing
4 changed files
with
122 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local utils = require 'cord.util' | ||
|
||
local M = {} | ||
|
||
function M.get_plugin_root() | ||
local source = debug.getinfo(1, 'S').source:sub(2) | ||
return vim.fn.fnamemodify(source, ':h:h:h:h') | ||
end | ||
|
||
function M.get_target_path(name) | ||
return M.get_plugin_root() | ||
.. utils.path_sep | ||
.. 'target' | ||
.. utils.path_sep | ||
.. 'release' | ||
.. utils.path_sep | ||
.. name | ||
end | ||
|
||
function M.get_data_path() | ||
return vim.fn.stdpath 'data' .. utils.path_sep .. 'cord' | ||
end | ||
|
||
function M.get_executable_name() | ||
return utils.os_name == 'Windows' and 'cord.exe' or 'cord' | ||
end | ||
|
||
function M.get_executable() | ||
local executable_name = M.get_executable_name() | ||
local target_path = M.get_target_path(executable_name) | ||
local data_path = M.get_data_path() | ||
local executable_path = data_path .. utils.path_sep .. executable_name | ||
|
||
if utils.file_exists(target_path) then | ||
if not utils.file_exists(executable_path) then | ||
utils.mkdir(data_path) | ||
else | ||
local ok, err = utils.rm_file(executable_path) | ||
if not ok then | ||
return nil, 'Failed to remove existing executable: ' .. (err or '') | ||
end | ||
end | ||
|
||
local ok, err = utils.move_file(target_path, executable_path) | ||
if not ok then return nil, 'Failed to move executable: ' .. (err or '') end | ||
return executable_path | ||
end | ||
|
||
if utils.file_exists(executable_path) then return executable_path end | ||
|
||
return nil, 'Executable not found' | ||
end | ||
|
||
return M |