Subject: bug#72701: eglot crash when project-files-relative-names t

From: Dmitry Gutov <[email-masked]>
Date: Fri, 23 Aug 2024 02:22:52 +0300

Hi!

On 18/08/2024 18:43, Ship Mints wrote:
> project-files-relative-names was introduced a few months ago, so it's no 
> surprise that there are some side effects when set.
> 
> This affects the handler for workspace/didChangeWatchedFiles. The result 
> is that dirs-to-watch...
> 
>           (dirs-to-watch
>            (delete-dups (mapcar #'file-name-directory
>                                 (project-files
>                                  (eglot--project server))))))
> 
> ...is nil when project-files-relative-names is t, due to 
> file-name-directory failing to parse the directories it was expecting. 
> This results in file-readable-p failing with a nil dir:

You're not really supposed to customize it as an end user (or at least 
not yet) - the caller code either sets it to t to indicate support for 
relative names, or not.

>           (watch-dir (dir)
>             (when-let ((probe
>                         (and (file-readable-p dir)
> 
> One solution which I've tested is simply the defensive:
> 
>           (project-files-relative-names nil) ; add this
>           (dirs-to-watch
>            (delete-dups (mapcar #'file-name-directory
>                                 (project-files
>                                  (eglot--project server))))))

...that said, someday the default value of this var will be flipped, and 
some changes like that might be needed.

The relative version is a bit faster, though, so maybe Eglot could 
switch to relative names too. If it makes sense.