A JavaScript development environment for Emacs https://indium.readthedocs.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.4KB

  1. ;;; indium-list-scripts.el --- List script and sourcemap mappings -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017-2018 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;; This file provides commands useful for debugging project configuration
  17. ;; issues when breakpoints or sourcemaps do not work.
  18. ;;
  19. ;; - `indium-list-sourcemap-sources': List all sourcemap sources, as resolved to
  20. ;; disk files. This commands helps understanding how Indium maps sourcemaps to
  21. ;; file paths using the `.indium.json' project file.
  22. ;;
  23. ;; - `indium-list-script-sources': List all script parsed by the backend. Their
  24. ;; source file is resolved to a file on disk when possible.
  25. ;;; Code:
  26. (require 'indium-client)
  27. (require 'map)
  28. (require 'tabulated-list)
  29. (defvar indium-list-sources-function nil
  30. "Function used to fetch a list of sources.")
  31. (make-local-variable 'indium-list-sources-function)
  32. ;;;###autoload
  33. (defun indium-list-sourcemap-sources ()
  34. "Display a list of all resolved sourcemap sources."
  35. (interactive)
  36. (let ((buf (get-buffer-create (indium-list-sources-buffer-name))))
  37. (with-current-buffer buf
  38. (setq indium-list-sources-function #'indium-client-get-sourcemap-sources)
  39. (indium-list-sources-mode)
  40. (indium-list-sources--refresh))
  41. (display-buffer buf)))
  42. ;;;###autoload
  43. (defun indium-list-script-sources ()
  44. "Display a list of all resolved script sources."
  45. (interactive)
  46. (let ((buf (get-buffer-create (indium-list-sources-buffer-name))))
  47. (with-current-buffer buf
  48. (setq indium-list-sources-function #'indium-client-get-script-sources)
  49. (indium-list-sources-mode)
  50. (indium-list-sources--refresh))
  51. (display-buffer buf)))
  52. (defun indium-list-sources-buffer-name ()
  53. "Return the name of the buffer used to list sources."
  54. "*Indium sources*")
  55. (define-derived-mode indium-list-sources-mode tabulated-list-mode "Indium list sources"
  56. "Major mode for listing sources."
  57. (setq tabulated-list-format [("sources" 0 t)])
  58. (add-hook 'tabulated-list-revert-hook 'indium-list-sources--refresh nil t)
  59. (tabulated-list-init-header))
  60. (defun indium-list-sources--refresh ()
  61. "Refresh the list of parsed scripts."
  62. (funcall indium-list-sources-function
  63. (lambda (sources)
  64. (with-current-buffer (get-buffer (indium-list-sources-buffer-name))
  65. (setq tabulated-list-entries
  66. (seq-map (lambda (source)
  67. (indium-list-sources--make-entry source))
  68. (seq-filter #'identity sources)))
  69. (tabulated-list-print)))))
  70. (defun indium-list-sources--make-entry (source)
  71. "Return a tabulated list entry for SOURCE."
  72. (list nil
  73. (make-vector 1 (if (file-exists-p source)
  74. (cons source
  75. (list 'action (lambda (&rest _)
  76. (find-file source))))
  77. (propertize source 'font-lock-face 'error)))))
  78. (provide 'indium-list-sources)
  79. ;;; indium-list-sources.el ends here