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.devel Subject: Re: Standardizing tree-sitter fontification features Date: Mon, 5 Dec 2022 13:02:24 -0800 Message-ID: References: <2AEA8AB6-593E-4D89-AB05-0C8EB2BCE327@gmail.com> <5B7EE037-C85A-411C-B42B-1E234EE66DFA@gmail.com> <64C676F2-C4A0-4D28-8FE7-5FB250BF1B9B@gmail.com> <87sfhuxm5g.fsf@thornhill.no> <4FC19A2A-E4B3-4BB4-B718-8BB0BE70B04B@gmail.com> <87r0xedr55.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="12359"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= , emacs-devel To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 05 22:03:22 2022 Return-path: Envelope-to: ged-emacs-devel@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 1p2IcU-0002zk-3e for ged-emacs-devel@m.gmane-mx.org; Mon, 05 Dec 2022 22:03:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2Ibl-0006Fb-1X; Mon, 05 Dec 2022 16:02:37 -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 1p2Ibi-0006ER-Fv for emacs-devel@gnu.org; Mon, 05 Dec 2022 16:02:35 -0500 Original-Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2Ibg-0007ih-Pk for emacs-devel@gnu.org; Mon, 05 Dec 2022 16:02:34 -0500 Original-Received: by mail-pf1-x42e.google.com with SMTP id d82so3861416pfd.11 for ; Mon, 05 Dec 2022 13:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=JjgUDzuvHdE+Q3MwqRSFslPVCxMXN8B1TcTS6Z/WVGw=; b=gJnGyBO8hdkcB3yRIQ0KY9cwTbihWeXl4yjDyHfQVRT+kSFhTRfeW/3WRyex0YASRQ jUe4CieyszhyDhrUWjkXVdDqps639hnmbuyu7Jyqa/4/hjNasNWKQaipMX3LnqiEn7z7 LztZQ8rESAIbiMZqGA8GRlnrh+ImmKtdhgDI1ie18bSvxa7BZEdkvycyK+pG/4zuo58U kffrzHg0Ov5NHDs54aakGLNX+2LySJa5h0ERdpWQXhEZJORApdxakaX75rDRecYPvO4e qXIk9GQWtU+I2zhVtbjEM3RnvdkrJOmiFu8TkogZYmsrgXBmFBzKULvShQehO9fHpSS/ jK+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JjgUDzuvHdE+Q3MwqRSFslPVCxMXN8B1TcTS6Z/WVGw=; b=SPGlAgWBb/uoJU1jc0FBrHhUASs2TDYNAoS54pucfBipzyXiV+/gDiKtLoEeP5fvSL gSHYLTo0IabNaC1HfZHK0EhmL3e7TlHuf1sMrIj2Ys52IZqF7Q0rZAd8ahGmGCaMfLYc WJLNRU9AwUFBAio/Yg4DwrBs6fhKwSBXtsn+B4FERL3PadyGZVasMbCAenIN3T2f/aWL qxOb5Ca+YEOfEhyNa8GkGtayT2Nb0ppxnrKCXJ2YJhUKhxGGXYAwb6IqNDpYG5oxpAGI k3uk6dbuZwXt4rZgiAubBDGKlHGjbbvDRfK0/Z9t9abFAMVRZw7UyUUFqMyJZcNbHLcK L3Qg== X-Gm-Message-State: ANoB5plLF/1XABsGiRakN6evjf2YBbM6MfGMYMnXbRZ6Q2mDfuIl6q4U kkFQHRKTtEugyrLQ+gxoDDI= X-Google-Smtp-Source: AA0mqf46kscSVm8Efdr903MJm+cO6oziFKi6+/wvY3+FgGUk8mlcCWauzzkyEOowGHfUvy6GJic+Og== X-Received: by 2002:a05:6a00:410b:b0:56b:dc84:7783 with SMTP id bu11-20020a056a00410b00b0056bdc847783mr70991789pfb.35.1670274146835; Mon, 05 Dec 2022 13:02:26 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b00189c62eac37sm5121805plk.32.2022.12.05.13.02.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Dec 2022 13:02:26 -0800 (PST) In-Reply-To: <87r0xedr55.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=casouri@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300942 Archived-At: > On Dec 5, 2022, at 3:30 AM, Theodor Thornhill = wrote: >=20 > Mattias Engdeg=C3=A5rd writes: >=20 >> 5 dec. 2022 kl. 09.58 skrev Theodor Thornhill : >>=20 >>> I agree - but in most tree-sitter languages it seems like there = usually >>> is no distinction between them. We need to implement some = heuristics to >>> locate a comment above method etc, if I'm not mistaken. >>=20 >> At least distinguish doc comments by their special syntax, such as = `-- >> !` or `/**`; it's better than nothing and only requires local >> analysis. A grammar tie-in to make sure they aren't misplaced is >> obviously better (and valuable) but it can be a later improvement. >=20 > Sure, but I don't think it's too hard. We could do something like (on > emacs-29 branch): >=20 > diff --git a/lisp/progmodes/java-ts-mode.el = b/lisp/progmodes/java-ts-mode.el > index 2c42505ac9..abf67a4c14 100644 > --- a/lisp/progmodes/java-ts-mode.el > +++ b/lisp/progmodes/java-ts-mode.el > @@ -123,13 +123,24 @@ java-ts-mode--operators > "|=3D" "~" ">>" ">>>" "<<" "::" "?" "&=3D") > "C operators for tree-sitter font-locking.") >=20 > +(defun java-ts-mode--font-lock-comment (node override start end &rest = _) > + (when (or (equal (treesit-node-type node) "block_comment") > + (equal (treesit-node-type node) "line_comment")) > + (let ((face (if (equal (treesit-node-type = (treesit-node-next-sibling node)) > + "method_declaration") > + 'font-lock-doc-face > + 'font-lock-comment-face))) > + (treesit-fontify-with-override > + (treesit-node-start node) (treesit-node-end node) > + face override start end)))) > + > (defvar java-ts-mode--font-lock-settings > (treesit-font-lock-rules > :language 'java > :override t > :feature 'comment > - `((line_comment) @font-lock-comment-face > - (block_comment) @font-lock-comment-face) > + `((line_comment) @java-ts-mode--font-lock-comment > + (block_comment) @java-ts-mode--font-lock-comment) > :language 'java > :override t > :feature 'constant >=20 >=20 > This naive function will work for comments directly above a method. = It > won't try to fix annotations and do other smartness. The local = analysis > is actually a little more complex because you need to extract the > comment text and scan it. Is a more robust variant of this of = interest? Yeah! Throw in some checks for empty lines and `-- !` or `/**` (when = applicable) and it=E2=80=99ll be good to go. Yuan=