From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Artem Newsgroups: gmane.emacs.bugs Subject: bug#75154: 31.0.50; java-ts-mode. Issues with Indentation Date: Fri, 27 Dec 2024 18:34:45 +0300 Message-ID: <87ttapdtre.fsf@void> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39922"; mail-complaints-to="usenet@ciao.gmane.io" To: 75154@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 28 05:38:17 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tROae-000AFK-GM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Dec 2024 05:38:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tROaS-0000Tm-OJ; Fri, 27 Dec 2024 23:38:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tROaR-0000Te-AA for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 23:38:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tROaQ-0005Rb-UE for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 23:38:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=EMQhwMPvt/4FiyN6HxCDCYCzld/pRiwSf9loR/yV4+4=; b=s5hoFnI3XNYnPTiSs8QDYjBZC0RhEuqVedg7BPsZYGQhqEs5ZJhq2oFVsJOMTRCBFIvCm5DqgTlSkpZphnaJ7JXOz4yU9Is2pj4GORZNqcjbZ3h/TrnvYRV8apscAXgn5ovjcD5VpgWpmM4t/8DVbD5zATklUJk8QxIQoTXakCEDVZzMDXzmTzfRKYRqS3KmxyxWc6xmARwQV0975wNg7MZTSEJxElK3WNbueNTiz1YL3L2spgmt3VynawNtWlAQWnit3rbMruvGyVEtzZgpszd2tzbHrEwdBFTCBpCPkA9/DAolXrj/WkUWk+Edu3xSAd3FSV5ma1+19ozdyoJoBg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tROaQ-0004q3-IW for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 23:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Artem Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Dec 2024 04:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75154 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.173536066418558 (code B ref -1); Sat, 28 Dec 2024 04:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Dec 2024 04:37:44 +0000 Original-Received: from localhost ([127.0.0.1]:48325 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tROa7-0004pE-Az for submit@debbugs.gnu.org; Fri, 27 Dec 2024 23:37:44 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:49462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRCgh-0000nD-No for submit@debbugs.gnu.org; Fri, 27 Dec 2024 10:55:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRCgg-000495-Iq for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 10:55:42 -0500 Original-Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tRCge-0005OT-JJ for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 10:55:42 -0500 Original-Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a9e44654ae3so1191505066b.1 for ; Fri, 27 Dec 2024 07:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735314938; x=1735919738; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=EMQhwMPvt/4FiyN6HxCDCYCzld/pRiwSf9loR/yV4+4=; b=dcOFzf8p7r9R7NpTdwof6BxGonsfLim2E3hQxr8J8Fg+HSkk0SqDRbDs5/xvQCspEm k+uH/GdMXMXl7XZiVO0bK0/WckXdfhmSi3XyxT3V1HahvqTb5emw7WkPl6Oj3Df8QL9n NOlUfA0vxwRf5jGh6CK5RoRxZvLOhDVedOnf2iDyCkn9xYe3P6AYbw8a6IZOjgKgaiLB WL4sSJLpmF0Q4nd+JMwDkcgK7/LmJBhO8uAESEjXwmUaBuNKuwd4Ejq6LRzZgpT6f9e/ 3nwpS4gZ2+RMgUYDsBBWtB5r7dm/mSgZoCpAvDXE7dojf4r8d50Pak3W4W6pMyCzJ4iz 4K0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735314938; x=1735919738; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EMQhwMPvt/4FiyN6HxCDCYCzld/pRiwSf9loR/yV4+4=; b=wL3qeRYv74ZqmmVvYsar1uPLZ7OTx6FWL8eUTMAKuDltn9guIPsQXEUOaBAE9PmfP0 FNpnwBAVshDcRVFDftobB8bjL8UtiRdBd6MLz4rsBCQlN7euUtn4mBp41+99TwpC4CIK V1/iUQi8/Oxz/FsYN4csskrtkBXjWK3lXf7imnA5KpfCerHYeU6BLypJddvFA7F5AeQ+ ej1oGMYpfL0Jd40x4JaWUDkukSN7n5PF7xj2JnOGEFLqD0brR+SA8gsc2Bn+on7+3csn 9Vbd/EoCFiRzOypn1o54KFxwxKm5b0fiALez0rZiEzeBOMaNX+U0EvDrY/p8pJuO1V0x 9gEw== X-Gm-Message-State: AOJu0Yxm5wiBGN5Wk3pkfUr1c6D9UV5hOXAj+b4dknCPKa5PweLzntTA 7w8KrXT2M0uAhIJj332fvxR8F6FSChZpZe+UEGp2NtHzccCtRqi0F9mt09Ypzq4= X-Gm-Gg: ASbGncuLXojWX4hZX0yRX5h9XQdZD52NB6bLNI8Q3SfCsRd87S8blWHXNrcIQ/v2pTp jKdjs+BO8KmMnFcFHwc7XxMHjbK2BuqxoZaNspThT2S6czPxG8mKIoG6B8UEbdjYLsd5ri+CzdE JWQAKIr1+QefG9DkUs/r3gMRAKb/RVsTEM/kCl9b96PA7uCncrg2ieUcb1H6BrCnvesSI1AhwJO faDHctRmeRxC2OpXxltc0osNohb4rRQ3FkQ1duiko8= X-Google-Smtp-Source: AGHT+IH1FBqXhvsGj8EXOiN8rf4lARgAw85I00gcaUqpX5g+fe8jYObkpw283MuLlxEhhRpwxwC8RA== X-Received: by 2002:a17:907:97c6:b0:aa6:a9fe:46e5 with SMTP id a640c23a62f3a-aac3366afbdmr2451025866b.53.1735314937976; Fri, 27 Dec 2024 07:55:37 -0800 (PST) Original-Received: from void ([77.51.14.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f06543asm1128334866b.175.2024.12.27.07.55.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 07:55:37 -0800 (PST) Original-Received: from localhost (void [local]) by void (OpenSMTPD) with ESMTPA id 1739995c for ; Fri, 27 Dec 2024 15:34:45 +0000 (UTC) Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=snake05865@gmail.com; helo=mail-ej1-x631.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 27 Dec 2024 23:37:41 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297847 Archived-At: Hello I've identified several issues with indentation in java-ts-mode where it doesn't work as expected. Let me first clarify what I consider "expected" behavior - there are things that are "GOOD", "BAD but allowed", and "Opinion-based. Here are the specific problems: 1) Chaining Methods in the Stream API and Lambda Expressions Example 1: class Foo { void Foo() { List customers =3D customer | <-- Actual (BAD) | <-- Expected (GOOD) (8 spaces) } } When continuing the statement List customers =3D customer .stream and then adding closing parentheses=20=20=20=20=20=20=20=20 List customers =3D customer .stream() <-- The method filter will move to 4 spaces automatica= lly .filter <-- without parentheses=20 .filter() <-- closing bracet and method moving to 4 spaces This behavior is problematic. In java-mode, this does not occur.IntelliJ IDEA uses 8 spaces for method chains,which makes the code more readable. While some examples use 2 spaces (e.g., for web snippets),in production environments, 8 spaces are more common. This should ideally be customizable= for end users. Moreover, the current indentation is hardcoded and doesn=E2=80=99t allow flexibility. For instance, in python-ts-mode, pressing TAB allows you to adjust constructions more freely. This level of flexibility would be beneficial in this context This inflexibility prevents writing common patterns like: @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/admin/**").hasAuthority("ADMIN") .antMatchers("/user").hasAnyAuthority("USER", "ADMIN") .antMatchers("/", "/index").permitAll() Example 2: The following looks correct - public class FloodFill { public static void main(String[] args) { List stream =3D students.stream() .filter(item -> { return item.getValue() > 100 && item.isActive(); }) .map() .collect(); } } But java-ts-mode produces: public class FloodFill { public static void main(String[] args) { List stream =3D students.stream() .filter(item -> { return item.getValue() > 100 && item.isActive(); }) .map() .collect(); } } 2) Inner Classes Example 1: public class Outer { class Inner {| <-- cursor here moves Inner class unexpectedly } } Example 2: public class Outer { class Inner { // ??? | <-- cursor here.=20=20=20=20=20=20=20=20=20=20=20 } } Why does this happen? I did not request this behavior. While Example 1 demonstrates bad code style, it is technically valid. Such "magical" formatting should be handled by a Java formatter, not by Emacs or Tree-sitter rules. IntelliJ IDEA does not apply such formatting; it leaves this task to the fo= rmatter. Example 3: public class Outer { class Inner{ void foo(){ }|<--start position. RET |<-- expected position |<-- actual } } If Inner class has incorrect indentation, subsequent code will also be inco= rrectly indented. 3) for, if, else if, while, do-while without braces public class While { { while () | <-- Expected=20=20=20=20=20=20 | <-- Actual } } Although this is bad coding style, it=E2=80=99s allowed and compiles correc= tly. 4) Java 15 text blocks Text blocks are not properly handled public class TextBlocks { System.out.println(ctx.fetch(""" SELECT table_schema, count(*) FROM information_schema.tables """)); } - Triple quotes handling (should electric-pair-mode be enhanced?) - Text block alignment is opinion-based and should be adjustable with TAB - New SQL expressions should be sticky It seems such multiline strings also do not work well, for example: "'The time has come,' the Walrus said,\n" + 5) Broken Syntax Highlighting public class Outer { HELLO EMACS <-- Write something here class Inner{ <-- This class will not be highlighted void foo(){ } } } Tree-sitter should ignore such uncommon cases to maintain syntax highlighti= ng 6) Multiple Parameters in Methods Example 1 public record StudentRecord( String firstName,=20 String lastName,=20 Long studentId,=20 String email) Example 2 public String filterData(@RequestParam(required =3D false) String name, @RequestParam(required =3D false) String name, @RequestParam(required =3D false) Integer age ) java-ts-mode fails to handle these cases correctly. Desired Fontification (Out of the Box): - Annotations (@Annotations) - Diamond Brackets (<>) - Constants, Static Variables, Enum Variables should be highlighted with distinct colors and optionally italic font - Unused Variables or Classes (Grayed Out) - Unused variables, unused classes, etc., highlighted in gray. Not sure if = this can be achieved with Tree-sitter. Anyway, with Flymake + Eglot, it currently works in a som= ewhat clunky manner. Example public class TextBlocks { enum AnEnum { CONST1, CONST2 } <-- No effect for unused AnEnum. public static final String HELLO =3D"HELLO"; public static void main(String[] args) { int i =3D 0; <-- Flymake identifies as unused but looks unpolished.= =20 System.out.println(HELLO); } } Overall: I may have missed some aspects, but as it stands, Emacs is not comfortable for Java development with these issues. Some information that might be helpful: - https://github.com/dakrone/eos/blob/dd8aa3a25b496397dd0162d229de571989668= 619/eos-java.org?plain=3D1#L30 .Not sure why this Elasticsearch developer created so many custom rules for= indentation. - https://github.com/Michael-Allan/Java_Mode_Tamed A major Java mode with s= ensible fontification. - JetBrains Intellij IDEA Community Edition - File>Settings>Editor>Color Scheme>Java Java for understanding which col= ors are needed and what is missing. - Editor>Color Scheme>Java>Code Style>Java for indentation settings.