zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Henri Tremblay <henri.tremblay@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: Java completion for Java files
Date: Sat, 17 Feb 2024 02:18:36 +0100	[thread overview]
Message-ID: <70740-1708132716.601082@rJjR.yILq.82lJ> (raw)
In-Reply-To: <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
   ;;


       reply	other threads:[~2024-02-17  1:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CADZL2=u-c69DmGyWFNMhYRCR0NQ3DtZv9DbuMSGK+iFT6t5ASQ@mail.gmail.com>
2024-02-17  1:18 ` Oliver Kiddle [this message]
2024-02-17  2:49   ` Henri Tremblay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70740-1708132716.601082@rJjR.yILq.82lJ \
    --to=opk@zsh.org \
    --cc=henri.tremblay@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).