Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Java completion for Java files
- X-seq: zsh-workers 52552
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Henri Tremblay <henri.tremblay@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: Java completion for Java files
- Date: Sat, 17 Feb 2024 02:18:36 +0100
- Archived-at: <https://zsh.org/workers/52552>
- In-reply-to: <CADZL2=u-c69DmGyWFNMhYRCR0NQ3DtZv9DbuMSGK+iFT6t5ASQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CADZL2=u-c69DmGyWFNMhYRCR0NQ3DtZv9DbuMSGK+iFT6t5ASQ@mail.gmail.com>
[ moved to zsh-workers ]
On 5 Feb, Henri Tremblay wrote:
> Java now supports (since Java 10 I think) command lines like
>
> java Math.java
>
> or
>
> java src/main/java/org/me/Math.java.
>
> It will then just compile and launch that java file. But zsh won't autocomplete
> for that. It only wants a jar, class file or whatever.
The following adds completion for that. This does add --source to the
options completed because that's needed to limit completion to files
when it's present. However, there does appear to be many new options
not covered by the completion. I'd guess that most javac options are now
valid with java too.
The JEP330 link indicates that with --source, files needn't have a .java
extension but broadening the file completion in that case is probably
unhelpful (seems the feature primarily exists to support use with a
shebang).
Oliver
diff --git a/Completion/Unix/Command/_java b/Completion/Unix/Command/_java
index b2352df7b..325413d87 100644
--- a/Completion/Unix/Command/_java
+++ b/Completion/Unix/Command/_java
@@ -82,7 +82,10 @@ java)
'(- 1)-X-[non-standard java option]:option' \
'(- 1)-jar[specify a program encapsulated as jar]:jar:_files -g \*.jar\(-.\)' \
'-splash\:-[show splash screen with specified image]:image:_files' \
- '(-):class:_java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]}' \
+ '--source=[set the version of the source in source-file mode]:version' \
+ '(-):arg: _alternative
+ "classes\:class\:{ (( ! $+opt_args[--source] )) && _java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]} }"
+ "files\:source file\:_files -g \*.java\(-.\)"' \
'*::args:= _normal' \
&& return 0
;;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author