From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id CPyVGkQagGOkfAAAbAwnHQ (envelope-from ) for ; Fri, 25 Nov 2022 02:28:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 71WQGkQagGPWGgAA9RJhRA (envelope-from ) for ; Fri, 25 Nov 2022 02:28:36 +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 1B8792755A for ; Fri, 25 Nov 2022 02:28:36 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyNVl-0001ip-NI; Thu, 24 Nov 2022 20:28:13 -0500 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 1oyNVg-0001gU-EL for guix-patches@gnu.org; Thu, 24 Nov 2022 20:28:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyNVc-0000xI-Uq for guix-patches@gnu.org; Thu, 24 Nov 2022 20:28:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyNVc-0000dQ-Qn for guix-patches@gnu.org; Thu, 24 Nov 2022 20:28:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v7 29/32] gnu: Add rust-tree-sitter-for-emacs. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 25 Nov 2022 01:28:04 +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.16693396582357 (code B ref 49946); Fri, 25 Nov 2022 01:28:04 +0000 Received: (at 49946) by debbugs.gnu.org; 25 Nov 2022 01:27:38 +0000 Received: from localhost ([127.0.0.1]:60929 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyNVB-0000bq-JX for submit@debbugs.gnu.org; Thu, 24 Nov 2022 20:27:38 -0500 Received: from mout.gmx.net ([212.227.17.21]:53197) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyNV2-0000aM-L1 for 49946@debbugs.gnu.org; Thu, 24 Nov 2022 20:27:29 -0500 Received: from localhost.localdomain ([82.69.64.142]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MKKUp-1pKASX2f31-00LnrN; Fri, 25 Nov 2022 02:22:22 +0100 From: Pierre Langlois Date: Fri, 25 Nov 2022 01:21:39 +0000 Message-Id: <20221125012142.22579-30-pierre.langlois@gmx.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221125012142.22579-1-pierre.langlois@gmx.com> References: <87mtfi63ut.fsf@gmx.com> <20221125012142.22579-1-pierre.langlois@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:zBgujInTmLA9ug+YTlRRIQylsNSC9dZtPVBF5yjWvNK/3rfv9DT R8Y70PZ+U2VALYTo8693E2PTsIxdzkHxlPSulwTVvRSMYSAG7o91p288cVCJutT4UGfuyFh /q5zdRb5eECkYHJkwxo1iH+org3HEg/nVlAB2UGiki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43C1f9Ba3MU= 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-bounces+larch=yhetil.org@gnu.org 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=1669339716; 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; bh=VYkgPodYuerTyCcfGxiN/3kzAhGcv7jwS1nxeXr5gq4=; b=BQGrPlbCaWiDMUIRJ4laWK3JdfM9I5dWX1+HsrdUfaOOz1FJ8wPjYpSI29trdICCvrAr+i PXSi8HIinpcGht5youOt+w4z4w6uK6vpBMfMPmSZkIVvXpLSIDndyiVVM1FiIElI/DbkdR 3rljgGHUS+G7KNBWpFHVX2AIzXf5QFPpFYja/hz6RZ/5g4VNRR+5ziixeXf4AcKcoJq231 44/fpxqIbKh5k4rVLH3YOTy28MNkE7LfF9gbj0kn2uLwbmT5jJazredHfKn7fbdICUk3Xm iLv0QfxHDkJQ2a90eDis6VPx3z/knh91niy1wVBqwEHj6JKWsv6+E6kzqMLNpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1669339716; a=rsa-sha256; cv=none; b=ZUvk2AOk5JHBVMZaPaleww/FFS2iuupxg5A5nyZSbcWy9ov6zI4ypPXqPfBA2RewSwbwaT heK1MwHQUhA129t9wP+zk1EPCU/ZsyBw23PTWPsvyueYLVsY4ecYv1Hn/SDVyHjXguYF/H RJTY/VpXmsDf+gXlGbiRPLhyOURhmoOC6XQx0Tr3NIGCNWZYB540FRMujTw5NKApXr5M8u VCRjjoaZ+aCd1g2/HXKdINQvJCYz2tBhwnndjaqxACkwYNHqEm17+FSeUpr4I+MCfNpcgY lksbRfMRJNNSlGVtwglYD0E2Nq4izq3/A+uizVyd476I49whIDYddsLGgSsqFQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" 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: 3.42 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" 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: 1B8792755A X-Spam-Score: 3.42 X-Migadu-Scanner: scn1.migadu.com X-TUID: XvSS1vYUg474 * 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. --- gnu/local.mk | 1 + .../rust-tree-sitter-text-provider-fix.patch | 98 +++++++++++++++++++ gnu/packages/tree-sitter.scm | 14 +++ 3 files changed, 113 insertions(+) create mode 100644 gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch diff --git a/gnu/local.mk b/gnu/local.mk index 7d11f4bb27..961d90bee9 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1832,6 +1832,7 @@ dist_patch_DATA = \ %D%/packages/patches/rust-nettle-disable-vendor.patch \ %D%/packages/patches/rust-nettle-sys-disable-vendor.patch \ %D%/packages/patches/rust-openssl-sys-no-vendor.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..215e7fc18b --- /dev/null +++ b/gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch @@ -0,0 +1,98 @@ +From e3576b180488b8231e1fc0ca130748577579d129 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Tu=E1=BA=A5n-Anh=20Nguy=E1=BB=85n?= +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 e88a411c..cf214d92 100644 +--- a/binding_rust/lib.rs ++++ b/binding_rust/lib.rs +@@ -5,6 +5,7 @@ mod util; + use std::os::unix::io::AsRawFd; + + use std::{ ++ borrow::Cow, + char, error, + ffi::CStr, + fmt, hash, iter, +@@ -183,7 +184,8 @@ pub struct QueryCaptures<'a, 'tree: 'a, T: TextProvider<'a>> { + } + + pub trait TextProvider<'a> { +- type I: Iterator + 'a; ++ type I: Iterator>; ++ + fn text(&mut self, node: Node) -> Self::I; + } + +@@ -1840,19 +1842,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 = chunks.next().unwrap_or(&[]); ++ ) -> Cow<'a, [u8]> { ++ let first_chunk = chunks.next().unwrap_or(Cow::Owned(vec![0u8; 0])); + if let Some(next_chunk) = 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 + } +@@ -1888,7 +1890,7 @@ impl<'a, 'tree> QueryMatch<'a, 'tree> { + match node { + Some(node) => { + let text = get_text(buffer1, text_provider.text(node)); +- r.is_match(text) == *is_positive ++ r.is_match(&text) == *is_positive + } + None => true, + } +@@ -2002,23 +2004,24 @@ impl<'cursor, 'tree> fmt::Debug for QueryMatch<'cursor, '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 = I; ++ type I = 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 = iter::Once<&'a [u8]>; ++ type I = 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 ca92fccfd6..d0214f3a12 100644 --- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -27,6 +27,7 @@ (define-module (gnu packages tree-sitter) #:use-module (guix git-download) #:use-module (guix packages) #:use-module (guix utils) + #:use-module (gnu packages) #:use-module (gnu packages crates-graphics) #:use-module (gnu packages crates-io) #:use-module (gnu packages icu4c)) @@ -196,6 +197,19 @@ (define-public rust-tree-sitter parsing library.") (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 (inherit rust-tree-sitter) + (source (origin + (inherit (package-source rust-tree-sitter)) + (patches (search-patches + "rust-tree-sitter-text-provider-fix.patch")))) + ;; Do not show this package in the UI as it's only meant to be used for + ;; emacs's tree-sitter module. + (properties '((hidden? . #t))))) + (define tree-sitter-delete-generated-files '(begin (delete-file "binding.gyp") -- 2.38.1