From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aFDvOVx172OgJgEAbAwnHQ (envelope-from ) for ; Fri, 17 Feb 2023 13:38:53 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id GPcMOVx172OSFwEAG6o9tA (envelope-from ) for ; Fri, 17 Feb 2023 13:38:52 +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 9AE191557D for ; Fri, 17 Feb 2023 13:38:52 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pT007-0003kV-3j; Fri, 17 Feb 2023 07:38:07 -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 1pT004-0003gO-BO for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:04 -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 1pT004-0000zv-1T for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pT003-0001Ia-TX for guix-patches@gnu.org; Fri, 17 Feb 2023 07:38:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v8 4/7] gnu: Add rust-tree-sitter-for-emacs. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 17 Feb 2023 12:38:03 +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.16766374614902 (code B ref 49946); Fri, 17 Feb 2023 12:38:03 +0000 Received: (at 49946) by debbugs.gnu.org; 17 Feb 2023 12:37:41 +0000 Received: from localhost ([127.0.0.1]:38707 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSzzg-0001Gt-HZ for submit@debbugs.gnu.org; Fri, 17 Feb 2023 07:37:41 -0500 Received: from mout.gmx.net ([212.227.17.22]:57025) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSzzX-0001FH-6a for 49946@debbugs.gnu.org; Fri, 17 Feb 2023 07:37:33 -0500 Received: from localhost.localdomain ([82.69.64.142]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1N6KUT-1oVLyO1dgv-016jwx; Fri, 17 Feb 2023 13:37:25 +0100 From: Pierre Langlois Date: Fri, 17 Feb 2023 12:37:19 +0000 Message-Id: <20230217123722.15143-5-pierre.langlois@gmx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217123722.15143-1-pierre.langlois@gmx.com> References: <20221125012142.22579-1-pierre.langlois@gmx.com> <20230217123722.15143-1-pierre.langlois@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:j0tnocQARpj2yRjuiZad6JcrpKULbc+YhjughTCWUZwLNsgsZT7 NA16XziDXU7AFj8x34hohsnPeGCh3zwvkdLsKrrmgpg+h9+lB9wrnHBGAL5TWwijx5lpayr eUbuOwVGp5SsKbK2VD2vbBSreuwfGAEJl+18rJW/ONj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GzKE+7+Y= 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-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676637532; a=rsa-sha256; cv=none; b=q5428Q2vQIMz2/C1w71BKLQmOElmLfgD/FSEu8oRIe6BrHMxXV21EiWFg+8JyewI3VAkiZ HmYWYVaPwl9chXiQhFMMG3cQeTwkDGU5znuZ5sspSjSIXEo5KYwahGuEAZfSVKlsYpvRz3 1S/wPjGyFfcEDyg/UaYXhbFAwHLjc9OoywRaH2KTbOmDCa+FYImdonRnuVtykv6wf7DgJt VcWYXelo+MeQYeJdwhjirxQuP9yUOmCLgIqzIDDYDuWF0hMyhyYmlnynmrzKk8Sst61BZY MOG6pJMjmSBYNYtq79huAHH/wj6id+hc/C4WXx+zA6R4V9Q0cynkyZNxsafQXw== 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676637532; 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=wdxbgHxmuj1Wjqm+Pl77J8VQbdfIJHF5UBcUF6cPgAc=; b=EBIZrENNcHXCGh6iWZW0Dxtc4ykUSlJZ8lkscVcfvU9H4KYSd9n0Nk9JhPhoRHblbChuTE KPwJSU/X92vh1uS+0oMmaxoCaOenk+V+b2zm8BXnDvPP07v6CLWpYXLv2kxoGo2ixVXZZ2 E2hFxiksqsqrc2z8fT2bzTsdF3Ngam72tycqzAzTrlKA29S0pUA1RgAIHyoBUvGLqM8m5C 2vMW36sKsdtjMIGW2SCEUSLhwMbtFD2WcOEyhPXiN/TSql7tLNeD98bcwW2efSmp9e/EG7 CC6cj6A3eAGMPbBSf8LRv7VJ6GMdbzSpa6MuRnk987tkcgYmh4/V0d7vQhOR8Q== X-Migadu-Spam-Score: -1.63 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: 9AE191557D X-Migadu-Scanner: scn1.migadu.com X-Spam-Score: -1.63 X-TUID: dn9mvZRBpA5e * 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 5fcbdd4586..1dd98592b5 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1831,6 +1831,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/rw-igraph-0.10.patch \ %D%/packages/patches/sbc-fix-build-non-x86.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 7256ad02e4..bb9972cb00 100644 --- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -22,6 +22,7 @@ (define-module (gnu packages tree-sitter) #:use-module ((guix licenses) #:prefix license:) + #:use-module (gnu packages) #:use-module (gnu packages crates-graphics) #:use-module (gnu packages crates-io) #:use-module (gnu packages graphviz) @@ -225,6 +226,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 grammar-directories) #~(begin (use-modules (guix build utils)) -- 2.39.1