From patchwork Thu Feb 10 22:55:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Langlois X-Patchwork-Id: 37189 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 547DC27BBE9; Thu, 10 Feb 2022 22:58:09 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9F7B927BBEA for ; Thu, 10 Feb 2022 22:58:08 +0000 (GMT) Received: from localhost ([::1]:43168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nIIO7-0002nY-Od for patchwork@mira.cbaines.net; Thu, 10 Feb 2022 17:58:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIIMF-0007nq-O9 for guix-patches@gnu.org; Thu, 10 Feb 2022 17:56:11 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:35443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nIIMF-0006Kq-9M for guix-patches@gnu.org; Thu, 10 Feb 2022 17:56:11 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nIIMF-0000zi-9N for guix-patches@gnu.org; Thu, 10 Feb 2022 17:56:11 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [WIP PATCH v3 20/26] gnu: Add rust-tree-sitter-for-emacs. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Feb 2022 22:56:11 +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.16445337693779 (code B ref 49946); Thu, 10 Feb 2022 22:56:11 +0000 Received: (at 49946) by debbugs.gnu.org; 10 Feb 2022 22:56:09 +0000 Received: from localhost ([127.0.0.1]:57563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIIMC-0000yZ-2e for submit@debbugs.gnu.org; Thu, 10 Feb 2022 17:56:08 -0500 Received: from mout.gmx.net ([212.227.17.20]:55089) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIILm-0000sG-Hj for 49946@debbugs.gnu.org; Thu, 10 Feb 2022 17:55:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644533736; bh=V2yBM0BuNrEVzKpJYz/VmalXddCqD74QybapS1w5/hg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Bp8d1tElh2cfDlkfuNjNvINMPZASd9gyZpMbvqtJ0xjnZO30dJEZXb1Oovt1yBq50 x+1aW/c+S3xdb4wAOd3w/6CgMuvDZ5SaZ+1lg3j+UNCDvJ6zBkF+CG+wcjwAA4Jl2J g6JuYdKZ/NMTNccTh6c04qxRuJgCoAgdpDlLeMTM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([82.69.64.142]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MK3Vu-1nbc9O2huY-00LX8z; Thu, 10 Feb 2022 23:55:36 +0100 From: Pierre Langlois Date: Thu, 10 Feb 2022 22:55:21 +0000 Message-Id: <20220210225527.25189-20-pierre.langlois@gmx.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220210225527.25189-1-pierre.langlois@gmx.com> References: <87leyinxly.fsf@gmx.com> <20220210225527.25189-1-pierre.langlois@gmx.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:oWu6wrLwLRhpQMWtO+x4MDl9ApJAq7k+mfP1ooOXyhouQa4cCob Np3NWR28BgiHgfg5dnHYZjhd2/J2p7i/J5uoQMg274P2fSV6xovmWop3FUq0qMYCe1BKnfY fwSYK/STJL/v5xFztx6E50NUmELwFdCAf8oVfF05aNv8y1iO/TFr7+Uhv0lEVNqUd2U19Nn scHdH4u1OjULl80Ctxmfg== X-UI-Out-Filterresults: notjunk:1;V03:K0:TUrukI0IOvs=:fKovlJb5MiZ36RYlAJEKFs axYNafc7FL8MwG+TyDPRR38s3ighIF9NVp/XdJ6j5GCK9tJ3ioK8EV7WQ46qEjJ451PiH8+Ny gApZEG8C3wE8s7AUCsVrIuSwgGd5SlFv/VmBuLv/COOKhKKKkHOpWRYiDSSZ/s1gnqiDa2Gto of2xQt7Fy73jdBgxbn3LBSynm4uWRgknqO3/grGaQgw0MJYuOLMLEg18cE6UQjlIW3f+ZaTp1 gkfxXONAzgIjYL45vxUN1/I+jH7V8OfYWf+2Vq6kJQ2WmUN+Atki4lVYomLBUebeDKFAAXnTE lX4GVFLmmPoXNP7nyvQvnePsPYaIpwK5zSWpx9T6OHQLUG06yl3nIh/i0ZWcTpw2DGyswQhF7 a9gfmIg3cd5XJcILS0b0n8IWViUcygN5CUUbQKYnaqsEzIw0/q9vXoCiU4uAM2hk3ItZViLy6 BL0O5vgJip+qltpRA449cWlVTe+hC/tKG8jYydo+KO3yMRycvqcGTof9NreRyTC9SDtMEX55e w4aFptDSmY6TlIk66vypq4badpbstyuKNA4eToyvvzVXchcce78Rxw8CtnFie4ro05nfd9VfP eeDun/wTH3OYTm+rFi+eFRGbBBRJmkbvWdtCz9vDDZLNT6SbxqxEMDBIdu0vnZ2GTGlOCUwLk aMR9bRsHj+XKTjvt3CMsYkahX/oN3fgteIIWr0Pt7kkC1sVpvtgLtAPqYSZRk5dvfaD2xlyOp rusj69TI+uUBV0yX9bcSGt0x1j4eTKPpKHBQj+K+bnW90PwBFqCeXvXbvVBdlD6fES6KQ3gEH LRBUtENqyTMc2U5peQXcBIH1Nq/BWm+V2I/D9LAKM8aTpElFkdL6HPLTog7rxl9Yy4Gpk24Hl YEw4iqYMn2FUXydCrtukHzO5+QsnkNJxXKcPeUqtrwhJwDVRGDBuDX8di5KK25WtispRJuTaP Y2998I+ySwfIkIznqSbCsHubbYwS8gScF9ZOcg5Oq7Ea1BJRsL4Ll7psC/DfTCmP/Mfr1VeuQ isQxCCrOYf46nJsTxuFmBrWibwWMFXNHTDfU9W5TLyBwv2Tb+DGRBHtC9r6s7IQaeR+vee2fd vEZL6iWClpXPc0= 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 | 45 +++++++++ 3 files changed, 144 insertions(+) create mode 100644 gnu/packages/patches/rust-tree-sitter-text-provider-fix.patch -- 2.34.0 diff --git a/gnu/local.mk b/gnu/local.mk index 273d80a9c2..f2b6f0afdd 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1811,6 +1811,7 @@ dist_patch_DATA = \ %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 --- /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: =?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 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: TextProvider<'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 = 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 + } +@@ -1835,7 +1837,7 @@ impl<'a, 'tree> QueryMatch<'a, 'tree> { + TextPredicate::CaptureMatchString(i, r, is_positive) => { + let node = self.nodes_for_capture_index(*i).next().unwrap(); + let text = get_text(buffer1, text_provider.text(node)); +- r.is_match(text) == *is_positive ++ r.is_match(&text) == *is_positive + } + }) + } +@@ -1946,23 +1948,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 2dcf4dae87..c86244a300 100644 --- a/gnu/packages/tree-sitter.scm +++ b/gnu/packages/tree-sitter.scm @@ -23,9 +23,11 @@ (define-module (gnu packages tree-sitter) #:use-module (guix build-system gnu) #:use-module (guix build-system node) #:use-module (guix gexp) + #: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) @@ -146,6 +148,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.patch")) + (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=tree-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-origin name version hash) (origin (method git-fetch)