-
Hi, I'm facing a strange issue that only global
Minimal configuration (mandatory);;; emacs -Q -l ~/.config/emacs/test.el
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(package-install 'eglot)
(require 'eglot)
(require 'tramp)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-hook 'python-mode-hook
(lambda ()
(setq-local eglot-workspace-configuration
'((:python . (:venvPath "/data/wangtianshu/.local/share/conda/envs"))))
(eglot-ensure))) manually run If I use global eglot-workspace-configuration, it takes effect. ;;; emacs -Q -l ~/.config/emacs/test.el
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(package-install 'eglot)
(require 'eglot)
(require 'tramp)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-hook 'python-mode-hook
(lambda ()
(setq-default eglot-workspace-configuration
'((:python . (:venvPath "/data/wangtianshu/.local/share/conda/envs"))))
(eglot-ensure))) LSP transcript - M-x eglot-events-buffer (mandatory unless Emacs inoperable)important diff part I think (remove the different of id and time) of two events buffer (global vs local)
setq-local:
setq-global
Backtrace (mandatory, unless no error message seen or heard):No. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 14 replies
-
I can reproduce this, and what's more, I can reproduce this by setting |
Beta Was this translation helpful? Give feedback.
-
Stepping through the E.g., if I'm visiting the file (defun eglot--uri-to-path (uri)
"Convert URI to file path, helped by `eglot--current-server'."
(when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
(let* ((server (eglot-current-server))
(remote-prefix (when (and server
(file-remote-p
(project-root (eglot--project server))))
(project-root (eglot--project server))))
(retval (url-filename (url-generic-parse-url (url-unhex-string uri))))
;; Remove the leading "/" for local MS Windows-style paths.
(normalized (if (and (not remote-prefix)
(eq system-type 'windows-nt)
(cl-plusp (length retval)))
(substring retval 1)
retval)))
(concat remote-prefix normalized))) I filed #879 to change this behavior, but I'm not sure there isn't a deeper bug here |
Beta Was this translation helpful? Give feedback.
-
Thanks for your analysis, Andreas!
I'll have a look at your PR
…On Sun, Mar 13, 2022, 17:06 Andreas Fuchs ***@***.***> wrote:
Stepping through the eglot-handle-request method for
workspace/configuration, I think I see why this doesn't set local
variables from the .dir-locals.el file, at least: The form (eglot--uri-to-path
scopeUri) on a remote server doesn't return the path to the project - it
only returns the path to the TRAMP prefix.
E.g., if I'm visiting the file
/scpx:ferdl.hack:/home/asf/Hacks/cloud/infra/backend.py, that form
returns /scpx:ferdl.hack: instead of (what I'd expect, given the
description and behavior in local files)
/scpx:ferdl.hack:/home/asf/Hacks/cloud. Indeed, manually patching the
function to return the full project prefix instead of just the remote part
does apply local variables set via .dir-locals.el correctly:
(defun eglot--uri-to-path (uri)
"Convert URI to file path, helped by `eglot--current-server'."
(when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
(let* ((server (eglot-current-server))
(remote-prefix (when (and server
(file-remote-p
(project-root (eglot--project server))))
(project-root (eglot--project server))))
(retval (url-filename (url-generic-parse-url (url-unhex-string uri))))
;; Remove the leading "/" for local MS Windows-style paths.
(normalized (if (and (not remote-prefix)
(eq system-type 'windows-nt)
(cl-plusp (length retval)))
(substring retval 1)
retval)))
(concat remote-prefix normalized)))
—
Reply to this email directly, view it on GitHub
<#876 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC6PQ25PT3WVPVJLA7ZSYTU7YVCBANCNFSM5QSYHKVQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Reproduce steps without tramp:
mkdir test_project
cd test_project
git init
touch test.py
;;; emacs -Q -l ~/.config/emacs/test.el
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
(package-initialize)
(package-install 'eglot)
(require 'eglot)
(require 'tramp)
(setq native-comp-async-report-warnings-errors nil)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-hook 'python-mode-hook
(lambda ()
(setq-local eglot-workspace-configuration
'((:python . (:venvPath "/Users/wangtianshu/.local/share/conda/envs"))))
(eglot-ensure)))
;;; emacs -Q -l ~/.config/emacs/test.el
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
(package-initialize)
(package-install 'eglot)
(require 'eglot)
(require 'tramp)
(setq native-comp-async-report-warnings-errors nil)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-hook 'python-mode-hook
(lambda ()
(setq-default eglot-workspace-configuration
'((:python . (:venvPath "/Users/wangtianshu/.local/share/conda/envs"))))
(eglot-ensure)))
As we can see: local |
Beta Was this translation helpful? Give feedback.
-
This is by design. You're supposed to set eglot-workspace-confuguration
project-locally, because that's what it is, a project-local setting
(project ~= workspace).
And the only current way to do that is either globally or through
dir-locals.el.
The real problem of that other issue is that tramp directories aren't --
apparently -- being correctly calculated.
…On Fri, Jul 15, 2022, 18:09 JD Smith ***@***.***> wrote:
See also the very closely related #967
<#967>. The behavior there
occurs locally, no tramp involvement needed. I believe it is this
with-temp-buffer that causes the "falling back on the default value"
issue:
(cl-defmethod eglot-handle-request
(server (_method (eql workspace/configuration)) &key items)
"Handle server request workspace/configuration."
(apply #'vector
(mapcar
(eglot--lambda ((ConfigurationItem) scopeUri section)
(with-temp-buffer
—
Reply to this email directly, view it on GitHub
<#876 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC6PQY5L3ZNUSOHUJ33H2DVUGLLDANCNFSM5QSYHKVQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I claim you do want some variability based on the singular & special buffer from which the lsp server is started. For example, I have a small package which updates the path to the python executable, setting up a virtual environment, for each new python buffer opened. This runs before eglot is started. There are many tools which do something like this. I want any LSP server started from there to have the correct venv configured. A function call e-w-c, which could examine default directory, could also work well for this.
Doesn't eglot consider the current buffer when starting the server, examining the buffer's mode for example to pick a server command to run? So it already does consider "one file from the project". The config functionality people are after is in that same vein: on first start of a server, setup not just the server command, but alter some of its initial config as well. Or do you mean, having started a server from a buffer, you later close all buffers from the associated workspace? And then for some reason the already running server (sans buffers) asks again for the configuration? I can certainly see how that would be a problem if the correct information is kept in (now lost) buffer-local state.
I can see the argument here. And I now understand why eglot processes requests in a temp buffer with the .dir-locals applied. A function call version of BTW, eglot declaring the variable with |
Beta Was this translation helpful? Give feedback.
-
After trying it out in-depth today I found that it now works fine without the hack. |
Beta Was this translation helpful? Give feedback.
After trying it out in-depth today I found that it now works fine without the hack.