From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simon Pugnet Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter: issue embedding HTML, CSS, JavaScript within a new php-ts-mode Date: Fri, 10 Feb 2023 11:40:32 +0000 Message-ID: <87y1p53fqv.fsf@polaris64.net> References: <87o7q3ngu8.fsf@polaris64.net> <494661C8-02BC-4A22-9217-B2110A8D0668@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29801"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs developers To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 10 13:19:24 2023 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 1pQSN9-0007Wh-0n for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Feb 2023 13:19:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQSME-0005lt-N2; Fri, 10 Feb 2023 07:18:26 -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 1pQRrH-0001i1-3H for emacs-devel@gnu.org; Fri, 10 Feb 2023 06:46:27 -0500 Original-Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1pQRrE-0000P7-OV for emacs-devel@gnu.org; Fri, 10 Feb 2023 06:46:26 -0500 Original-Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4PCsQ30QPWz9sTM; Fri, 10 Feb 2023 12:46:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polaris64.net; s=MBO0001; t=1676029579; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Kbyi/iwB+61AgJWqMoWDhHkaIrU8xGs/mejBP3H6LqQ=; b=UoF+A5iHeCEB7Hbrvm6s3dZUyTF5dG6kHmGaiTZRPxhFqyzSPqYmNq1ON6tkQc6ExHxle4 FEqQK2SRitmWAZVYAko/xgpoQeBCdrK/OVLKrX9gTuOXvoBMY2qUejj2pNeNLiHbtG6dNY THJmJFrC8KewEfE+G9ZCLQLMdFQQ6xtvKg1eNSHcqFBY3GXDFiw04htgyhQnqILdYrmj7i h/8FE+jjLxx4h3xaPbPtpNtEhg/+WbOC7jzKATHJp1Sk72DGyeWvCfymwR6POG1rGyZwwV Hflzgnzhr+SLYScwe0UQENs64IKItdTgfF9S2V082kQhcgacrpQ/8SSIWMcWwg== In-reply-to: <494661C8-02BC-4A22-9217-B2110A8D0668@gmail.com> Received-SPF: pass client-ip=2001:67c:2050:0:465::102; envelope-from=simon@polaris64.net; helo=mout-p-102.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 10 Feb 2023 07:18:24 -0500 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:303106 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Yuan Fu writes: > Hey Simon, > > Thanks for trying this out! Feedbacks like this are very welcome. Hi Yuan, you're very welcome! I'm glad to be able to help. >> On Feb 9, 2023, at 4:45 AM, Simon Pugnet =20 >> wrote: >>=20 >> 1. Based on my rules for embedding =3D'html=3D within =3D'php=3D above,= =20 >> should I expect ~(treesit-language-at (point))~ to return =3D'php=3D=20 >> when the point is within a PHP region? > > Because we don=E2=80=99t have much experience with tree-sitter and its > interfaces, I made treesit-language-at simply delegate work to > treesit-language-at-point-function, which can be an arbitrary > function, giving developers maximum flexibility. You need to set=20 > that > variables to a function, otherwise treesit-language-at simply=20 > returns > the first parser in the parser list. Ah, that makes sense, thank you. I must have missed that in the=20 documentation as I thought this was just used when overriding the=20 default behaviour. I've added the following implementation and this appears to work=20 nicely: - (defun php-ts--language-at-point (point) "Return the language at POINT, used to determine which tree sitter=20 parser to use." =20=20 (let* ((php-node-at-point (treesit-node-at point 'php)) (parent-node (treesit-node-parent php-node-at-point))) (if (and (string-equal "text" (treesit-node-type=20 php-node-at-point)) (or (string-equal "program" (treesit-node-type=20 parent-node)) (string-equal "text_interpolation"=20 (treesit-node-type parent-node)))) 'html 'php))) The next step will be to run further tests on the current node in=20 cases where the language is 'html in order to determine if the actual=20 language is 'css or 'javascript. >> 2. Is my goal of embedding HTML within PHP, then embedding CSS and=20 >> JavaScript/TypeScript within HTML feasible and if so am I going=20 >> about this in the right way? > > It should be. Although I didn=E2=80=99t thought of having multiple layers= of > embedded language (in this case PHP embedding HTML embedding > CSS/Javascript), if you order the entries in treesit-range-rules=20 > like > you do now (outer most host language, then embedded language, then > embedded embedded language), it should work. Try setting > treesit-language-at-point-function and it should work right. If not=E2=80= =A6 > then we need to look into it. I'll try this next and I'll be sure to let you know how it goes. Thanks for your advice, and kind regards, =2D-=20 Simon Pugnet https://www.polaris64.net/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJIBAEBCAAyFiEEO/eF3hYsAMj7Tab9uhNZqCwLPvkFAmPmLogUHHNpbW9uQHBv bGFyaXM2NC5uZXQACgkQuhNZqCwLPvmPGw/+KXVSmi+huyps/JU+0p4HFu5fYQ6s kjyBJsLmqcDNR2eybVsXZW96vDZ9qNdB5vOfCMZqYWuw87j/t3ITziAT0F2ncuUI deGjr+p3onzTgKX/2IX9cmbAq7Ko/do4zJolh2SHUj5eB2GvYLDdraecQb2xXyK4 STXe1CbI94XHu1SQ4pC9DCncmDDKuwlDJOeZMNwkx8LurzsU9OmJK7S+c9HAJJ5T rIzmolbIglxqdbWEhk7BDb9gNvnixBzAzLWea8JD/jZnWAAKLzH7lwrG1+q7Ynaj gcWu2UzxGZ+I5rsaZ69u0izFS/Mwmk1BvUuFpzs3+JUF0WJRUndSfuVotZ7vtDGM VfPVD4YIWRgmHdkJv0ePNf8LLnTXY9z9H1FjVUUnq0vrG67ndZuTHulFzZALI4sx zpKtInfFd2ksQAO4L0NFxJRHCTTTWskk+Exe6WOsaSl9Kx8Lqy6y2LqJoKY/P/nf 1aqHHQ1xF3rkZNPchsZZ0yYPiRKWiRnM1qVkTMZUSVI791qc475lVpkTx+Uw1cle pifRBDHLmYu+gLITid5up0bV2r9kre4/hz9/Lp2xxIJDbuaE2vbXXgJrlv7WbjZ/ cuNJoGr0gXmXOnojgknLuYigjjlXrDwocpiVzo4geoY7HlAofVC4MABFT2EgH3hS xzzUGZgaxUELRGk= =bk2L -----END PGP SIGNATURE----- --=-=-=--