From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#67061: [PATCH] Improve syntax highlighting for python-ts-mode Date: Wed, 20 Dec 2023 23:04:04 -0800 Message-ID: <80835E29-BA35-4550-9CAC-DA7AE9F60440@gmail.com> 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> <27502181702944649@mail.yandex.ru> <16489c3d-bddf-984b-6c98-2a1de9fdb6e8@gutov.dev> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="22569"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Denis Zubarev , "67061@debbugs.gnu.org" <67061@debbugs.gnu.org> To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 21 08:05:14 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 1rGD7K-0005d4-I3 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 Dec 2023 08:05:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGD79-0004r0-6x; Thu, 21 Dec 2023 02:05:03 -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 1rGD75-0004qj-3M for bug-gnu-emacs@gnu.org; Thu, 21 Dec 2023 02:05:01 -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 1rGD74-0004wV-OL for bug-gnu-emacs@gnu.org; Thu, 21 Dec 2023 02:04:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rGD78-0001FY-2d for bug-gnu-emacs@gnu.org; Thu, 21 Dec 2023 02:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Dec 2023 07:05:02 +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.17031422704761 (code B ref 67061); Thu, 21 Dec 2023 07:05:02 +0000 Original-Received: (at 67061) by debbugs.gnu.org; 21 Dec 2023 07:04:30 +0000 Original-Received: from localhost ([127.0.0.1]:42308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rGD6b-0001Ei-SF for submit@debbugs.gnu.org; Thu, 21 Dec 2023 02:04:30 -0500 Original-Received: from mail-oo1-xc2c.google.com ([2607:f8b0:4864:20::c2c]:50586) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rGD6Z-0001EU-6f for 67061@debbugs.gnu.org; Thu, 21 Dec 2023 02:04:28 -0500 Original-Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-593f420187aso353102eaf.1 for <67061@debbugs.gnu.org>; Wed, 20 Dec 2023 23:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703142257; x=1703747057; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=t9RKY7YNs4svi0Wd8eu3UYYcLxfRXvjlXUE/CQ2cuk0=; b=FDe2m03udnWauxaodTCrLDl4KVI1EPrkGUXPL1LUi3hwAo4/y3OUqfegOriAvSfhL0 Rs2ZOx4IHr0r04yvemWTFgedi+oaTXlOzOJIs2q+djk0E2kclkMQnKUroAXmSEKC9nbC 04hzI7MxHFrCs1tyKIemRv5nxIVxTPIvJBBBYYGOlqyU8T52Y1SNp91nd1pxMHX4Kd3X I/ltKZxZwN4X/+hxvVdV8Y+AYmlNOFUDUql7Ug8B0oC+IjlrV0vfb814iuB7C3w7c7aA Np9esL/qvyu6wkH+v2y/p4tfL9lzmdw7kst8PDIyvPWqCocxGpz3CBPfEUk2njZ/W5YM W9/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703142257; x=1703747057; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t9RKY7YNs4svi0Wd8eu3UYYcLxfRXvjlXUE/CQ2cuk0=; b=mSr5M/GYhVP2vOGyhYFUWQOTnKLG8dzLGCEYG3aT0f7OBoqMENBYpfMDHMMaub5XY5 awtB5k3TAbKccV2dzC5jl11IszOkFA4zn7Gb3USjcgOPVm1Pzwka9cwSIdOUPIp3JBI5 QLQl3a5s/KKS9ifRVo8Uabz988GzYl3wMAsV21wbnZk+eCyImvFBP5ZTdR+JqbZjk1ro h3K0dI4fXbtSTNcAPWubvXqdHualrrSZN92ou0lfY9F2Cwss1esnj97ViRQ2fWE4DY+i 5HZj2erBzybh7ro9DYQjoBCj0ptYoHjLMC0bk5PB/2mbIUwWa2T+u0Pskb6OKShAT4CZ TLtg== X-Gm-Message-State: AOJu0YyyF034mezSnyGCRCPwur6B97sQpMNgGfJfIJiSWuDnQWrlsbhA LIJc7QzRG56DGwAj/WbcC68= X-Google-Smtp-Source: AGHT+IH/DScp3IpdaNjvuOOEVXgNM3NVkbdt9EXNOWVghP2o53RrOj8ZlC7G1cCh9W0/P7TG9tdoCQ== X-Received: by 2002:a05:6358:8187:b0:172:d789:df8a with SMTP id r7-20020a056358818700b00172d789df8amr613947rwk.56.1703142257408; Wed, 20 Dec 2023 23:04:17 -0800 (PST) Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id a12-20020a62d40c000000b006d975ca1fcesm433746pfh.49.2023.12.20.23.04.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2023 23:04:16 -0800 (PST) In-Reply-To: <16489c3d-bddf-984b-6c98-2a1de9fdb6e8@gutov.dev> X-Mailer: Apple Mail (2.3731.700.6) 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:276612 Archived-At: > On Dec 20, 2023, at 3:34 PM, Dmitry Gutov wrote: >=20 > On 19/12/2023 02:14, Denis Zubarev wrote: >> > 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. >> Thank you for investigating this. It seems this commit introduced >> changes to type nodes hierarchy = (https://github.com/tree-sitter/tree-sitter-python/commit/bcbf41589f4dc38a= 98bda4ca4c924eb5cae26f7b). >=20 > Could be this one, yes. >=20 >> > 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. >> It may lead to unnecessarily complex rules. I don't >> know is it worth it, since users can easily update grammars. >=20 > No problem. >=20 >> > 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. >> These two functions expect a type (or tuple of types) as the second >> argument. To address your concerns about highlighting as a type a >> non-type variable, I added regexp python--treesit-type-regex. This = regex >> matches if text is either built-in type or text starts with capital >> letter. I extracted built-in types from the python--treesit-builtins >> into its own variable python--treesit-builtin-types. >> python--treesit-builtins is now constructing by appending >> python--treesit-builtin-types and other built-ins. I hope it is ok. >=20 > Thank you. I'm actually not sure if we _have to_ check the identifier = names in this context (any chance to have a false negative, miss some = valid types?), but it probably doesn't hurt either. >=20 >> > 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. >> It is good idea, to highlight some variables as types. But I think it >> should be done on the 4th level. One could split the variable feature >> into multiple features: variable-type, variable-argument, = variable-use, >> etc. So for variable-type feature we can use = python--treesit-type-regex >> and highlight matched identifiers with type face. For now I wanted to >> properly highlight types in places where they expected to be. >=20 > I wouldn't mind the level 4 (after all, python-mode is also = conservative here and doesn't add such highlighting), but I'd rather not = add the special handling for isinstance/issubclass thing for the reasons = previously outlined. >=20 > Perhaps Yuan will disagree. I'm just here to say that the rest of the = patch LGTM. I wouldn=E2=80=99t mind either, go crazy with level 4 :-) I wouldn=E2=80=99= t even mind it in level 3, since they are indeed types. Using a separate = feature is a good idea, so people who doesn=E2=80=99t want it can turn = it off. Yuan