Skip to content

Commit 785e00b

Browse files
committed
Filter-out legacy filenames that are not UTF-8 encodable.
Emacs's json serialization only supports UTF-8. Since sonarlint requires emacs to provide the whole list of files in the workspace, this can be an issue when filenames use ISO 8859 accentuated characters typically. The simplest work around seems to filter-out those files, but I guess sonarlint won't work on those.
1 parent 20d4b47 commit 785e00b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lsp-sonarlint.el

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,30 @@ temporary buffer."
286286
i.e folders starting with '.' will be ignored"
287287
(not (string= (substring (file-name-base dirname) 0 1) ".")))
288288

289+
(defun lsp-sonarlint--invalid-file-name-encoding(file-path)
290+
"Return t if the file-path is not encodable as UTF-8.
291+
This is important since emacs does not support non UTF-8 json serialization,
292+
so a stray accentuated character encoded in a legacy filename in 8859-1
293+
will raise an error for the whole project."
294+
(cl-some (lambda (ch)
295+
(not (encode-coding-char ch 'utf-8 'unicode)))
296+
file-path))
297+
289298
(defun lsp-sonarlint--list-files-in-folder (workspace _params)
290299
"Respond to a listFilesInFolder request.
291300
List all files of interest in WORKSPACE's directory.
292301
See `lsp-sonarlint-analyze-folder' to see which files are ignored."
293302
(let* ((root-dir (lsp--workspace-root workspace))
294-
(files (directory-files-recursively root-dir ".*" nil 'lsp-sonarlint--analyze-folder)))
303+
(files (directory-files-recursively root-dir ".*" nil 'lsp-sonarlint--analyze-folder))
304+
(utf8-filenames (cl-remove-if #'lsp-sonarlint--invalid-file-name-encoding files)))
295305
(lsp-ht
296306
("foundFiles"
297-
(apply 'vector
298-
(mapcar (lambda(file)
299-
(lsp-ht
300-
("fileName" (file-name-nondirectory file))
301-
("filePath" file)))
302-
files))))))
307+
(apply 'vector
308+
(mapcar (lambda(file)
309+
(lsp-ht
310+
("fileName" (file-name-nondirectory file))
311+
("filePath" file)))
312+
utf8-filenames))))))
303313

304314
(defvar lsp-sonarlint--action-handlers '())
305315

0 commit comments

Comments
 (0)