Browse Source

Fix #24 Use local files in the REPL when possible

workspaces
Nicolas Petton 4 years ago
parent
commit
663291b248
Signed by: nico GPG Key ID: 233587A47C207910
3 changed files with 26 additions and 8 deletions
  1. +11
    -8
      jade-repl.el
  2. +4
    -0
      jade-workspace.el
  3. +11
    -0
      test/jade-workspace-test.el

+ 11
- 8
jade-repl.el View File

@ -245,14 +245,17 @@ optional."
(defun jade-repl--emit-message-url-line (url line)
"Emit the URL and LINE for a message."
(unless (seq-empty-p url)
(insert "\nFrom "
(propertize (if line
(format "%s:%s" url line)
url)
'font-lock-face 'jade-link-face
'jade-action (lambda ()
(browse-url url))
'rear-nonsticky '(font-lock-face jade-action)))))
(let ((path (jade-workspace-lookup-file-safe url)))
(insert "\nFrom "
(propertize (if line
(format "%s:%s" path line)
path)
'font-lock-face 'jade-link-face
'jade-action (lambda ()
(if (file-regular-p path)
(find-file path)
(browse-url path)))
'rear-nonsticky '(font-lock-face jade-action))))))
(defun jade-repl-next-input ()
"Insert the content of the next input in the history."


+ 4
- 0
jade-workspace.el View File

@ -57,6 +57,10 @@ If no file is found, return nil."
(or (jade-workspace--lookup-using-file-protocol url)
(jade-workspace--lookup-using-workspace url)))
(defun jade-workspace-lookup-file-safe (url)
"Find a local file for URL, or return URL is no file can be found."
(or (jade-workspace-lookup-file url) url))
(defun jade-workspace--lookup-using-file-protocol (url)
"Return a local file matching URL if URL uses the file:// protocol."
(when (jade-workspace--file-protocol-p)


+ 11
- 0
test/jade-workspace-test.el View File

@ -49,6 +49,17 @@
(assess-with-filesystem jade-workspace--test-fs
(should (null (jade-workspace-lookup-file "http://localhost:9229/non-existant-file-name.js")))))
(ert-deftest jade-workspace-lookup-file-safe-fallback-test ()
(assess-with-filesystem jade-workspace--test-fs
(let ((url "http://localhost:9229/non-existant-file-name.js"))
(should (equal url (jade-workspace-lookup-file-safe url))))))
(ert-deftest jade-workspace-lookup-file-safe-test ()
(assess-with-filesystem jade-workspace--test-fs
(let ((url "http://localhost:9229/js/app.js")
(file (expand-file-name "js/app.js")))
(should (equal file (jade-workspace-lookup-file-safe url))))))
(ert-deftest jade-workspace-make-url-with-no-workspace-test ()
(let ((jade-connection '((url . "http://localhost:9229"))))
(should (null (jade-workspace-make-url "js/app.js")))))


Loading…
Cancel
Save