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

Error on Compiling Command-T Plugin (clang) #388

Closed
Takuzen opened this issue Mar 17, 2022 · 17 comments
Closed

Error on Compiling Command-T Plugin (clang) #388

Takuzen opened this issue Mar 17, 2022 · 17 comments

Comments

@Takuzen
Copy link

Takuzen commented Mar 17, 2022

While running the make command following this documentation I got this error message:

ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.6.Internal.sdk/usr/local/lib'

So I go to check my Xcode files:

command-t ❯ cd /../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX
MacOSX.sdk/ MacOSX11.1.sdk@

Here is what I got.

I think I'm missing MacOSX11.6.Internal.sdk so I cannot accomplish this task.

I'm not sure that my assumption is right,

if so, how can I get this specific SDK?

If not, how should I solve this to make command-t work?

@wincent
Copy link
Owner

wincent commented Mar 18, 2022

In general, I don't think you should have to mess with specific SDKs or anything. What version of Ruby are you running? The one that comes with the system? Homebrew? Something else?

@Takuzen
Copy link
Author

Takuzen commented Mar 19, 2022

I see.

I noticed I was using a bit old-fashioned 2.6.3p62 version Ruby, so I installed and switched to the latest 3.1.1 with rbenv.

command-t ❯ rbenv versions
  system
* 3.1.1 (set by /Users/takuzen/.config/nvim/pack/plugins/start/command-t/ruby/command-t/ext/command-t/.ruby-version)

Though then I run

 cd ~/.vim/bundle/command-t/ruby/command-t/ext/command-t
 ruby extconf.rb
 make

this again, there's still the same error msg:(

Next, following your doc., I run this following command in my Nvim

 :ruby puts "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"

and it says my Neovim's still linked with the old version Ruby.

So I rebuilt with Homebrew but the link doesn't change.

Do you think the linkage matters? How I can change it even the rebuild doesn't work.

Or maybe my Xcode's version is a bit outdated, which is 12.4?

P.s.

command-t ❯ ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

Even after switching to 3.1.1 and rbenv versions says it works, the above command doesn't match that, which makes me wonder. JFYI.

@wincent
Copy link
Owner

wincent commented Mar 19, 2022

Do you think the linkage matters? How I can change it even the rebuild doesn't work.

What matters is that the version numbers must match up — Command-T will be happy with an old version, or with a recent version, as long as it's the same one that Neovim itself is using.

The specific thing about the SDK is indicative of something weird and macOS related (because the Ruby headers are embedded inside the SDK, if I recall correctly). Sorry about the hassle; Command-T itself isn't doing anything strange here — it's just using mkmf (in the Ruby standard file) and trying to compile a bit of vanilla C code with no funny stuff.

After you run ruby extconf.rb, what are the contents of the generated Makefile? You might be able to remove the offending path(s) or correct it (them). It would be interesting to look around the vicinity of /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.6.Internal.sdk/usr/local/lib to see what lib directories actually are there...

@Takuzen
Copy link
Author

Takuzen commented Mar 21, 2022

I've made sure that Nvim and Terminal(inside command-t dir.) are using the same 2.6.3p62 version Ruby,
and this is what I get in Makefile originally. C.f. $ make clean is run before $ ruby extconf.rb

SHELL = /bin/sh

# V=0 quiet, V=1 verbose.  other values don't work.
V = 0
Q1 = $(V:1=)
Q = $(Q1:0=@)
ECHO1 = $(V:1=@ :)
ECHO = $(ECHO1:0=@ echo)
NULLCMD = :

#### Start of system configuration section. ####

srcdir = .
topdir = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
hdrdir = $(topdir)
arch_hdrdir = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20
PATH_SEPARATOR = :
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
rubyarchprefix = $(rubylibprefix)/$(arch)
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
exec_prefix = $(prefix)
vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
sitearchhdrdir = $(sitehdrdir)/$(sitearch)
rubyarchhdrdir = $(rubyhdrdir)/$(arch)
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
sitehdrdir = $(rubyhdrdir)/site_ruby
rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
vendorarchdir = $(vendorlibdir)/$(sitearch)
vendorlibdir = $(vendordir)/$(ruby_version)
vendordir = $(rubylibprefix)/vendor_ruby
sitearchdir = $(sitelibdir)/$(sitearch)
sitelibdir = $(sitedir)/$(ruby_version)
sitedir = $(DESTDIR)/Library/Ruby/Site
rubyarchdir = $(rubylibdir)/$(arch)
rubylibdir = $(rubylibprefix)/$(ruby_version)
sitearchincludedir = $(includedir)/$(sitearch)
archincludedir = $(includedir)/$(arch)
sitearchlibdir = $(libdir)/$(sitearch)
archlibdir = $(libdir)/$(arch)
ridir = $(datarootdir)/$(RI_BASE_NAME)
mandir = $(DESTDIR)/usr/share/man
localedir = $(datarootdir)/locale
libdir = $(exec_prefix)/lib
psdir = $(docdir)
pdfdir = $(docdir)
dvidir = $(docdir)
htmldir = $(docdir)
infodir = $(DESTDIR)/usr/share/info
docdir = $(datarootdir)/doc/$(PACKAGE)
oldincludedir = $(DESTDIR)/usr/include
includedir = $(DESTDIR)/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk$(prefix)/include
localstatedir = $(prefix)/var
sharedstatedir = $(prefix)/com
sysconfdir = $(DESTDIR)/Library/Ruby/Site
datadir = $(datarootdir)
datarootdir = $(prefix)/share
libexecdir = $(exec_prefix)/libexec
sbindir = $(exec_prefix)/sbin
bindir = $(exec_prefix)/bin
archdir = $(rubyarchdir)


CC_WRAPPER = 
CC = xcrun clang
CXX = xcrun clang++
LIBRUBY = $(LIBRUBY_SO)
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework Security -framework Foundation $(MAINLIBS)
empty =
OUTFLAG = -o $(empty)
COUTFLAG = -o $(empty)
CSRCFLAG = $(empty)

RUBY_EXTCONF_H = 
cflags   = $(optflags) $(debugflags) $(warnflags)
cxxflags = $(optflags) $(debugflags) $(warnflags)
optflags = 
debugflags = -g
warnflags = 
cppflags = 
CCDLFLAGS = 
CFLAGS   = $(CCDLFLAGS)  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -DUSE_FFI_CLOSURE_ALLOC $(ARCH_FLAG)
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
DEFS     =  -DWATCHMAN_BUILD
CPPFLAGS = -DHAVE_FCNTL_H -DHAVE_STDINT_H -DHAVE_SYS_ERRNO_H -DHAVE_SYS_SOCKET_H -DHAVE_RUBY_ST_H -DHAVE_ST_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
CXXFLAGS = $(CCDLFLAGS)  -g -Os -pipe  $(ARCH_FLAG)
ldflags  = -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.6.Internal.sdk/usr/local/lib
dldflags = $(ARCH_FLAG)             -undefined dynamic_lookup -multiply_defined suppress 
ARCH_FLAG = 
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
LDSHARED = $(CC) -dynamic -bundle
LDSHAREDXX = $(CXX) -dynamic -bundle
AR = libtool -static
EXEEXT = 

RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
RUBY_SO_NAME = ruby.2.6
RUBYW_INSTALL_NAME = 
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
RUBYW_BASE_NAME = rubyw
RUBY_BASE_NAME = ruby

arch = universal-darwin20
sitearch = $(arch)
ruby_version = 2.6.0
ruby = $(bindir)/$(RUBY_BASE_NAME)
RUBY = $(ruby)
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h

RM = rm -f
RM_RF = $(RUBY) -run -e rm -- -rf
RMDIRS = rmdir -p
MAKEDIRS = mkdir -p
INSTALL = /usr/bin/install -c
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = $(INSTALL) -m 644
COPY = cp
TOUCH = exit >

#### End of system configuration section. ####

preload = 
libpath = . $(libdir)
LIBPATH =  -L. -L$(libdir)
DEFFILE = 

CLEANFILES = mkmf.log
DISTCLEANFILES = 
DISTCLEANDIRS = 

extout = 
extout_prefix = 
target_prefix = 
LOCAL_LIBS = 
LIBS = $(LIBRUBYARG_SHARED) -lpthread   
ORIG_SRCS = ext.c heap.c match.c matcher.c watchman.c
SRCS = $(ORIG_SRCS) 
OBJS = ext.o heap.o match.o matcher.o watchman.o
HDRS = $(srcdir)/matcher.h $(srcdir)/ruby_compat.h $(srcdir)/match.h $(srcdir)/heap.h $(srcdir)/watchman.h $(srcdir)/ext.h
LOCAL_HDRS = 
TARGET = ext
TARGET_NAME = ext
TARGET_ENTRY = Init_$(TARGET_NAME)
DLLIB = $(TARGET).bundle
EXTSTATIC = 
STATIC_LIB = 

TIMESTAMP_DIR = .
BINDIR        = $(bindir)
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR    = $(sitelibdir)$(target_prefix)
RUBYARCHDIR   = $(sitearchdir)$(target_prefix)
HDRDIR        = $(rubyhdrdir)/ruby$(target_prefix)
ARCHHDRDIR    = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
TARGET_SO_DIR =
TARGET_SO     = $(TARGET_SO_DIR)$(DLLIB)
CLEANLIBS     = $(TARGET_SO) 
CLEANOBJS     = *.o  *.bak

all:    $(DLLIB)
static: $(STATIC_LIB)
.PHONY: all install static install-so install-rb
.PHONY: clean clean-so clean-static clean-rb

clean-static::
clean-rb-default::
clean-rb::
clean-so::
clean: clean-so clean-static clean-rb-default clean-rb
		-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time

distclean-rb-default::
distclean-rb::
distclean-so::
distclean-static::
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
		-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
		-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
		-$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true

realclean: distclean
install: install-so install-rb

install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.time
	$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
clean-static::
	-$(Q)$(RM) $(STATIC_LIB)
install-rb: pre-install-rb do-install-rb install-rb-default
install-rb-default: pre-install-rb-default do-install-rb-default
pre-install-rb: Makefile
pre-install-rb-default: Makefile
do-install-rb:
do-install-rb-default:
pre-install-rb-default:
	@$(NULLCMD)
$(TIMESTAMP_DIR)/.sitearchdir.time:
	$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
	$(Q) $(TOUCH) $@

site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb

.SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S

.cc.o:
	$(ECHO) compiling $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.cc.S:
	$(ECHO) translating $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

.mm.o:
	$(ECHO) compiling $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.mm.S:
	$(ECHO) translating $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

.cxx.o:
	$(ECHO) compiling $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.cxx.S:
	$(ECHO) translating $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

.cpp.o:
	$(ECHO) compiling $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.cpp.S:
	$(ECHO) translating $(<)
	$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

.c.o:
	$(ECHO) compiling $(<)
	$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.c.S:
	$(ECHO) translating $(<)
	$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

.m.o:
	$(ECHO) compiling $(<)
	$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

.m.S:
	$(ECHO) translating $(<)
	$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<

$(TARGET_SO): $(OBJS) Makefile
	$(ECHO) linking shared-object $(DLLIB)
	-$(Q)$(RM) $(@)
	$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
	$(Q) $(POSTLINK)



###
# Copyright 2010-present Greg Hurrell. All rights reserved.
# Licensed under the terms of the BSD 2-clause license.

CFLAGS += -Wall -Wextra -Wno-unused-parameter

ifdef DEBUG
CFLAGS += -DDEBUG
endif

@Takuzen
Copy link
Author

Takuzen commented Mar 21, 2022

I corrected l. 91 as following.

lldflags  = -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib

Then I run,

command-t ❯ make                                                                                                              main ~/.config/nvim/pack/plugins/start/command-t/ruby/command-t/ext/command-t
compiling ext.c
compiling heap.c
compiling match.c
compiling matcher.c
compiling watchman.c
linking shared-object ext.bundle
command-t ❯ 

so it seemed worked.

However when I type :CommandT in Nvim command, I still got the following error msg., and I noticed which is the same one with #385 coincidentally.

Error detected while processing /Users/takuzen/.config/nvim/pack/plugins/start/command-t/autoload/commandt.vim:                                                                                            
line  230:
NameError: uninitialized constant CommandT
Error detected while processing function commandt#FileFinder:
line    2:
NoMethodError: undefined method `show_file_finder' for nil:NilClass

P.s.
As you mentioned, I went to look what's inside of
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
, and I found a bunch of .tbd files, which is novel for me. Thanks.

@wincent
Copy link
Owner

wincent commented Mar 22, 2022

However when I type :CommandT in Nvim command, I still got the following error msg., and I noticed which is the same one with #385 coincidentally.

It may be just that (a coincidence)... it's going to display something like that whenever there's a total failure to load the Ruby module. You can see the code that is doing that here. One way to try and see what's happening would be to run some of those commands by hand. For example:

:ruby require "command-t"

If that fails the first time around with LoadError: cannot load such file (which is normal), you can modify the LOAD_PATH and try again. First, take a look at what is in the LOAD_PATH:

:ruby p LOAD_PATH

and then try modifying it (obviously substituting the actual paths to your ext and lib directories):

:ruby $LOAD_PATH << "/Users/wincent/.config/nvim/pack/bundle/opt/command-t/ruby/command-t/ext"
:ruby $LOAD_PATH << "/Users/wincent/.config/nvim/pack/bundle/opt/command-t/ruby/command-t/lib"
:ruby require "command-t"

If that works, it may be that Command-T's plug-in directory isn't in your rtp... What's the value output of :set rtp?.

I found a bunch of .tbd files, which is novel for me.

Me too. 😁

@Takuzen
Copy link
Author

Takuzen commented Mar 24, 2022

P.S. (Pre-Script)
Following your advice I tinkered around, :CommandT worked once.
However then I dropped my guard and closed Nvim, now I'm unable to make it work again, even repeating what all I did.
I thought because I happened to run ruby require 'command-t/ext' during reading here, but there's no repeatability.

--

After adding $LOAD_PATHs, :ruby require "command-t" successfully executed.
But now there's another error msg. when run :CommandT

Error detected while processing function commandt#FileFinder:
line 2:
NoMethodError: undefined method `show_file_finder` for nil:NilClass

I also did :set rtp and even added potential paths to it. With configuring, it looks as followed.

runtimepath=~/.config/nvim,~/.config/nvim/pack/*/start/*,/etc/xdg/nvim,~/.local/share/nvim/site,/us
r/local/share/nvim/site,/usr/share/nvim/site,/usr/local/Cellar/neovim/0.6.1/share/nvim/runtime,/usr/l
ocal/Cellar/neovim/0.6.1/share/nvim/runtime/pack/dist/opt/matchit,/usr/local/Cellar/neovim/0.6.1/lib/
nvim,/usr/share/nvim/site/after,/usr/local/share/nvim/site/after,~/.local/share/nvim/site/after,/etc/
xdg/nvim/after,~/.config/nvim/after,~/.config/nvim/pack/plugins/start/command-t/,~/.config/nvim/pack/
plugins/start/command-t/ruby/command-t/ext/,~/.config/nvim/pack/plugins/start/command-t/ruby/command-
t/lib/,~/.config/nvim/pack/plugins/start/command-t/ruby/command-t

My $LOAD_PATH is like this.

["/Library/Ruby/Gems/2.6.0/gems/did_you_mean-1.3.0/lib", "/Library/Ruby/Gems/2.6.0/gems/msgpack-1.4.5
/lib", "/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/msgpack-1.4.5", "/Library/Ruby/
Gems/2.6.0/gems/multi_json-1.15.0/lib", "/Library/Ruby/Gems/2.6.0/gems/neovim-0.9.0/lib", "/Library/R
uby/Site/2.6.0", (...omitting...) ,  "/Users/takuzen/.config/nvi
m/pack/plugins/start/command-t/ruby/command-t/ext", "/Users/takuzen/.config/nvim/pack/plugins/start/c
ommand-t/ruby/command-t/lib"]

--

In addition to this, I wonder where and how I should write these $LOAD_PATH and rtp config., so I can make it reflected permanently. (I set my config. of Nvim in .config/nvim/lua/config.lua and required from init.lua which exists in one previous dir.

@wincent
Copy link
Owner

wincent commented Mar 24, 2022

The thing is, you shouldn't have to manually mess with your 'rtp' or $LOAD_PATH; I was just hoping that it would help us debug why Command-T can't seem to actually require any of the Ruby files even after you got the extension built.

After adding $LOAD_PATHs, :ruby require "command-t" successfully executed.
But now there's another error msg. when run :CommandT

You probably need this after the require:

$command_t = CommandT::Controller.new

But like I said, you shouldn't have to be doing any of that... the code I linked to in my previous comment is supposed to require Command-T, and if that doesn't work, update the $LOAD_PATH based on what's in your 'rtp' before trying again, and then setting up the $command_t global.

@Takuzen
Copy link
Author

Takuzen commented Mar 24, 2022

At last, I got how to make command-t work temporarily!

To sum up and jog it down for other users of this plugin facing the same problem, I fixed by running following commands in Nvim.

:ruby $LOAD_PATH << '/Users/takuzen/.config/nvim/pack/plugins/start/command-t/ruby/command-t/ext'
:ruby $LOAD_PATH << '/Users/takuzen/.config/nvim/pack/plugins/start/command-t/ruby/command-t/lib'
:ruby require 'command-t'
:ruby $command_t = CommandT::Controller.new

Before closing this issue, my last question is where to put these 4 lines,
so I can leave these configurations permanent?

+α:
Unexpectedly, I accepted in popup window to search through all my photos and now there's a warning says that

Warning: maximum file  limit reached

Increase it by setting a higher value in $MYVIMRC; eg:
	let g:CommandTMaxFiles=200000
Or suppress this warning by setting:
	let g:CommandTSuppressMaxFilesWarning=1
For best performance, consider using a fast scanner; 

Is there a way to set command-t not to go look into my photos?

@wincent
Copy link
Owner

wincent commented Mar 24, 2022

Before closing this issue, my last question is where to put these 4 lines,
so I can leave these configurations permanent?

Well, as I said, you shouldn't have to do this. The question is, why isn't the code in the plug-in doing it already on your behalf? I obviously can't reproduce the problem you've reported here, but if I could, I would want to put logging statements in there to figure out exactly where it is failing...

Having said that, if you just want to dump this somewhere and move on, you could put it in your vimrc after the plugin has loaded. Given that the set-up is supposed to happen in response to autoloading, you might want to trigger that first with :call commandt#Load().

Unexpectedly, I accepted in popup window to search through all my photos and now there's a warning says that

That will happen if you run Vim in a current working directory that is or contains (directly or indirectly) your photos directory. All of the file scanners work in this way — they recursively search from the current directory and find whatever you have in there. So, the "workaround" is to not use Command-T in directories where you don't want it searching. The tip about CommandTMaxFiles is for use cases that really do involve lots of files, like large monorepos; if that's your situation, then using something like the Watchman scanner is going to be a lot faster anyway (as it maintains an always up-to-date in-memory cache of what's on the filesystem in a given directory hierarchy).

@yujinyuz
Copy link

I was having the same problem and I managed to get this working by having this in my config

use {
    'wincent/command-t',
    event = 'VimEnter',
}

Previously it was just

use { 'wincent/command-t' }

I'm currently using ruby 2.7.5.

I do have some problems -- when opening a file, the cursor gets placed at the start of the file (as if pressing gg)..

I have an autocommand that jumps to the last edit position -- this does happen but after half a second, it goes back to the top when a file is opened via CommandT. Is this intentional?

Also, is it possible to use other find commands such as rg --files or fd ?

@wincent
Copy link
Owner

wincent commented Apr 30, 2022

I have an autocommand that jumps to the last edit position -- this does happen but after half a second, it goes back to the top when a file is opened via CommandT. Is this intentional?

Nope, @yujinyuz. Unless you configure it otherwise (eg. via g:CommandTAcceptSelectionCommand) Command-T opens files as seen here:

  1. command = options[:command] || default_open_command
  2. VIM::get_string('g:CommandTAcceptSelectionCommand') || 'CommandTOpen edit'
  3. ::VIM::command "silent #{command} #{selection}"

And CommandTOpen is defined here:

command! -nargs=+ CommandTOpen call commandt#GotoOrOpen(<q-args>)

Calling commandt#GotoOrOpen, defined here:

function! commandt#GotoOrOpen(command_and_args) abort
let l:command_and_args = split(a:command_and_args, '\v^\w+ \zs')
let l:command = l:command_and_args[0]
let l:file = l:command_and_args[1]
" `bufwinnr()` doesn't see windows in other tabs, meaning we open them again
" instead of switching to the other tab; but `bufname()` sees hidden
" buffers, and if we try to open one of those, we get an unwanted split.
if s:BufVisible(l:file)
execute 'sbuffer ' . l:file
else
execute l:command . l:file
endif
endfunction

Which basically all boils down to this:

:edit {file}

So, if you see the cursor jumping around after all that, it's probably some other plugin, autocommand, or other configuration that is making it do so.

@yujinyuz
Copy link

yujinyuz commented May 1, 2022

@wincent thanks for the response! It does seem to be caused by this plugin: https://github.com/luukvbaal/stabilize.nvim

Adding it to the ignore list of stabilize.nvim doesn't seem to fix the issue. It doesn't happen when using file finders such as fzf-lua or telescope, and also the normal :edit {file}

@wincent
Copy link
Owner

wincent commented May 2, 2022

@yujinyuz I imagine it doesn't affect plugins like Telescope because they (probably) use floating windows whereas Command-T was written long before floating windows existed and so uses normal windows. I'll rewrite it one day to use the newer APIs, but not anytime soon, as it will be a huge undertaking (effectively equivalent to porting from Ruby to Lua).

@yujinyuz
Copy link

yujinyuz commented May 2, 2022

@wincent That might be the case.

Thanks for your answers! I'll be looking forward to the lua rewrite!

@AdeAttwood
Copy link

Hi all, I was having a play and I also run into this issue. At first had the plugin in pack/bundle/start and it was autoloading, this was when I was having the issue. I first manually loaded the plugin as per the comments, that got the plugin working.

:ruby $LOAD_PATH << '~/.config/nvim/pack/bundle/start/command-t/ruby/command-t/ext'
....

I then moved it into pack/bundle/opt and added packadd! command-t to the RC, and this sorted all the issues. This leads me to think it's an issue with the loading order.

Hope this helps, and thanks for all the work 👍

@wincent
Copy link
Owner

wincent commented Aug 26, 2022

Given the big rewrite for v6.0.x, I'm closing all older issues as there is unlikely to be anything significant happening on the 5-x-devel branch from here on1. Feedback issue for 6.0.x is here:

Footnotes

  1. Patches and PRs would be welcome, but my personal efforts are going to be directed towards main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants