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: treesit-range-settings with ':local' : I missed something or it's a bug? Date: Fri, 26 Jan 2024 20:32:02 -0800 Message-ID: <5C4F13B5-3FE3-499E-8F23-8B528AF194B7@gmail.com> References: <6107698.MhkbZ0Pkbq@3-191.divsi.unimi.it> 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="38528"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Vincenzo Pupillo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 27 05:32:49 2024 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 1rTaN6-0009rF-QW for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jan 2024 05:32:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTaMe-0005Pq-19; Fri, 26 Jan 2024 23:32:20 -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 1rTaMc-0005Jl-Fy for emacs-devel@gnu.org; Fri, 26 Jan 2024 23:32:18 -0500 Original-Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rTaMZ-0006bx-MX for emacs-devel@gnu.org; Fri, 26 Jan 2024 23:32:17 -0500 Original-Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-600273605a9so10696577b3.1 for ; Fri, 26 Jan 2024 20:32:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706329934; x=1706934734; darn=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=VPp+J7yHb3KreBx4/1Kmbrfnpnz2Z19K+jHPphx601g=; b=JY4TMgcg8tstHjBd9w5ROnROtAlrkeEgUBlZxWGYbwE38qPhjMihEWsb59EgUEatQr YhRMyS7AZbtdwg5sB+C2han6yblttyRumtPIinRWOJkjy0FBYPX9oQAEtN/UPbqUoXYi 7trIcsz71D276PdjViE3lDfhu84Ov6GitlloWwg1K1M2lMF+1s83Qn9vNu5ylZZ/Ck0K T/DGgWqnH4APlqA17feFE4sVQb+PXd8F1BxutsUYf8rsucMNA5uYTpVtHaTz9lg1dojG /g6ps4pKOem3XZGxx7vCVgxlIW0vYNX7AT61HVsMkAbfqAMhz1hu3f4/85Ns7lvFN5XY npPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706329934; x=1706934734; 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=VPp+J7yHb3KreBx4/1Kmbrfnpnz2Z19K+jHPphx601g=; b=Scc8bM79GPna/s8rV8DgDbYo2aU+nM/iRx45atGk91Iq0EQNoOXkZDGL1Lev6ehf5O ShDBZq9M/+zLxwjJpDYaU5FCq70QVAz97MhNN4oWe/uMUkrhkauJeFXhcxIR3kNf5A7z 1AE7LWIYkv/7isUlDBB8q33oBATE2H4GtavHqix4bKavCC0OBK5buH9ui+cOz6fp2YzT Cq1JSn8NCENjbtpGQ1TLyY+egzykDr1/a6WqVFinc6myzIpPyl5fjXxWtYLhgWgaKfA9 UO0RtMgfHOAFMOyDGBlIic4QcoDgDJ8kw9I+4pxkbmsdVFgrTLME5+GDVZ9gKRsFs8O4 fw4w== X-Gm-Message-State: AOJu0Ywbful00crcNYFJ0Stt7ghJkcAqgrXm1Q7zmqWIQ1ondPwgmwDu PRaYwQLkXX9+MrLvzvuV3VWveFXAnONUNd1UvKjQafriYHpH4G3T X-Google-Smtp-Source: AGHT+IFLimfCvCMrN4Ep5UO+poJhTOiM38onII/aL13UK0wudsRf5y8bzzqGs3/B3YDGMSqNLvEb9A== X-Received: by 2002:a81:7608:0:b0:602:d13f:1d1d with SMTP id r8-20020a817608000000b00602d13f1d1dmr853195ywc.101.1706329934301; Fri, 26 Jan 2024 20:32:14 -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 c3-20020a170903234300b001d8b4d501f8sm250537plh.124.2024.01.26.20.32.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2024 20:32:13 -0800 (PST) In-Reply-To: <6107698.MhkbZ0Pkbq@3-191.divsi.unimi.it> X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::1135; envelope-from=casouri@gmail.com; helo=mail-yw1-x1135.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, T_SCC_BODY_TEXT_LINE=-0.01 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:315462 Archived-At: > On Jan 11, 2024, at 3:15 AM, Vincenzo Pupillo = wrote: >=20 > Hi,=20 > in the php-ts-mode I am writing, I am trying to use the = tree-sitter-phpdoc parser=20 > (I had tried before but without success, and I currently use a font = block based=20 > on regular expressions).=20 > tree-sitter-phpdoc requires a single doc block (a single /** */ doc = block and=20 > nothing else, no /* */ or #). I wrote these range rules: > (setq-local treesit-range-settings > (treesit-range-rules > :embed 'phpdoc > :host 'php > :local t > '(((comment) @cap > (:match "/\\*\\*" @cap))) >=20 > :embed 'html > :host 'php > '((program (text) @cap) > (text_interpolation (text) @cap)) >=20 > :embed 'javascript > :host 'html > :offset '(1 . -1) > '((script_element > (start_tag (tag_name)) > (raw_text) @cap)) >=20 > :embed 'css > :host 'html > :offset '(1 . -1) > '((style_element > (start_tag (tag_name)) > (raw_text) @cap)))) >=20 > With html, js and css it works fine. With phpdoc I tried with or = without :local.=20 > Without :local the parse intervals are all null. Without :local on the = other hand they are correct. > With this simple php snippet: > =20 > /** > * Test class > * @author v > */ > class Test { > /** @see http://example.com the lib */ > function test() { > echo "prova"; > } > } >=20 > Without :local the field rules are: > ((# ((1 . 1) (8 . 64) (82 . 120))) = (# parser for html> ((1 . 1) (1 . 2))) (# ((1 . = 1)))=20 > (# ((1 . 1))) (# nil)) >=20 > With :local the result is: > ((# nil) (# nil)=20= > (# nil) (# nil)=20= > (# nil)) >=20 >=20 > With :local the treesit-language-at breaks, and js or css rules=20 > are also applied to php code :-( >=20 > I tried tracking the node location sent from the parser to the = font-lock-rules I wrote for phpdoc,=20 > with :local the result is: >=20 > phpdoc-block node-start=3D 8 node-end=3D 64 start=3D 1 end=3D 166 > phpdoc-block node-start=3D 82 node-end=3D 120 start=3D 1 end=3D 166 > phpdoc-block node-start=3D 1 node-end=3D 166 start=3D 1 end=3D 166 >=20 > the first two are right, the last one is not. >=20 > Any idea? > Tested with: > GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.39, = cairo version 1.18.0) of 2024-01-11 >=20 >=20 > Thanks >=20 > p.s. the function I wrote to get the ranges is: > (defun php-ts-mode--get-parser-ranges () > "Return the ranges covered by the parsers. >=20 > `php-ts-mode' use 5 parsers, this function returns, for the > current buffer, the ranges covered by each parser. > Usefull for debugging." > (let ((ranges)) > (if (not (treesit-parser-list)) > (message "At least one parser must be initialized")) > (cl-loop > for parser in (treesit-parser-list) > do (push (list parser (treesit-parser-included-ranges parser)) = ranges) > finally return ranges))) IIUC your problem is that treesit-language-at doesn=E2=80=99t work, = right? Have you assigned treesit-language-at-function? People often = assume treesit-language-at works automatically when they define = treesit-range-rules. But you actually need to define = treesit-language-at-function. Yuan=