Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new Clojure file with æ/ø/å in the filename breaks workspace/willRenameFiles #1813

Open
magnars opened this issue May 13, 2024 · 1 comment
Labels
API Related to API / CLI bug Something isn't working

Comments

@magnars
Copy link

magnars commented May 13, 2024

Describe the bug

Saving a new file with characters from a non-US alphabet will throw an "Internal Error", in Emacs preventing the buffer from being marked as saved. The current workaround I have found is to save the file in fundamental-mode. Once it exists, lsp no longer throws.

To Reproduce

  1. Create a new file in an lsp-enabled Clojure project, call it something quirky, like kåre.clj
  2. Try saving the file.
  3. See "Internal Error"

Expected behavior

I was hoping to save my file without workarounds. 😅

User details:

  • OS: Emacs on MacOS

  • Version:

    clojure-lsp 2024.04.22-11.58.08-nightly
    clj-kondo 2024.03.13

Additional context

Toggling on debug-on-error in Emacs shows this stack:

Debugger entered--Lisp error: (error "Internal error")
  signal(error ("Internal error"))
  error("Internal error")
  lsp-request("workspace/willRenameFiles" #<hash-table equal 1/65 0x47ec724d>)
  lsp--on-rename-file(#<subr rename-file> "/Users/magnars/work/parenteser/src/parenteser/kåre..." "/Users/magnars/.emacs.d/backups/!Users!magnars!wor..." t)
  apply(lsp--on-rename-file #<subr rename-file> ("/Users/magnars/work/parenteser/src/parenteser/kåre..." "/Users/magnars/.emacs.d/backups/!Users!magnars!wor..." t))
  rename-file("/Users/magnars/work/parenteser/src/parenteser/kåre..." "/Users/magnars/.emacs.d/backups/!Users!magnars!wor..." t)
  backup-buffer()
  basic-save-buffer-2()
  basic-save-buffer-1()
  basic-save-buffer(t)
  save-buffer(1)
  funcall-interactively(save-buffer 1)
  call-interactively(save-buffer nil nil)
  command-execute(save-buffer)

Looking at the stack trace, here's what happens:

  • Emacs keeps a backup of the file somewhere while it is unsaved.
  • When saving, it triggers a rename-file which in turn triggers the lsp-mode rename-file hook
  • This performs the workspace/willRenameFiles

This works as expected with regular characters, but breaks with æ/ø/å and presumably other non-US alphabet chars.

So, the problem is actually renaming files with strange chars. Due to the way Emacs handles new files, this leaks into saving any new files with strange chars.

@magnars magnars added API Related to API / CLI bug Something isn't working labels May 13, 2024
@magnars
Copy link
Author

magnars commented May 13, 2024

Having tried (naively) to reproduce it it clojure-lsp's test suite, it might come down to this:

(shared/uri->filename "file:///user/project/src/my/kåre.clj")

1. Unhandled java.lang.IllegalArgumentException
   Bad escape

         UnixUriUtils.java:   88  sun.nio.fs.UnixUriUtils/fromUri
UnixFileSystemProvider.java:  125  sun.nio.fs.UnixFileSystemProvider/getPath
                 Path.java:  204  java.nio.file.Path/of
                Paths.java:   98  java.nio.file.Paths/get
                shared.clj:  179  clojure-lsp.shared/uri-obj->filepath
                shared.clj:  177  clojure-lsp.shared/uri-obj->filepath
                shared.clj:  223  clojure-lsp.shared/uri->filename
                shared.clj:  202  clojure-lsp.shared/uri->filename
                      REPL:  349  clojure-lsp.feature.file-management-test/eval60866

I'm not sure if this is me missing a step on the way where maybe the "Bad escape" would be fixed, tho.

magnars added a commit to magnars/emacsd-reboot that referenced this issue May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to API / CLI bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant