zsh-workers
 help / color / mirror / code / Atom feed
* Re: Java completion for Java files
       [not found] <CADZL2=u-c69DmGyWFNMhYRCR0NQ3DtZv9DbuMSGK+iFT6t5ASQ@mail.gmail.com>
@ 2024-02-17  1:18 ` Oliver Kiddle
  2024-02-17  2:49   ` Henri Tremblay
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2024-02-17  1:18 UTC (permalink / raw)
  To: Henri Tremblay; +Cc: zsh-workers

[ 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
   ;;


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Java completion for Java files
  2024-02-17  1:18 ` Java completion for Java files Oliver Kiddle
@ 2024-02-17  2:49   ` Henri Tremblay
  0 siblings, 0 replies; 2+ messages in thread
From: Henri Tremblay @ 2024-02-17  2:49 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1872 bytes --]

Awesome! Thank you so much!

On Fri, 16 Feb 2024 at 20:18, Oliver Kiddle <opk@zsh.org> wrote:

> [ 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
>    ;;
>

[-- Attachment #2: Type: text/html, Size: 2446 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-17  2:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CADZL2=u-c69DmGyWFNMhYRCR0NQ3DtZv9DbuMSGK+iFT6t5ASQ@mail.gmail.com>
2024-02-17  1:18 ` Java completion for Java files Oliver Kiddle
2024-02-17  2:49   ` Henri Tremblay

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).