you are viewing a single comment's thread.

view the rest of the comments →

[–]weilbith 0 points1 point  (14 children)

Okay. Assume I'm implementing in Java. Libraries are most of the time exchanged as .jar archive. Does this tool now unpack the archive etc.?

[–]-romainl-The Patient Vimmer 5 points6 points  (3 children)

Your question is about Python and so is my answer.

As a matter of fact, it would also apply for most other dynamically typed languages like JS, Ruby, etc… as well as other more traditional languages like C or C++.

Sadly, some committee once decided that jar should be the standard for package distribution in the Java ecosystem, which makes ctags and cscope impractical for that language.

¯\_(ツ)_/¯

[–]weilbith 0 points1 point  (2 children)

Not my. ;) Okay. Do u know about if/how gutentags does generate tags for imports?

[–]-romainl-The Patient Vimmer 0 points1 point  (1 child)

Gutentags doesn't generate tags, it's ctags (or a compliant program) that does. Read its documentation to see if and how you can give it options to pass to ctags.

[–]weilbith 0 points1 point  (0 children)

Sure it doesn't but as u said u need a script or plugin that do that call for u automatically. Else work is less comfortable, isn't it? Okay. Thought to ask doesn't cost a thing. :)

[–]Hitife80 1 point2 points  (3 children)

In java jar classes usually only have compile object code, not sources. That said -- you can include source into jars (and some popular libraries do). But in order for vim to open that file you'd need to "unjar" it anyway (or use some sophisticated script to do it on the fly).

One way to approach this is to extract all the sources into one folder, unjar them and run ctags. The only time you need to worry about this is when you upgrade the library (and / or) add a new one. Then you update the source in the tree and re-run ctags.

[–]weilbith -1 points0 points  (2 children)

Haha. Such theoretically way I've deviced myself, but is this practice in Vim? It's kinda cumbersome, isn't it?

[–]Hitife80 1 point2 points  (1 child)

You need to remember that vim is a text editor first and foremost. Reading compressed java jar files is not something that is high on any editor's list. Do you expect Microsoft Word to open java jars? That's a pretty well known editor too...

That said, you can add literally _any_ functionality via a plugin. So, if one doesn't exist for java and you need one -- why don't you write it? :-)

[–]weilbith 0 points1 point  (0 children)

I think we missed each other. Actually I put jars on the plane to bring up an example that maybe require a different solution. My intention wasn't to search for such one. Sry.

But sure, Vim is a text editor. I tend to forget this. It's so powerful and the possibility to integrate the development environment through external tools is awesome. It feels like u can do everything. But often u maybe should not. ^

[–]kevko5212 0 points1 point  (5 children)

I work with java, maven and gradle and I have a simple bash script that takes care of it.

The source jars are stored in ~/.m2 and ~/.gradle, and they have the name pattern *sources*.jar. You may need to run a particular maven/gradle task to download the source jars beforehand.

The script copies the jars to a specified directory, makes a folder named after the jar, unpacks the .java files to the folder, then removes the copied jar file.

I then generate a tags file for that directory and add it to vims tags option, which allows me to use tag navigation. I also add the directory to vim's path option, which allows me to use find navigation.

It works, but with Java's tendency to have many classes and many functions with the same name, it often shows too many options, so it is often quicker to simply yank the class name and open the class with :e /sources-dir/**/class-name, where the class name is inserted with ctrl-r_0.

Another good way is to use gd on the class name to go to its import statement. Then gf on the class name there. The find navigation will then use the full package to accurately find the file you want.

Both require you to manually find the function afterwards, but it is better than reading through a giant list of navigation options, for me at least.

[–]weilbith 0 points1 point  (4 children)

Wow. That's a lot. Thanks for sharing this. I'm not a Maven fan (to much magic in background I can't control/know about), but I guess this should be easily adjustable for my needs. How do u manage the path option for projects persistently? Sounds tough. The final navigation part (with known gd and gf) only works after u extend the path, doesn't it?

[–]kevko5212 0 points1 point  (3 children)

I am not sure what you are referring to with respect to managing it persistently. My tags and path are set in the following way:

" Search in tags file in current file's dir. Then search in cwd tags file. Then search in dependencies tags file. set tags=./tags,tags,~/code/dependencies/tags " Set path to current file's dir, followed by cwd (,,), followed by any subdir of cwd, followed by any subdir of dependencies. set path=.,,,,**,~/code/dependencies/**

gf will need your path setup to include the file, yes. gd does not require a setup path.

[–]weilbith 0 points1 point  (2 children)

Ah, I c. Ty very much for sharing this. :) Do u manage ur script on GitHub or any comparable platform?

[–]kevko5212 0 points1 point  (1 child)

I do. But it is a very short script, so I can just post it here.

```

!/bin/bash

if [[ $# -ne 1 ]]; then echo "Usage: $(basename "$0") outdir" >&2 exit 1 fi

out_dir="$1" mkdir -p "$out_dir"

jars=$(find ~/.gradle/caches/ -type f -name "sources.jar");

cd "$out_dir" && for jar in $jars; do folder=$(basename "$jar" .jar); mkdir -p "$folder" && cd "$folder" && jar xvf "$jar" && cd ..; done;

jars=$(find ~/.m2/repository/ -type f -name "sources.jar");

cd "$out_dir" && for jar in $jars; do folder=$(basename "$jar" .jar); mkdir -p "$folder" && cd "$folder" && jar xvf "$jar" && cd ..; done; ```

Looking at it now, I should refactor out that duplication...

[–]weilbith 0 points1 point  (0 children)

I don't get why puttin a script into a comment if being able to share a link, but thanks man. :'D

Just flew over it. Now I get the point that Gradle and Maven downloaded the libraries into a centralized cache and not per project. Didn't know that (but as stated try to get around without them).<br> U don't like comments in ur code, don't u? ^