From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qIqQFISxD2JbwgAAgWs5BA (envelope-from ) for ; Fri, 18 Feb 2022 15:47:32 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id +KIDEYSxD2L6ewAAauVa8A (envelope-from ) for ; Fri, 18 Feb 2022 15:47:32 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A832F258DA for ; Fri, 18 Feb 2022 15:47:31 +0100 (CET) Received: from localhost ([::1]:39278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nL4Xi-0003qC-NN for larch@yhetil.org; Fri, 18 Feb 2022 09:47:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nL4WI-0002FZ-TA for guix-patches@gnu.org; Fri, 18 Feb 2022 09:46:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:59966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nL4WI-0006QL-H5 for guix-patches@gnu.org; Fri, 18 Feb 2022 09:46:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nL4WI-0000ET-G4 for guix-patches@gnu.org; Fri, 18 Feb 2022 09:46:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v4 25/31] gnu: Add rust-tree-sitter-for-emacs. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 18 Feb 2022 14:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49946 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49946@debbugs.gnu.org Cc: Pierre Langlois Received: via spool by 49946-submit@debbugs.gnu.org id=B49946.1645195516792 (code B ref 49946); Fri, 18 Feb 2022 14:46:02 +0000 Received: (at 49946) by debbugs.gnu.org; 18 Feb 2022 14:45:16 +0000 Received: from localhost ([127.0.0.1]:53853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nL4VX-0000Cb-Bu for submit@debbugs.gnu.org; Fri, 18 Feb 2022 09:45:15 -0500 Received: from mout.gmx.net ([212.227.17.22]:49327) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nL4VQ-0000BU-LT for 49946@debbugs.gnu.org; Fri, 18 Feb 2022 09:45:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1645195502; bh=t6GcbpfJsTEUh0uqMEnAVGdtZAU4rJJ3B/CJ7mwhhFE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=VaCMCnOaXolgoXKHdua5X7tHxF1iPHpf09DRRD6tCvNYxECRdD0umRUYH/TxCELHo QokVI15m+8qe62ZSOS6yDtaJJvqxzmJNBTmdpQaL4vaGmM2m44Aa0JdeAWIfJZpzma qXZ46pX3482imTnfF3/kveIyBmtThOcSH+0ur00M= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([82.69.64.142]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MMGNC-1nb56t3nJ0-00JKfr; Fri, 18 Feb 2022 15:40:02 +0100 From: Pierre Langlois Date: Fri, 18 Feb 2022 14:39:42 +0000 Message-Id: <20220218143948.28989-25-pierre.langlois@gmx.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218143948.28989-1-pierre.langlois@gmx.com> References: <877d9s2qa9.fsf@gmx.com> <20220218143948.28989-1-pierre.langlois@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jDwuDTG87g1DDlihetmQfsiJxQo35NxMz38bvSlH3jEymD54i3B 6U1mrkDESvSKzatNJIkSYDqdp9+8lmpaYgAyVnv3tU6g/KpCrlEDb1e3feVuAsMv17wjMgM qlpcTlr7d8Qnz3FnkcbXYuHriYtjUUB0KtOI/4mRPre62wC6vBKLzKGau/0EagHay7gAICX UENrC2lq1JqAKKmM+8Miw== X-UI-Out-Filterresults: notjunk:1;V03:K0:jZSA774ahfs=:kUirvADLJ3ahqm8aUG0ylu 85o53qlnUqxmaSK7jJFRmHrbmzvygABa105tYeRym4Zbwpzz7Tqpte36E2wFRJX98+87rMtgz NMJzeYnDOqJBGHcc6Oy+GbD7m++seQHBPgZQj5otOtlX8NCPuxvGKmwdN61cFblgeGivqZiAr xcyxr0F3KW7wxFp6b7RWPzEz4H9EPCX+u46/taDdiwKkigbVM6WNNzqCjzE1HArNUvTLgRk4r AQvcAytCL6QPHNG9XWW9INaJcMutJMV8texw300c0sRbHvUgjZn3ZsZoq2mgEO4lj2chAlpW6 WvqYjmjIxOHOrLxrSyGSHxForQm2tfXZHc+vfodqRJH8ygObhLO77V1oJ0NPKH8Ok/oOqteLT 4VDjagDQPD+lrtBjpKpW6vNJK89pAljwCnxZ8NOpUX8HkUJrJX0/aIYXiibxekY5lDbQfwEPh /yMLQR3wE1e6iIXPLrAQ2o18KeojX30UcouZprFsYbMRFA7I2yUGvsd3vAdC4bnVeEgLvfL00 3FSYvrJWdu5wH1Y1TtBdSaXCO2oyxFQsNcdGI5GRg21tTt241l4QH0nDuBuMbDwD2dHRyEYEy 4B1BHM9jZdXsj/D0J3tGlqFp+E6lbXq748/HK63dN0aw6Xss2GMbT10s/QhOI1COEkmXA9gMp kKWKHYSQZuCfqrvOeWT/2Nw8C2AkNsprtcBaO2+YtGc6LZlOd6HAIK8Z//AlvhDY0FB+Vaw1/ jKqy+1cUaCufN7G7D96ZmEdpZtDHv4Gxxyp24GRNR95LJAS9hFMsK71e+xYjjkyfwzguh0bmP 70D0ScEWppahuIIdHX0bXPBEeKFiaSx0l1J7axkK21QYVe02inma8AnKNHebpD84n0Z3dvPN4 N2Fl93CaH1PU7oUjWDnfu91nAcUpIPg/6dub3FRRwYaVPoJp6MUZLirSV388kPBVi17quuNzK S/SMub3jxthop92zVd2X6C3vWJrJapBim2U4/iqCvPrBZrWN8CkePYdQ41CDhZzddRjdjU3mz 3fgj2qnpQfUUpOzGRc4QVkA99Z5NQDlTa8Rz66G2asiOcx70D0DtWnMmiuYBv5rWAVVBSPaCp SnMysmARExQQ7I= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645195651; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=FlXzO/n1Am5eCb7w6Vle+CsDp19X63uflkk9NdrT9Kw=; b=EK0ps49o+Z3Z/R/mOKntlHDWvZA3xZKf6Axgi6PZqNQkPP1i9210/KSsgg9H0B2DrAKszo ESxsFL6sP04BMsHKrdb1L2Nnuuf13gERDal/dwbh+um4k8++vAlnEZNqC1fbuf+0ZlLXnL a9UYkzeQzCHp3vNPhmT0Ap6gJVeltLyGNOxY9u/4BjtgLkGtFBQs+/P5VuRErbqn98hQx7 ddnZtBOUQI3TdjEFkg3bpWhLqXSytlG5i0zyfMB56TfL6eEmaXU3LsDvYVhMEe4+WQA1hW Ixw0Db1h/d9abXdJYBB81vyyAvcduGvjA8hXhfcGh9n28zNPoo57bqVlc8Vnag== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645195651; a=rsa-sha256; cv=none; b=eqvVRX9H9mg26lvIyDmncQji+0HbVzdGh+5Vueo45gUASofd8vl5RtnrGwXVMi5hUUVIWf Vm15sQ0fumsxeqbpIXgH71unAT0fUpLRKpkiNufeI4gBamc31w1Ac5x5x59hwwFq/k+9mV QL9F16rSXTNutpQ/awNUKKQ66a4vdQ/SN2iMtf1eQotAML2E0GRLnPK2mzlCj8C4sSdEBl uZiPtf8O62oksyv5gDrlrqL3Vo4B84HihxkqJSElYf+5+z7sZTWAVOej2fqVrkIP8IjWJn SfPmwp9IVl7foXFhxCzhXSR0+cF3Tt25ZgrxDPEB0HmPNXZIxRLPSMiylOH5dQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=VaCMCnOa; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -0.63 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=VaCMCnOa; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A832F258DA X-Spam-Score: -0.63 X-Migadu-Scanner: scn0.migadu.com X-TUID: RZUfraHqcjfp * gnu/packages/tree-sitter.scm (rust-tree-sitter-for-emacs): New variable. * gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. =2D-- gnu/local.mk | 1 + .../rust-tree-sitter-text-provider-fix.patch | 98 +++++++++++++++++++ gnu/packages/tree-sitter.scm | 45 +++++++++ 3 files changed, 144 insertions(+) create mode 100644 gnu/packages/patches/rust-tree-sitter-text-provider-fi= x.patch diff --git a/gnu/local.mk b/gnu/local.mk index 97ab160c3c..0c113956d3 100644 =2D-- a/gnu/local.mk +++ b/gnu/local.mk @@ -1775,6 +1775,7 @@ dist_patch_DATA =3D \ %D%/packages/patches/rust-nettle-sys-disable-vendor.patch \ %D%/packages/patches/rust-openssl-sys-no-vendor.patch \ %D%/packages/patches/rust-shell2batch-lint-fix.patch \ + %D%/packages/patches/rust-tree-sitter-text-provider-fix.patch \ %D%/packages/patches/rust-wl-clipboard-rs-newer-wl.patch \ %D%/packages/patches/sbc-fix-build-non-x86.patch \ %D%/packages/patches/sbcl-aserve-add-HTML-5-elements.patch \ diff --git a/gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch= b/gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch new file mode 100644 index 0000000000..beda2d8391 =2D-- /dev/null +++ b/gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch @@ -0,0 +1,98 @@ +From 475b822f47bdc58d832533448b6f6d9818554f37 Mon Sep 17 00:00:00 2001 +From: =3D?UTF-8?q?Tu=3DE1=3DBA=3DA5n-Anh=3D20Nguy=3DE1=3DBB=3D85n?=3D +Date: Sun, 25 Jul 2021 13:11:52 +0700 +Subject: [PATCH] Allow TextProvider's iterators to generate owned text + +--- + binding_rust/lib.rs | 33 ++++++++++++++++++--------------- + 1 file changed, 18 insertions(+), 15 deletions(-) + +diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs +index 068a60285..79c3991ed 100644 +--- a/binding_rust/lib.rs ++++ b/binding_rust/lib.rs +@@ -8,6 +8,7 @@ pub mod allocations; + use std::os::unix::io::AsRawFd; + + use std::{ ++ borrow::Cow, + char, error, + ffi::CStr, + fmt, hash, iter, +@@ -162,7 +163,8 @@ pub struct QueryCaptures<'a, 'tree: 'a, T: TextProvid= er<'a>> { + } + + pub trait TextProvider<'a> { +- type I: Iterator + 'a; ++ type I: Iterator>; ++ + fn text(&mut self, node: Node) -> Self::I; + } + +@@ -1799,19 +1801,19 @@ impl<'a, 'tree> QueryMatch<'a, 'tree> { + buffer2: &mut Vec, + text_provider: &mut impl TextProvider<'a>, + ) -> bool { +- fn get_text<'a, 'b: 'a, I: Iterator>( ++ fn get_text<'a, 'b: 'a, I: Iterator>>( + buffer: &'a mut Vec, + mut chunks: I, +- ) -> &'a [u8] { +- let first_chunk =3D chunks.next().unwrap_or(&[]); ++ ) -> Cow<'a, [u8]> { ++ let first_chunk =3D chunks.next().unwrap_or(Cow::Owned(vec![= 0u8; 0])); + if let Some(next_chunk) =3D chunks.next() { + buffer.clear(); +- buffer.extend_from_slice(first_chunk); +- buffer.extend_from_slice(next_chunk); ++ buffer.extend_from_slice(&first_chunk); ++ buffer.extend_from_slice(&next_chunk); + for chunk in chunks { +- buffer.extend_from_slice(chunk); ++ buffer.extend_from_slice(&chunk); + } +- buffer.as_slice() ++ Cow::Borrowed(buffer.as_slice()) + } else { + first_chunk + } +@@ -1835,7 +1837,7 @@ impl<'a, 'tree> QueryMatch<'a, 'tree> { + TextPredicate::CaptureMatchString(i, r, is_positive) =3D= > { + let node =3D self.nodes_for_capture_index(*i).next()= .unwrap(); + let text =3D get_text(buffer1, text_provider.text(no= de)); +- r.is_match(text) =3D=3D *is_positive ++ r.is_match(&text) =3D=3D *is_positive + } + }) + } +@@ -1946,23 +1948,24 @@ impl<'cursor, 'tree> fmt::Debug for QueryMatch<'c= ursor, 'tree> { + } + } + +-impl<'a, F, I> TextProvider<'a> for F ++impl<'a, F, I, T> TextProvider<'a> for F + where + F: FnMut(Node) -> I, +- I: Iterator + 'a, ++ T: Into>, ++ I: Iterator, + { +- type I =3D I; ++ type I =3D iter::Map Cow<'a, [u8]>>; + + fn text(&mut self, node: Node) -> Self::I { +- (self)(node) ++ (self)(node).map(T::into) + } + } + + impl<'a> TextProvider<'a> for &'a [u8] { +- type I =3D iter::Once<&'a [u8]>; ++ type I =3D iter::Once>; + + fn text(&mut self, node: Node) -> Self::I { +- iter::once(&self[node.byte_range()]) ++ iter::once(Cow::Borrowed(&self[node.byte_range()])) + } + } + diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm index 309b38386d..3c8b4588c4 100644 =2D-- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -22,9 +22,11 @@ (define-module (gnu packages tree-sitter) #:use-module (guix build-system cargo) #:use-module (guix build-system gnu) #:use-module (guix build-system node) + #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix packages) #:use-module (guix utils) + #:use-module (gnu packages) #:use-module (gnu packages algebra) #:use-module (gnu packages crates-graphics) #:use-module (gnu packages crates-io) @@ -150,6 +152,49 @@ (define-public tree-sitter-cli This package includes the @command{tree-sitter} command-line tool.") (license license:expat))) +;; We need to apply a patch in order to compile the rust bindings against= the +;; emacs tree-sitter module. +;; See https://github.com/tree-sitter/tree-sitter/pull/1294 +(define-public rust-tree-sitter-for-emacs + (package + (name "rust-tree-sitter") + (version "0.20.0") + (source + (origin + (method url-fetch) + (uri (crate-uri "tree-sitter" version)) + (file-name (string-append name "-" version ".tar.gz")) + (sha256 + (base32 + "1yg4p54hsfsxxknjq492i8b4rvibzpl2zdvr2bwvwakqgah05v33")) + (patches (search-patches "rust-tree-sitter-text-provider-fix.patc= h")) + (modules '((guix build utils))) + (snippet + '(begin + ;; Force + (delete-file-recursively "src") + (delete-file "binding_rust/build.rs") + (with-output-to-file "binding_rust/build.rs" + (lambda _ + (format #t "fn main() {~@ + println!(\"cargo:rustc-link-lib=3Dtree-sitter\");= ~@ + }~%"))) + #f)))) + (build-system cargo-build-system) + (inputs (list tree-sitter)) + (arguments + `(#:tests? #f ;; Running tests misinterprets comments as doc-tests. + #:cargo-inputs + (("rust-cc" ,rust-cc-1) + ("rust-lazy-static" ,rust-lazy-static-1) + ("rust-regex" ,rust-regex-1) + ("rust-spin" ,rust-spin-0.7)))) + (home-page "https://tree-sitter.github.io/tree-sitter/") + (synopsis "Rust bindings to the Tree-sitter parsing library") + (description "This package provides Rust bindings to the Tree-sitter +parsing library.") + (license license:expat))) + (define tree-sitter-delete-generated-files '(begin (delete-file "binding.gyp") =2D- 2.34.0