From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#61017: 29.0.60; ruby-ts-mode indents class between two lines incorrectly Date: Tue, 24 Jan 2023 20:53:20 +0200 Message-ID: References: <1a2436ef-ff4d-827c-f22f-33b0737d9b1f@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4914"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: 61017@debbugs.gnu.org To: Aaron Jensen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 24 19:54:35 2023 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 1pKORG-000182-8r for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Jan 2023 19:54:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKOQz-0000AU-Ga; Tue, 24 Jan 2023 13:54:17 -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 1pKOQk-0000AH-A7 for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2023 13:54:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKOQj-0001DS-Sz for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2023 13:54:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pKOQj-0007Du-PN for bug-gnu-emacs@gnu.org; Tue, 24 Jan 2023 13:54:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Jan 2023 18:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61017 X-GNU-PR-Package: emacs Original-Received: via spool by 61017-submit@debbugs.gnu.org id=B61017.167458641027726 (code B ref 61017); Tue, 24 Jan 2023 18:54:01 +0000 Original-Received: (at 61017) by debbugs.gnu.org; 24 Jan 2023 18:53:30 +0000 Original-Received: from localhost ([127.0.0.1]:57630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKOQE-0007D8-Bp for submit@debbugs.gnu.org; Tue, 24 Jan 2023 13:53:30 -0500 Original-Received: from mail-ej1-f46.google.com ([209.85.218.46]:33704) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKOQC-0007Cv-O2 for 61017@debbugs.gnu.org; Tue, 24 Jan 2023 13:53:29 -0500 Original-Received: by mail-ej1-f46.google.com with SMTP id tz11so41674730ejc.0 for <61017@debbugs.gnu.org>; Tue, 24 Jan 2023 10:53:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=IjxzM54zdUtsanSpXRgY16bT07lUo2czZj4tUv2hCkI=; b=fs1ILaV60ye9isuTkNgK6oU5ObPiLNAFNDoOREHr0ST2LUGV4FEF2y5nMdcOnJQxp9 gt6mi8UwxvUVz/9AN4SEN6PNCRxNe1u2Bve+esUWdKLrDIRBExcRxwFQtM3E8VjB4ydC if/kch9lDJTPlggX9HndmrjXlzk3eaMtp+vDyJENFO4TDg5km9BoQtY8sRiqen8p0ofM fPwgRV6P6w2IzlXXvE1N6P71W/yBQnyQOKfijfmC00wFH0RISK4Q7/MyF6yTSY74Ql4a MoyfJbbqr69eGcVztX/Rr4wKGTQkKYdkklSJz493D9lH9tZjJ0odX13m9uWlK6B1RxUf sG4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IjxzM54zdUtsanSpXRgY16bT07lUo2czZj4tUv2hCkI=; b=AHq1WehWwkzcO6Rp0AjCSWZj30GcIrgUYTYifJdxVGvvz1fGVhgoFbOrng8Tr7oO77 gVGY5+Pgho+jZNHcnCRY51X4jyks3spTMIAYXaQprkcIb8lAoRAojO1oKMxk2ETs3B/L Vb9UK488Fc7xpkk0k3gbobecdeC5pU+/7dzyYHF/ZJUpuqACuRiCldnCIdaKXZ/e/hT2 OOeN+b2tbh1S4Wmz2fGvPUfeVXCK0tLshCHKr2s9xY8IjgCtukVQp6GHM/4ZfZWoN4cM 70qYk6PN4z43dMMXCFod5zIJCP+OFJvTLp8KYJthfKoOOjvEn70d5jWMXfzvIKJJjxr3 zDHw== X-Gm-Message-State: AFqh2kryH32YaQMpIgTVTWfyw0xUk026ebPoo6vqNQjI7WfyTUDSEXPF IXOCyYaVomzsUHDvoKzFdJQ= X-Google-Smtp-Source: AMrXdXuxpjNsGt0ll6f58cv1mHggMPNb21IPTmxWpLzp0txycY/X7SP/Tab3xqbeaz0nqy3oZp0TvA== X-Received: by 2002:a17:906:37c4:b0:871:91ec:edae with SMTP id o4-20020a17090637c400b0087191ecedaemr30148734ejc.75.1674586402633; Tue, 24 Jan 2023 10:53:22 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id fq32-20020a1709069da000b0083f91a32131sm1260655ejc.0.2023.01.24.10.53.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jan 2023 10:53:22 -0800 (PST) Content-Language: en-US In-Reply-To: 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:254068 Archived-At: On 24/01/2023 16:17, Aaron Jensen wrote: > On Mon, Jan 23, 2023 at 4:28 PM Dmitry Gutov wrote: >> >> Hi! >> >> On 23/01/2023 06:33, Aaron Jensen wrote: >>> >>> Start with a buffer in ruby-ts-mode like: >>> >>> a >>> >>> b >>> >>> Between the two lines, type "class Foo", then press enter >>> >>> You should get this: >>> >>> a >>> >>> class Foo >>> >>> b >>> >>> But this is expected: >>> >>> a >>> >>> class Foo >>> >>> b >>> >>> Note that reindenting after adding the "end" will indent correctly, so >>> it's only an issue with electric indent >> >> Thanks for the report, the problem here is that such examples parse into >> a malformed syntax tree: >> >> (program (identifier) >> (ERROR class (constant) (identifier))) >> >> Another example would be: >> >> class C >> def foo >> >> which parses as >> >> (ERROR class (constant) def (identifier)) >> >> We can try to anticipate such cases and infer the implied structure >> somehow, or just disable indentation for specific cases. See the >> attached patch for the latter. >> >> Is it enough of an improvement? > > That seems to make indentation after an open def not happen: > > def foo > bar > end Not sure what you mean. Is that an example with an "open def"? "end" seems to be closing it. In the final state, it indents correctly here. > I applied the patch manually though, so maybe you can confirm that you > see the same thing? If I have a buffer with just the first line: def foo then it indeed doesn't indent. But I think that happens with or without this patch? It's a slightly different problem: the grammar parses this code example without ERROR nodes, like a full method, for some reason: (program (method def body: (identifier) end)) And the end position of the "virtual" end node stays at the previous line, so our code doesn't know it's inside the method. I suppose we could add some tricky predicate like (is the previous node a method with an "end" child that is 0 characters long), but the grammar might change (we should look for any previous reported issues about this behavior, or maybe ones that resulted in it), and it only happen this way when there is nothing after "def xyz" in the buffer. Because in the more common case, like class C def foo | end the last "end" is parsed like the closer for the method, the method node spans until it, and the line with "|" indents correctly. WDYT?