Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running on Mac OS X #23

Closed
scotts777 opened this issue Apr 8, 2019 · 19 comments
Closed

Running on Mac OS X #23

scotts777 opened this issue Apr 8, 2019 · 19 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@scotts777
Copy link

scotts777 commented Apr 8, 2019

I am attempting to run Conjure through nvim in the mac's Terminal bash, but I am getting an error when doing ConjureAdd. It probably isn't a bug and more likely it is that I am new to nvim and doing something wrong. But this plugin looks so good that it is finally pushing me to the vim side. I will understand if you deem it an issue with my setup and not a bug then please just close it.

I added this to my init.vim
`call plug#begin('~/.local/share/nvim/plugged')

Plug 'Olical/conjure', { 'tag': 'v0.8.2', 'do': 'make compile', 'for': 'clojure', 'on': 'ConjureAdd' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

" Initialize plugin system
call plug#end()`

I did a successful PlugInstall. I am running a prepl in another Terminal that I can successfully connect to with nc localhost port. However, in nvim when I do a ConjureAdd {:tag :dev, :port 40404}, it opens a vertical split window, but I get this error message:

Error from thread 'RPC message handler': #error {                                                                                                 
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [clojure.lang.Numbers ops Numbers.java 1068]}]
 :trace
 [[clojure.lang.Numbers ops Numbers.java 1068]
  [clojure.lang.Numbers gt Numbers.java 259]
  [conjure.ui$append invokeStatic ui.clj 48]
  [conjure.ui$info invokeStatic ui.clj 68]
  [conjure.prepl$add_BANG_ invokeStatic prepl.clj 102]
  [conjure.main$fn__12976 invokeStatic main.clj 34]
  [conjure.main$fn__12976 invoke main.clj 33]
  [clojure.lang.MultiFn invoke MultiFn.java 229]
  [conjure.rpc$init$fn__11386 invoke rpc.clj 168]
  [clojure.core$binding_conveyor_fn$fn__5756 invoke core.clj 2030]
  [clojure.lang.AFn call AFn.java 18]
  [java.util.concurrent.FutureTask run FutureTask.java 264]
  [java.util.concurrent.ThreadPoolExecutor runWorker ThreadPoolExecutor.java 1128]
  [java.util.concurrent.ThreadPoolExecutor$Worker run ThreadPoolExecutor.java 628]
  [java.lang.Thread run Thread.java 835]]}

When I quit out of nvim, I see this message: Conjure exited, restarting

Thanks for any assistance you may provide

@Olical
Copy link
Owner

Olical commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019 via email

@Olical Olical self-assigned this Apr 9, 2019
@Olical Olical added the bug Something isn't working label Apr 9, 2019
@Olical Olical added this to the v1.0.0 milestone Apr 9, 2019
@Olical
Copy link
Owner

Olical commented Apr 9, 2019

I am informed by the OSX dev to my right that it does have a /tmp, so it's probably not the /tmp/conjure.cljc buffer not being created. I would guess it's a setting in Neovim like "new lines at end of empty files" or something so the line count is reporting nil instead of 0.

Your logs will prove this though, every RPC call gets written there when it's enabled so we'll see what Conjure asked and what it got back from Neovim 😃 should be an easy fix.

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019

I really appreciate you taking the time to look into this. Yes the /tmp exists and I can see the buffer in the split.
NVIM v0.3.4
Build type: Release
LuaJIT 2.0.5

Here is the log output.

INFO [conjure.dev:17] - Logging initialised
INFO [conjure.rpc:132] - Starting RPC loops
TRACE [conjure.rpc:162] - Received RPC message: {:type :notify, :method :add, :params ["{:tag :dev, :port 40404}"]}
INFO [conjure.prepl:110] - Adding :dev 127.0.0.1 40404
TRACE [conjure.rpc:151] - Sending RPC message: {:type :request, :id 1, :method :nvim-execute-lua, :params ["return require('conjure').upsert_log(...)" ("/tmp/conjure.cljc" 40 false false)]}
TRACE [conjure.rpc:120] - Sent request, awaiting response: {:type :request, :id 1, :method :nvim-execute-lua, :params ["return require('conjure').upsert_log(...)" ("/tmp/conjure.cljc" 40 false false)]}
TRACE [conjure.rpc:154] - Sent!
TRACE [conjure.rpc:162] - Received RPC message: {:type :response, :id 1, :error nil, :result nil}
TRACE [conjure.rpc:26] - Received response: {:type :response, :id 1, :error nil, :result nil}
TRACE [conjure.rpc:120] - Sent request, awaiting response: {:type :request, :id 1, :method :nvim-buf-line-count, :params [nil]}
TRACE [conjure.rpc:151] - Sending RPC message: {:type :request, :id 1, :method :nvim-buf-line-count, :params [nil]}
TRACE [conjure.rpc:154] - Sent!
TRACE [conjure.rpc:162] - Received RPC message: {:type :response, :id 1, :error [0 "Wrong type for argument 1, expecting Buffer"], :result nil}
TRACE [conjure.rpc:26] - Received response: {:type :response, :id 1, :error [0 "Wrong type for argument 1, expecting Buffer"], :result nil}
ERROR [conjure.nvim:12] - Error while making nvim call {:method :nvim-buf-line-count, :params [nil]} -> {:error [0 "Wrong type for argument 1, expecting Buffer"], :result nil}
ERROR [conjure.rpc:?] - Error from thread 'RPC message handler': java.lang.NullPointerException

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Not a problem! You're helping me make a better tool by reporting it!

Received RPC message: {:type :response, :id 1, :error [0 "Wrong type for argument 1, expecting Buffer"], :result nil}

Hmm, that'll be the one. So I wonder why the buffer is nil, that should be the reference to the log buffer that comes back from the Lua code. A bit convoluted I know, but I have my reasons 😅

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

This means that one of these is returning nil when it should be returning the buffer ID:

conjure/lua/conjure.lua

Lines 3 to 49 in 68c2dac

-- Find the log window and buffer if they exist.
local function find_log (log_buf_name)
local tabpage = vim.api.nvim_get_current_tabpage()
local wins = vim.api.nvim_tabpage_list_wins(tabpage)
for _, win in ipairs(wins) do
local buf = vim.api.nvim_win_get_buf(win)
local buf_name = vim.api.nvim_buf_get_name(buf)
if buf_name == log_buf_name then
return {win = win, buf = buf}
end
end
return nil
end
-- Find or create (and then find again) the log window and buffer.
function conjure.upsert_log (log_buf_name, width, focus, resize)
local result = find_log(log_buf_name)
if result then
if focus == true then
vim.api.nvim_set_current_win(result.win)
end
if resize == true then
vim.api.nvim_win_set_width(result.win, width)
end
return result
else
vim.api.nvim_command("botright " .. width .. "vsplit " .. log_buf_name)
vim.api.nvim_command("setlocal winfixwidth")
vim.api.nvim_command("setlocal buftype=nofile")
vim.api.nvim_command("setlocal bufhidden=hide")
vim.api.nvim_command("setlocal nowrap")
vim.api.nvim_command("setlocal noswapfile")
vim.api.nvim_command("setlocal nobuflisted")
vim.api.nvim_command("setlocal nospell")
if focus ~= true then
vim.api.nvim_command("wincmd p")
end
return find_log(log_buf_name)
end
end

And you won't see it in the buffer list, it's a special hidden thing that can't be accidentally written to a file or clutter your buffer list etc. As long as you can see the window with the buffer name set to /tmp/conjure.cljc that's enough proof for me.

So why the nil... I do wonder if it could be some sort of race condition that isn't present on my machine.

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Is there anything else interesting / scaring in :messages? Like possibly related to these commands?

conjure/lua/conjure.lua

Lines 34 to 41 in 68c2dac

vim.api.nvim_command("botright " .. width .. "vsplit " .. log_buf_name)
vim.api.nvim_command("setlocal winfixwidth")
vim.api.nvim_command("setlocal buftype=nofile")
vim.api.nvim_command("setlocal bufhidden=hide")
vim.api.nvim_command("setlocal nowrap")
vim.api.nvim_command("setlocal noswapfile")
vim.api.nvim_command("setlocal nobuflisted")
vim.api.nvim_command("setlocal nospell")

I wonder if one of those could be failing and causing the Lua function to return nil after mostly creating the buffer.

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Just out of interest, swapping your vim-plug call to 'commit': 'ecfb1c09e5e8258036dfb30f3927e33488533e98' doesn't help, right? I just fixed the requiring of Compliment if you don't have it in your project.

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Okay, I'm out of lunch time now but will have a look ASAP. Just need to try and repo which seems hard 😬 I'd be surprised if it was OSX specific but maybe! Do you have other plugins / settings or is it a blank neovim? I might try to repro it in a bare bones neovim environment.

Latest commit is better too, prints out the full stack trace when something goes wrong 063c29b54459a326b5ff244685dd2765bcd19adf.

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

I'll try a stripped down neovim soon and see if I can reproduce it there. I would put money on this being some weird setting that most people have set that might not be set by default. It's so odd how the Lua, Clojure and VimL is all up and talking to each other but still manages to get a nil where it shouldn't.

That nil means it couldn't find the Conjure buffer/window. This could be a race condition (ahhhhh) or it could just be a setting on the buffer / neovim instance. I'll work it out 😄

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Ah! OSX's /tmp is a symlink if I'm not mistaken to /private/tmp or something of the sort. Could you confirm that the Conjure buffer isn't in the place I expect by running :echo expand("%:p")? I bet it's not /tmp/conjure.cljc. I'll start looking for a better solution that should work for you now, if that is indeed the problem.

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

If my hunch is correct, this commit should fix it! If you get a chance to give it a go let me know how it goes 😄 3918cbc

@scotts777
Copy link
Author

scotts777 commented Apr 9, 2019 via email

@Olical
Copy link
Owner

Olical commented Apr 9, 2019

Well that's weird... definitely some strange path things going on here but glad the hunch was essentially correct. I think different functions in nvim are reporting different paths depending on your dir being in a symlink or not 😬

But yay! It's fixed! Thank you for your thanks, there's a lot more to do before I'm relatively happy, I hope you get a lot of value out of my work 😄

Success

@Olical Olical closed this as completed Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants