-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `DistantConnect` command as alternative to `DistantLaunch` * Fix docker container by switching to a locked version of neovim 0.5.0
- Loading branch information
1 parent
9f8a802
commit 06de9e1
Showing
7 changed files
with
121 additions
and
7 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
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,64 @@ | ||
local lib = require('distant.lib') | ||
local log = require('distant.log') | ||
local state = require('distant.state') | ||
|
||
--- Connects to a running distance binary on the remote machine | ||
return function(opts, cb) | ||
opts = opts or {} | ||
cb = cb or function() end | ||
vim.validate({opts = {opts, 'table'}, cb = {cb, 'function'}}) | ||
log.fmt_trace('editor.connect(%s)', opts) | ||
|
||
-- Verify that we were provided a host | ||
local host_type = type(opts.host) | ||
if host_type ~= 'string' then | ||
error('opts.host should be string, but got ' .. host_type) | ||
end | ||
|
||
-- Verify that we were provided a port | ||
local port_type = type(opts.port) | ||
if port_type ~= 'number' then | ||
error('opts.port should be number, but got ' .. port_type) | ||
end | ||
|
||
local key = vim.fn.inputsecret('Enter distant key: ') | ||
if #key == 0 then | ||
error('key cannot be empty') | ||
end | ||
opts.key = key | ||
|
||
-- Load settings for the particular host | ||
state.load_settings(opts.host) | ||
opts = vim.tbl_deep_extend('keep', opts, state.settings or {}) | ||
|
||
-- Clear any pre-existing session | ||
state.session = nil | ||
|
||
local first_time = not lib.is_loaded() | ||
lib.load(function(success, res) | ||
if not success then | ||
local msg = tostring(res) | ||
vim.api.nvim_err_writeln(msg) | ||
cb(false, msg) | ||
return | ||
end | ||
|
||
-- Initialize logging of rust module | ||
if first_time then | ||
log.init_lib(res) | ||
end | ||
|
||
local session | ||
success, session = pcall(res.session.connect, opts) | ||
if not success then | ||
local msg = tostring(session) | ||
vim.api.nvim_err_writeln(msg) | ||
cb(false, msg) | ||
return | ||
end | ||
|
||
state.session = session | ||
state.sessions[opts.host] = session | ||
cb(true) | ||
end) | ||
end |
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