From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sebastian Poeplau Newsgroups: gmane.emacs.devel Subject: eglot's interface for major modes Date: Fri, 07 Apr 2023 20:20:03 +0200 Message-ID: <874jpr35eh.fsf@mailbox.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27664"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 07 21:07:19 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pkrQd-000716-I4 for ged-emacs-devel@m.gmane-mx.org; Fri, 07 Apr 2023 21:07:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkrQ0-0001Xk-2P; Fri, 07 Apr 2023 15:06:40 -0400 Original-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 1pkqxr-0002bv-3J for emacs-devel@gnu.org; Fri, 07 Apr 2023 14:37:35 -0400 Original-Received: from mout-p-201.mailbox.org ([80.241.56.171]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1pkqxp-0000wK-8F for emacs-devel@gnu.org; Fri, 07 Apr 2023 14:37:34 -0400 Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4PtRtb0nFVz9sQ8 for ; Fri, 7 Apr 2023 20:37:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1680892647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=B/uTlAIQl+B01AQjAoVr85uSlcKa7b+sg3/Ea2vwWWc=; b=VXU6JAutsMr4v2gSpurbSaBWdT7PXyZT0IQpx8oq/gMRSis3mb9mZfuK6CprOXMaPMOqaB m6ahy5A520s+iXKAyEdgLzEL17C2rbtj4/RFO+CUx9O3HAlrLWYptL87HQWLTrnZAOjnhQ q2FncJxETq/prAKX/yPVw7GNLDhfVwevaB+dJLGbap4QoMM1Xq9dx2S9ijaR0uQls3UkeO j2lbHKZkEnW+Ma/1ljsR0Aix2OM6Iqq/a1yErfCl0+c/Vlq2l+7NNPz6R8ez3vKdvjURVu EhS2caRrD6/N6PIQOA+Uvc4Q5wLzCqFiCT2C2RmxZ4PDx4ul/ywoYzfPR9+fhA== X-MBO-RS-META: mp4djmrzzwqz3np9bi5w51r4k7ihuopr X-MBO-RS-ID: ef8e7f165a9332777c4 Received-SPF: pass client-ip=80.241.56.171; envelope-from=sebastian.poeplau@mailbox.org; helo=mout-p-201.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 07 Apr 2023 15:06:36 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:305163 Archived-At: I'm using eglot with the Ada Language Server [1]. The server exposes a custom command "als-other-file", whose purpose is to jump between specification and implementation, a bit like `ff-find-other-file' for C. Upon receiving the command, the server sends a "window/showDocument" request [2] to the client, specifying the file to open. Here's the code I use: (defun ada-light-other-file () "Jump from spec to body or vice versa using the Ada Language Server." (interactive) (if-let ((server (eglot-current-server))) (eglot-execute-command server "als-other-file" (vector (eglot--TextDocumentIdentifier))) (message "%s" "Not connected to the Ada Language Server"))) (unless (cl-find-method 'eglot-handle-request nil '(t (eql window/showDocument))) (cl-defmethod eglot-handle-request (_server (_method (eql window/showDocument)) &key uri &allow-other-keys) (find-file (eglot--uri-to-path uri)) (list :success t))) It works, but I wanted to discuss two things: 1. My function `ada-light-other-file' uses eglot's API `eglot-execute-command', but I wasn't able to find a public function that returns the document ID, hence my use of `eglot--TextDocumentIdentifier'. Do you think it makes sense to add one? 2. Should the handler for "window/showDocument" be part of eglot? By the way, I edit Ada code with a custom major mode [3], but the actual major mode being used shouldn't matter here. [1] https://github.com/AdaCore/ada_language_server [2] https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showDocument [3] https://github.com/sebastianpoeplau/ada-light-mode