]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify error reported by loading tree-sitter language definition
authorYuan Fu <casouri@gmail.com>
Mon, 17 Oct 2022 21:12:24 +0000 (14:12 -0700)
committerYuan Fu <casouri@gmail.com>
Mon, 17 Oct 2022 21:12:24 +0000 (14:12 -0700)
Before:

Error: Cannot load language definition:
"javascript",
("/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript:
cannot open shared object file: No such file or directory"
"/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript.so:
cannot open shared object file: No such file or directory"
"libtree-sitter-javascript: cannot open shared object file: No such
file or directory" "libtree-sitter-javascript.so: cannot open shared
object file: No such file or directory")

After:

(treesit-load-language-error
not-found
("libtree-sitter-z.so" "libtree-sitter-z.dylib")
"No such file or directory")

* src/treesit.c (treesit_load_language): Add base_candidates, remove
error_list, report base_candidates rather than error_list.

src/treesit.c

index 90a1249ba8d5d9c5f2bed7ea623f36bd87698b80..036411865d36a8d965c022d4c6de64aecd461d55 100644 (file)
@@ -512,6 +512,8 @@ treesit_load_language (Lisp_Object language_symbol,
   /* First push just the filenames to the candidate list, which will
      make dynlib_open look under standard system load paths.  */
   treesit_load_language_push_for_each_suffix (lib_base_name, &path_candidates);
+  /* This is used for reporting errors (i.e., just filenames).  */
+  Lisp_Object base_candidates = path_candidates;
   /* Then push ~/.emacs.d/tree-sitter paths.  */
   Lisp_Object lib_name =
     Fexpand_file_name (concat2 (build_string ("tree-sitter/"), lib_base_name),
@@ -531,7 +533,6 @@ treesit_load_language (Lisp_Object language_symbol,
      fail.  */
   dynlib_handle_ptr handle;
   char const *error;
-  Lisp_Object error_list = Qnil;
   for (Lisp_Object tail = path_candidates;
        !NILP (tail); tail = XCDR (tail))
     {
@@ -541,13 +542,12 @@ treesit_load_language (Lisp_Object language_symbol,
       error = dynlib_error ();
       if (error == NULL)
        break;
-      else
-       error_list = Fcons (build_string (error), error_list);
     }
   if (error != NULL)
     {
       *signal_symbol = Qtreesit_load_language_error;
-      *signal_data = Fcons (Qnot_found, Fnreverse (error_list));
+      *signal_data = list3 (Qnot_found, base_candidates,
+                           build_string ("No such file or directory"));
       return NULL;
     }