GithubHelp home page GithubHelp logo

vim-classpath's Introduction

classpath.vim

This plugin sets the 'path' for JVM languages to match the class path of your current Java project. This lets commands like :find and gf work as designed. I originally wrote it for Clojure, but I see no reason why it wouldn't be handy for other languages as well.

Currently, Maven and Leiningen are supported, with a fallback to $CLASSPATH if neither applies. Open an issue if you have ideas for supporting another project management system.

Included is a :Java command, which executes java (or $JAVA_CMD) with the current buffer's 'path' as the class path.

Installation

If you don't have a preferred installation method, I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/tpope/vim-classpath.git

Once help tags have been generated, you can view the manual with :help classpath.

FAQ

Why does it take so long for Vim to startup?

The short answer is because the JVM is slow.

The first time you load a Clojure file from any given project, classpath.vim sets about trying to determine your class path, leveraging either lein classpath or mvn dependency:build-classpath. This takes a couple of seconds or so in the best case scenario, and potentially much longer if it decides to hit the network.

Because the class path is oh-so-expensive to retrieve, classpath.vim caches it in ~/.cache/vim/classpath. The cache is expired when the timestamp on project.clj or pom.xml changes.

Contributing

See the contribution guidelines for pathogen.vim.

Self-Promotion

Like classpath.vim? Follow the repository on GitHub. And if you're feeling especially charitable, follow tpope on Twitter and GitHub.

License

Copyright ยฉ Tim Pope. Distributed under the same terms as Vim itself. See :help license.

vim-classpath's People

Contributors

fwy avatar gavocanov avatar tpope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-classpath's Issues

Is it possible to start vim with vim-classpath disabled, then optionally enable it?

This may well be a daft question - I can see that using Pathogen it's possible to disable plugins to prevent them being loaded using pathogen_disabled, but not how to then load them later on if you decide you want them after all. Is there a way to do this either at the pathogen or vim-classpath level?

Reason: I want to be able to load up vim without waiting for the JVM if I want to make a quick edit, and I'm happy to sacrifice being able to use fireplace stuff in those cases. If I'm spending more time in the project then I do want classpath enabled and the load time isn't such a big deal.

Option to get classpath offline

In case a maven repository is down it is impossible to open buffer without killing. It could be helpful to provide an option to user to set offline mode and use lein -o classpath in the plugin, which is significantly faster in general too.

lein classpath should be run with ! not system()

I'm having problems to get vim-classpath to work with GVIM @ Ubuntu 12.04. This can be easily fixed with this diff:

index f578405..8749612 100644
--- a/autoload/classpath.vim
+++ b/autoload/classpath.vim
@@ -123,7 +123,9 @@ function! classpath#detect(...) abort
       let dir = getcwd()
       try
         execute cd . fnameescape(root)
-        let out = system(cmd)
+        redir => out
+        exec 'silent !' cmd
+        redir END
       finally
         execute cd . fnameescape(dir)
       endtry`

There are some differences in how shell commands are run which precludes lein classpath to return something useful. IIRC this also depends on the OS and the version of (G)VIM one uses. I cannot currently remember the details though.

Error with scala buffer

Why is vim classpath messing around with scala files? I did
cd ~/.vim/pathogen ( since pathogen#infect('pathogen/{}') )
git clone git://github.com/tpope/vim-fireplace.git
git clone git://github.com/tpope/vim-classpath.git
vim core/src/main/scala/spark/api/python/PythonPartitioner.scala

"core/src/main/scala/spark/api/python/PythonPartitioner.scala" 48L, 1442C

Couldn't determine class path.

[INFO] Scanning for projects...

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD ERROR

[INFO] ------------------------------------------------------------------------

[INFO] Error resolving version for 'net.alchim31.maven:scala-maven-plugin': Plugin requires Maven version 3.0

[INFO] ------------------------------------------------------------------------

[INFO] For more information, run Maven with the -e switch

[INFO] ------------------------------------------------------------------------

[INFO] Total time: < 1 second

[INFO] Finished at: Fri Feb 22 16:48:39 IST 2013

[INFO] Final Memory: 5M/239M

[INFO] ------------------------------------------------------------------------

gvim hangs

Sometimes, when opening a clojure file, gvim hangs forever waiting for a response from this plugin.

Using strace I can see that gvim is stuck on wait4 for a specific pid. The process is definitely lein classpath:

noahlz   13643 13630  0 23:50 ?        00:00:00 bash /home/noahlz/bin/drip -client -Xbootclasspath/a:/home/noahlz/.lein/self-installs/leiningen-2.1.2-standalone.jar -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dfile.encoding=UTF-8 -Dmaven.wagon.http.ssl.easy=false -Dleiningen.original.pwd=/home/noahlz/projects/fireplace-nyc -Dleiningen.script=/home/noahlz/bin/../java/leiningen/lein -classpath :/home/noahlz/.lein/self-installs/leiningen-2.1.2-standalone.jar clojure.main -m leiningen.core.main classpath

When I kill the process, the following displays in vim:

Couldn't determine class path.
/home/noahlz/bin/lein: line 313: 13643 Terminated              "$LEIN_JAVA_CMD" -client "${BOOTCL
ASSPATH[@]}" $LEIN_JVM_OPTS -Dfile.encoding=UTF-8 -Dmaven.wagon.http.ssl.easy=false -Dleiningen.o
riginal.pwd="$ORIGINAL_PWD" -Dleiningen.script="$SCRIPT" -classpath "$CLASSPATH" clojure.main -m
leiningen.core.main "$@"     

This is the gvim/vim that comes with Ubuntu 12.04. I launch gvim from tmux so I can benefit from vim-dispatch.

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:22:36)
Included patches: 1-429
Modified by [email protected]
Compiled by buildd@
Huge version with GTK2-GNOME GUI.  Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent +clientserver
+clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope
+cursorbind +cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic +emacs_tags +eval
+ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork()
+gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak
+lispindent +listcmds +localmap +lua +menu +mksession +modify_fname +mouse +mouseshape
+mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +mouse_urxvt
+multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra +perl +persistent_undo +postscript
+printer +profile +python -python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static
-tag_any_white +tcl +terminfo +termresponse +textobjects +title +toolbar +user_commands
+vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows
+writebackup +X11 -xfontset +xim +xsmp_interact +xterm_clipboard -xterm_save   

Run maven et al. in jobs if available

This would greatly alleviate startuptime costs when jobs are available, at the penalty of not syncing path with the results until after the job completes.

Thoughts? I think I can work up a start.

How to run this plugin?

Sorry! my English is poor.I hope you can understand.
I don't know how the plugin works.I don't know the specific function of this plugin.I want to set the classpath automatically for java.For example:I set the classpath to demo1, and then compile,run.
when I worked demo2,I should change classpath to demo2.This is too much trouble.
I am not sure if your plugin can help me.If your plugin can not help me.
I hope you can recommend other plugins to me. Thank You!!!

The question:
what is meaning to this code ' \ command! -buffer -nargs=+ -complete=file Java execute '!'.classpath#java_cmd().' '.'.
How to run it.I set 'echo 111111111',but it do not run.

gf doesn't work properly with maven project

I've noticed that incorrect source path (with wrong number of asterisks) is inserted in
front of path variable (in autoload/classpath.vim). It looks like this currently:

 83       let base = escape(root.sep.'src'.sep.'*'.sep.'*', ', ') . ','

and I think it should be

 83       let base = escape(root.sep.'src'.sep.'*'.sep.'**', ', ') . ','

to cover subfolder of packages.

Missing *cd trailing space in classpath#detect

I just found that commit 34d4cdf (Jun 22) introduced a bug into the classpath#detect function.

The 'cd' variable requires a trailing space to be processed correctly by the shell, but this space was removed by the commit when the assignment statement was last changed.

I fixed it by restoring the trailing space.

vim-classpath should keep manually set path from vimrc.

I manually set path=$PWD/** in my .vimrc to ensure that :find works as I expect it to. With vim-classpath, navigating to another file resets my path and :find does not work as expected. Can vim-classpath simply append to the manually set path?

For example, opening vim in my project root without specifying a file allows me to :find somef<Tab> just fine. However, opening any file in my project changes the path, so calling :find anoth<Tab> does not list all of the files that it should (all of the files in the path $PWD/**.

Clojure CLI support (deps.edn)

clojure -Spath returns exactly the same thing that lein classpath

lein with-profiles dev,cljs classpath will became clojure -A:dev:cljs -Spath

I can answer any other clojure-related question.

[FEAT] Support Bazel

In polyglot monorepos it is a royal pain that I cannot have plugins like coc-java correctly set the classpath for the java language server since there is not a pom.xml or a gradle.build at the root of the project.

My team uses Bazel and there are a number of us that strictly use vim since there is so much context switching between languages. If possible, it would be fantastic to get first class support for Bazel.

Happy to contribute if you can provide some bootstrap pointers ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.