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#67061: [PATCH] Improve syntax highlighting for python-ts-mode Date: Mon, 18 Dec 2023 02:25:36 +0200 Message-ID: References: <8734xdni6y.fsf@yandex.ru> <831qcwycbj.fsf@gnu.org> <83v8a3qh6m.fsf@gnu.org> <834jhadvkt.fsf@gnu.org> <7aee7e42-c07d-9131-18a9-4806f07d4267@gutov.dev> <83a5qw7izt.fsf@gnu.org> <172531702081590@mail.yandex.ru> <212931702208489@mail.yandex.ru> <0c6e2e14-b494-a8cb-3893-ffb39577baf9@gutov.dev> <7b17c99d-6e4b-43b3-af93-993901a3a4ea@gmail.com> <95071702343720@mail.yandex.ru> <78ffdcf3-e322-49ea-a0d5-d0485ade9e73@gmail.com> <7371702772641@mail.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="6954"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: "67061@debbugs.gnu.org" <67061@debbugs.gnu.org> To: Denis Zubarev , Yuan Fu , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 18 01:26:10 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 1rF1SS-0001da-ID for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Dec 2023 01:26:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rF1SM-000842-Ls; Sun, 17 Dec 2023 19:26:02 -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 1rF1SK-00083t-Ag for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 19:26:00 -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 1rF1SK-0000Nt-2G for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 19:26:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rF1SL-0007DM-ID for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 19:26: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: Mon, 18 Dec 2023 00:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67061 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67061-submit@debbugs.gnu.org id=B67061.170285915027715 (code B ref 67061); Mon, 18 Dec 2023 00:26:01 +0000 Original-Received: (at 67061) by debbugs.gnu.org; 18 Dec 2023 00:25:50 +0000 Original-Received: from localhost ([127.0.0.1]:59194 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rF1SA-0007Cx-9M for submit@debbugs.gnu.org; Sun, 17 Dec 2023 19:25:50 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:55185) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rF1S7-0007Cd-87 for 67061@debbugs.gnu.org; Sun, 17 Dec 2023 19:25:48 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 4B7535C0105; Sun, 17 Dec 2023 19:25:40 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 17 Dec 2023 19:25:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1702859140; x=1702945540; bh=vfeXK4OnClrrA6FG3NONByDsooV16Y87gRgZ2EkzqsM=; b= 1VaW1IIhKxS3bbI4+OLa1zMSOM7jiWpRJ/JkFr64zRemB3AA+pVeRMYW9a/8t6cl SHAaPc1MVwBJacK+KndQC9n2RYJJ7SZVnbVOw1Ib7qFPJZ9wRDMb023Dw7iS6UNL Nh3qaqiwNl0mx6POCJpeJM0TOLDwa0n3nJU9Y1ZxYyiog6zkgotTgzTLg8UEqk3c qZYtiTIAjv74yMb03RhrL4ofS+v3xNmMecjtb+WNxHPxGHpRL+8e5LftfePsGb5K L3+i3mq67Ej3XEcunDHpxW/Ov5PYxJYkoSeKsbI4vTDjHsg5ff1/XXchhqGm/E85 RPQbBntznvXZ4Ryf1E4DCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1702859140; x= 1702945540; bh=vfeXK4OnClrrA6FG3NONByDsooV16Y87gRgZ2EkzqsM=; b=m LZczSqsS8CgyoOAej+fY0wv7SIpakc0htcmtl9sDv8U4P9Z8qMffx2fKirkKLWca z/qLbDxdocafFWj0FLeU0hq6l98v7VUrkqpVyvCc26mcCDKZQuJBj0ypeD/cA0RQ N2HIr1Q30GegdOXY9khpaKagbdkZAO2hpJwr8nLUqn0Uchcip/rCbo+BUmEQJNKI TIYCa9qfZI8+Jvke5MlxS+zlC0P7rDD6JGiiR0yW2r1ITIIx/eV6TgYII85FfkuS nmGo1Pk1wXvAvQmDKryYaJGdO+RKipK2YqcN3J+S9ekiHeFVBvKgFA5kLoUSEqwX x15/YBas2B8pl4qvxMByQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddtjedgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepteffudetffetveefieelfeevfefhueekheetgfetvdfgveehieejteekveei veehnecuffhomhgrihhnpehrvgguughithdrtghomhdprhgvuggurdhithenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumhhithhrhiesghhu thhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Dec 2023 19:25:38 -0500 (EST) Content-Language: en-US In-Reply-To: <7371702772641@mail.yandex.ru> 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:276450 Archived-At: On 17/12/2023 02:26, Denis Zubarev wrote: > Summary for all changes in the patch. > New feature variable-definition: > `for var in range(3)` > `[var+1 for var in []]` > `with T as var:` > `except E as var:` > `case str() as var:` > highlight var as font-lock-variable-name-face > assignment feature: > var := 3 (named_expression) > var *= 3 (augmented_assignment) > Highlight var as font-lock-variable-name-face. I still think variable-name-face is not the best fit for augmented_assignment, but admittedly it's a minor thing. > type feature: > Fontify built-ins (dict,list,etc.) as types when they are used in type > hints. > support nested union types, for example `Lvl1 | Lvl2[Lvl3[Lvl3], Lvl2]`. > This structure is represented via nesting binary_operator and subscript > nodes in the grammar. > Function python--treesit-fontify-union-types iterates over all children > and highlight identifier nodes. If you recall my earlier complaint that these highlightings didn't work (and the tests didn't pass), this happened due to an older Python grammar. More specifically, these highlights, and the type-related face tests, don't work with the Python ts grammar I had from March 7th 2023. The queries didn't lead to errors either (that's a good thing), but maybe we'll want to revisit these highlights later to add support for the older grammar as well. > Fontify base class names in the class definition: class Temp(Base1, > pack0.Base2): > Fontify class patterns in case statement: case [TempC() | bytes(b)]: > Highlight the second argument as a type in isinstance/issubclass call: > isinstance(var2, (str, dict, Type1)); issubclass(var1, int|str) I'm not sure highlighting types based on the caller method and position is a good idea. I think that's backward, logically. If one puts a non-type value in such argument, and we would highlight it as a type -- that seems like the wrong message. OTOH, see this reddit thread and this screenshot: https://www.reddit.com/r/emacs/comments/18kr1gl/how_can_i_configure_pythontsmode_to_fontify_more/ https://preview.redd.it/y8l3k8tt4x6c1.png?width=3840&format=png&auto=webp&s=0a6882e66d4b334c07e856934ce847e63aa2db2c One of the complaints is that "User" is not highlighted as a type when used in other, non-built-in methods, which like a reasonable question to me. Yes, Python is dynamic, but using CamelCase for types is a fairly regular convention, so highlighting such identifiers as types can work. You can see rust-ts-mode for an example of this approach. > decorator feature: > Highlight dotted names: @pytest.mark.skip > Function python--treesit-fontify-dotted-decorator iterates over all > nested attribute nodes and highlight identifier nodes. > When font-lock-level is set 4, `skip` had function-call face in: > @pytest.mark.skip(reason='t') > Add `:override t` to decorator feature to override function-call face. > string feature: Could we just move it above the 'function' feature, so that the override is not needed?