Skip to content

Commit 1418b19

Browse files
feat(java): enable .java filename completion for java command
Modify java command completion scripts to also complete filenames with the .java extension. This adds support for - JEP 330: Launch Single-File Source-Code Programs - JEP 458: Launch Multi-File Source-Code Programs Closes #1196 Co-authored-by: frankslin <frankslin@users.noreply.github.com>
1 parent 3039122 commit 1418b19

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

completions/java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ _comp_cmd_java()
236236
else
237237
# classes completion
238238
_comp_cmd_java__classes
239+
# support for launching source-code
240+
# programs (JEP 330, JEP 458)
241+
_comp_compgen -a filedir 'java'
239242
fi
240243
fi
241244

test/fixtures/java/JEP330.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* The java launcher is able to run a program
3+
* supplied as a single file of Java source code.
4+
*
5+
* @see <a href="https://openjdk.java.net/jeps/330">JEP 330: Launch Single-File Source-Code Programs</a>
6+
* @see <a href="https://openjdk.java.net/jeps/458">JEP 458: Launch Multi-File Source-Code Programs</a>
7+
*/
8+
class JEP330 {
9+
public static void main(String[] args) {
10+
System.out.println("Hello World");
11+
}
12+
}

test/t/test_java.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,40 @@ def can_list_jar(self, bash):
1919
def test_1(self, completion):
2020
assert completion
2121

22-
@pytest.mark.complete("java ")
22+
@pytest.mark.complete("java ", cwd="java")
2323
def test_2(self, completion, can_list_jar):
2424
if can_list_jar:
25-
assert completion == "b bashcomp.jarred c. toplevel".split()
25+
assert (
26+
completion
27+
== "JEP330.java a/ b bashcomp.jarred c. toplevel".split()
28+
)
2629
else:
27-
assert completion == "b c.".split()
30+
assert completion == "JEP330.java a/ b c.".split()
2831

29-
@pytest.mark.complete("java -classpath java/bashcomp.jar ")
32+
@pytest.mark.complete("java -classpath bashcomp.jar ", cwd="java")
3033
def test_3(self, completion, can_list_jar):
3134
if can_list_jar:
32-
assert completion == "bashcomp.jarred toplevel".split()
35+
assert (
36+
completion == "JEP330.java a/ bashcomp.jarred toplevel".split()
37+
)
3338
else:
34-
assert not completion
39+
assert completion == "JEP330.java a/".split()
3540

36-
@pytest.mark.complete("java -cp java/bashcomp.jar:java/a/c ")
41+
@pytest.mark.complete("java -cp bashcomp.jar:a/c ", cwd="java")
3742
def test_4(self, completion, can_list_jar):
3843
if can_list_jar:
39-
assert completion == "bashcomp.jarred d toplevel".split()
44+
assert (
45+
completion
46+
== "JEP330.java a/ bashcomp.jarred d toplevel".split()
47+
)
4048
else:
41-
assert completion == ["d"]
49+
assert completion == "JEP330.java a/ d".split()
4250

43-
@pytest.mark.complete("java -cp '' ")
51+
@pytest.mark.complete("java -cp '' ", cwd="java")
4452
def test_5(self, completion):
45-
assert not completion
53+
assert completion == "JEP330.java a/".split()
4654

47-
@pytest.mark.complete("java -jar java/")
55+
@pytest.mark.complete("java -jar ", cwd="java")
4856
def test_6(self, completion):
4957
assert completion == "a/ bashcomp.jar bashcomp.war".split()
5058

0 commit comments

Comments
 (0)