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 ms5.migadu.com with LMTPS id QAnYKd1yQmMrTQAAbAwnHQ (envelope-from ) for ; Sun, 09 Oct 2022 09:06:05 +0200 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 uMbKKd1yQmNA8gAAauVa8A (envelope-from ) for ; Sun, 09 Oct 2022 09:06:05 +0200 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 39648204E3 for ; Sun, 9 Oct 2022 09:06:05 +0200 (CEST) Received: from localhost ([::1]:35498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohQNv-0002JQ-Q7 for larch@yhetil.org; Sun, 09 Oct 2022 03:06:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohQNG-0002JH-U5 for emacs-orgmode@gnu.org; Sun, 09 Oct 2022 03:05:22 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:42802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohQNE-0000MX-Pb for emacs-orgmode@gnu.org; Sun, 09 Oct 2022 03:05:22 -0400 Received: by mail-pl1-x630.google.com with SMTP id c24so7926370pls.9 for ; Sun, 09 Oct 2022 00:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=oB4PtMA7ZqJE677JLkIGnvoylIhUIL+keBowdmXoQyA=; b=WWIeXe6cAt/5iEkAaP2QYzQ/rdhyHPSNpM/xJkGKIH2/bpxiPOgYQeSEGYwz7ElQmh T3mM7utGtDidB7n4gMTaAqfiHcygzE2gmolw+T9ltLRAq2K2siI8RKLb8c5tOljHtR22 jMMhRiaIkFoh+pPVRQohmR7zLjrZaUibW2aHicxMb0DspStb5uO8wtMcOfCOGDOAgZLI WD2OH9nynSL4Vruw5K93P9wrAk+a8CTQ4POI8rniWmSUdQkk77IH15ZP/ftTZfuZxwCS M5jGhhg8k1rfUFhG6Btta4gHpLCobVHSus0+YBvEh0bRzRyeogQm6/gz8s7uuK/Kb/qz 3IkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oB4PtMA7ZqJE677JLkIGnvoylIhUIL+keBowdmXoQyA=; b=ICfZPsPp7C+5pHnky7ChmAKzcVvdBr5cFGYcFjZOb0ry72mtpxRCBBnoh/bhnO0mkf rgkj5rsckAUma52H3fBLwX6yP94qX9zs7ZoIR0Seg6tuPfJdP22DZrG/FRHqPhev8ver ggL3CR1DBI5QZuSdD16NHKZshUhzlKSTg4wm9d5inDLe2rG6ZUTqCw8BXLYpIJsAOW7A UZVKaAp00tQibqM3EiGvSXNvCzTP6XPbeujd1I6iKs7sEMgqhXL5YjyRyAlzZeXOIr/f Wzb0fdYWU1MfPxHQbRQcn3+HtPcY/jMS8nZmqCha+9ulGcU+E9UMIxp+w0AX4bL1oBJg hqTQ== X-Gm-Message-State: ACrzQf3AX6SeL9n34ysNCP9zUn1Xunt/A93v3oKT/nRRhnyJAPgcPNAi c7arnFwEpYEcRb3UqAJS80g= X-Google-Smtp-Source: AMsMyM6jO6+PHj3pFyKf+zHVdINKysb2R7vehTSqSEUaxaLk4ukdNkVqNRZ85/POsinNgJBp/5hEXQ== X-Received: by 2002:a17:90b:388a:b0:205:daae:295c with SMTP id mu10-20020a17090b388a00b00205daae295cmr14598453pjb.203.1665299119194; Sun, 09 Oct 2022 00:05:19 -0700 (PDT) Received: from localhost ([2409:8970:af2:32f:6c23:3ad5:f37d:541b]) by smtp.gmail.com with ESMTPSA id h15-20020a170902680f00b0017f7c4e260fsm4276965plk.150.2022.10.09.00.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 00:05:18 -0700 (PDT) From: Ihor Radchenko To: Karthik Chikmagalur Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] LSP support in org-src buffers In-Reply-To: <87bkqmdhqz.fsf@gmail.com> References: <87bkqmdhqz.fsf@gmail.com> Date: Sun, 09 Oct 2022 15:06:09 +0800 Message-ID: <87mta5ease.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=yantar92@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" 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=1665299165; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=oB4PtMA7ZqJE677JLkIGnvoylIhUIL+keBowdmXoQyA=; b=ocLz4AgMJp6ffNUjxVSzxWjYoOl7ktK/KjkAOfpYoWDphKtFKEyEgFXr8xLN4ijXzM89LO jC73/+LYMpHhCEDuuynYcEgqVh4asQYiXSx35+4FwckZLtPpAoimcckC3o4WbiBt+U+JF0 YWGaRw6bP0dxYRkTfwcjt9nN9SoQc7XVgbG2yWcNu12ZyDSjDqUaiRFhS1Yo9IskUUiEpq 08W+4hwMFPlGelDN+tA7TJoqBdRcGoUDEvyxwN9hfi4nW927yujTs80WJ2iWXI8ucqNGTb E1cteDb8hs608Io162oDocBEpA5zzDWmYq7TAeIk4Vp1HMqy6sL3HDaznLW7CA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665299165; a=rsa-sha256; cv=none; b=HsWSyFlvDiMDL9vtHoL5Mcyipa+ybmVe5T4URlZYjFZBjug4LKma1Sw1c5c0wXgqfoJOkn 8aKzXekG3TxcxCRebgh4k6yS+wNnyDLSYADqCR6r5SjZkZIgNMLLT0QGFA2labyoFSxWAy MqBSRN4TczkuUXNe0mh4QRlcFGadOKz3HuE01iN75mUln7plSVi5p/Y7Zq1+1uycc1gYWq FmdO00tgtTCR2eckQwYUbwQb9HrK5YLz0Lhh2EuaJmEZTcqUT5C2knL2uHfmXll+kgIcli POEmZDMi0iQkcRNCt12q8asAzvcV5fa1T31UE35jUMaJJwSGkUCqCj/BxwZQyw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=WWIeXe6c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.89 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=WWIeXe6c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 39648204E3 X-Spam-Score: -1.89 X-Migadu-Scanner: scn1.migadu.com X-TUID: LyTUtJYs+X0u Karthik Chikmagalur writes: > I've added limited support for LSP via Eglot in org-src-mode buffers. I was intending to publish it as a package but it was suggested to me that it could live as part of Org instead, especially now that Eglot is intended to be part of the upcoming Emacs release. Here are some details: > ... > It allows you to run Eglot in org-src buffers opened with org-edit-special (C-c '), giving you context-aware completion, linting, code actions etc. > ... > The main problem with reconciling org-src-mode and Language Server (LS) support is that the LSP requires and expects files, not buffers. By default, org-src buffers are not associated with files. Even if one were to associate an org-src-mode buffer with a file, set the correct default-directory for a project and start Eglot, it would only contain the small chunk of code from the current code block. The LS cannot access enough code to form a useful picture of the project. Thanks for your interest in contributing to Org core! Transparent code editing in org-src buffers is certainly a feature that is requested by many. Starting from people complaining about flycheck giving nonsense errors in org-src buffers extending to any other serious development work that relies on the existing project development toolchains. This is not limited to Eglot support. M-x compile, eglot, project.el, xrefs, and similar tools all assume that current code buffer is associated with a real file in a real project folder, possibly containing all kinds of hints like .gitignore, .dir-locals.el, etc. > org-src-context-mode reuses the tangling machinery to populate an org-src buffer with code from all blocks associated with the current tangle file, and associates it with a temporary file. This way, the LS has a better picture -- if still limited to a single file -- of the project. > > org-src-context-mode then checks if there's an appropriate Eglot LSP connection active, and reconnects to it. > > Only the contents of the current code block are editable. The other blocks are marked read-only and (by default) only visible by widening the buffer. No actual tangling is done -- the default-directory of the org file is not touched at all. This sounds a bit fragile and full of caveats. You already implemented a way to associate the org-edit-src buffer with the fully tangled code. Then, why not make it simple and do the real tangling first and then make org-edit-src work directly with a real file buffer associated with the tangled file? All the tools, including Eglot will then work naturally and as intended. The only tricky problem I am seeing with your approach is dealing with noweb references. Care should be taken about editing code blocks containing noweb. > (v) org-src-context-mode does some pseudo-tangling -- this is required to specify what constitutes a "file" for the LS to parse. This adds a performance penalty to org-edit-src-code that can be noticeable if you have many (100+?) code blocks with the same tangle file as the current block. Our to-be-released main branch does tangling orders of magnitude faster. For example, my config.org with 660 src blocks tangles within 1.3 sec. This can be made even faster by extra caching if there is a real demand for super-fast tangling. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at