From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sami M'Barek Newsgroups: gmane.emacs.help Subject: Eglot gopls and organize imports Date: Wed, 11 Jan 2023 08:32:03 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20347"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 11 08:33:09 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1pFVbh-000544-2k for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 11 Jan 2023 08:33:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFVb8-0001GJ-Hm; Wed, 11 Jan 2023 02:32:34 -0500 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 1pFVb5-0001G8-RA for help-gnu-emacs@gnu.org; Wed, 11 Jan 2023 02:32:32 -0500 Original-Received: from pv50p00im-ztdg10021801.me.com ([17.58.6.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pFVb3-0003TQ-Py for help-gnu-emacs@gnu.org; Wed, 11 Jan 2023 02:32:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hamb.se; s=sig1; t=1673422345; bh=9U4gWYL9dOd9s6tgR2aXoJKTSiptwg9vwWk9Pr3zFH8=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LHYTmYZhELEX7HFfYt9CZfirQoJluVIyPc9gX+hZQ/1RHsEqqdw9yybh5K1mg+Q8/ cFScDQWvv7tSWnj3tydsfkKnErBXg47tAiG1CDR+PkaB17yy/zhNzXVut45mkZY7Fx +4L7W2CM1ngSMGY12G9H4OI8/b7ff1meBOcVkrvIIeUTBM6RuSvhFjubWTpaj2Ne1t i3Mdwn6Vmv50wgfq568B+M23LEmhL2T6BmV6tuP8NDLfsA+FsTrCI83syTkKREefW1 tz/mR4+f5EmcRZcMyZjlfAVrSsot4do4Gxk7xTA4YpkkAJfrjn0K3pj5SzAzwrrL/c o5s/WBvi+C5DQ== Original-Received: from rhea.local (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id 97056160A0C for ; Wed, 11 Jan 2023 07:32:23 +0000 (UTC) X-Proofpoint-ORIG-GUID: VeLXF6TWIac_uE80mVrS4H3EocEWGBJB X-Proofpoint-GUID: VeLXF6TWIac_uE80mVrS4H3EocEWGBJB X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.517,18.0.572,17.0.605.474.0000000_definitions?= =?UTF-8?Q?=3D2022-06-21=5F01:2022-06-21=5F01,2020-02-14=5F11,2020-01-23?= =?UTF-8?Q?=5F02_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=621 clxscore=1030 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2301110056 Received-SPF: pass client-ip=17.58.6.56; envelope-from=sami@hamb.se; helo=pv50p00im-ztdg10021801.me.com 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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:142202 Archived-At: I=E2=80=99m trying to get the code action of organize imports to work with = before-save-hook. Specifically for go-mode. I=E2=80=99ve been searching around and found a couple of issues later linki= ng to a solution similar to this: (defun sami/eglot-organize-imports () (call-interactively 'eglot-code-action-organize-imports)) (defun sami/before-saving-go () (add-hook 'before-save-hook #'eglot-format-buffer -10 t) (add-hook 'before-save-hook #'sami/eglot-organize-imports nil t)) (add-hook 'go-mode-hook #'sami/before-saving-go) Problem seems to be, running the function eglot-code-actions and selecting = Organize imports works fine, but running the stand-alone function of eglot-= code-action-organize-imports does not yield anything. Test case: Open emacs with emacs -q for an empty config (require 'go-mode) (require 'eglot) (add-hook 'go-mode-hook #'eglot-ensure) In any go file, add something like fmt.Println(=E2=80=9Chello=E2=80=9D) sho= uld import the package fmt automatically, deleting or commenting the line d= oes not delete the imported package fmt. eglot-code-action-organize-import= s does not delete the imported package fmt. Running the function eglot-code= -actions and selecting Organize imports DOES delete the package fmt from im= ports. Here is the client-request and server-response. [client-request] (id:613) Mon Dec 5 23:43:48 2022: (:jsonrpc "2.0" :id 613 :method "textDocument/codeAction" :params (:textDocument (:uri "file:///Users/sami/Code/Go/src/sami/something/temp.go") :range (:start (:line 5 :character 6) :end (:line 5 :character 10)) :context (:diagnostics [] :only ["source.organizeImports"]))) [server-reply] (id:613) Mon Dec 5 23:43:48 2022: (:jsonrpc "2.0" :result [(:title "Organize Imports" :kind "source.organizeImports" :edit (:documentChanges [(:textDocument (:version 172 :uri "file:///Users/sami/Code/Go/src/sami/something/t= emp.go") :edits [(:range (:start (:line 3 :character 2) :end (:line 3 :character 2)) :newText "bytes\"\n \"crypto/tls\"\n \"encoding/json\"\n \"") (:range (:start (:line 4 :character 2) :end (:line 4 :character 2)) :newText "go/token\"\n \"") (:range (:start (:line 5 :character 10) :end (:line 5 :character 10)) :newText "\"\n \"sami/something/models\"\n \"sami/something/tool")])]))] :id 613) Single difference between the usage of eglot-code-action-organize-imports a= nd not is ... :only ["source.organizeImports"]))) ... emacs-28.2 (emacs-mac, railwaycat/emacsmacport/emacs-mac) eglot-20221020.1010 (melpa)