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

cider-load-buffer fails to parse namespaced keywords on a narrowed buffer #2676

Closed
glittershark opened this issue Jul 17, 2019 · 3 comments
Closed
Labels
bug good first issue A simple tasks suitable for first-time contributors

Comments

@glittershark
Copy link
Contributor

glittershark commented Jul 17, 2019

Expected behavior

  1. M-x narrow-to-defun (or similar narrowing command)
  2. M-x cider-load-buffer

Loads the code from the (non-narrowed) buffer

Actual behavior

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling /path/to/my-clojure-file.clj at (8:0)
   #:clojure.error{:phase :read-source,
                   :line 8,
                   :column 0,
                   :source
                   "/path/to/my-clojure-file.clj"}
             Compiler.java: 7642  clojure.lang.Compiler/load
                      REPL:    1  com.gfredericks.test.chuck.generators/eval3043503
                      REPL:    1  com.gfredericks.test.chuck.generators/eval3043503
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  748  java.lang.Thread/run

1. Caused by java.lang.RuntimeException
   Invalid token: ::some-namespaced/keyword-in-the-buffer

Steps to reproduce the problem

My buffer has aliased namespaces and namespaced keywords using those aliases, eg:

(ns my-clojure-file
  (:require [some-other.namespace :as [some-namespaced]]))

(defn foo []
  ::some-namespaced/keyword-in-the-buffer)

Environment & Version information

CIDER version information

;; CIDER 0.22.0snapshot (package: 20190711.1657), nREPL 0.6.0
;; Clojure 1.10.0, Java 1.8.0_222

Emacs version

GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.3) of 2019-02-12

Operating system

Arch Linux 5.2.0-arch2-1-ARCH

@glittershark
Copy link
Contributor Author

M-x cider-eval-defun-at-point (and other non-entire-buffer eval commands) work fine

@bbatsov bbatsov added bug good first issue A simple tasks suitable for first-time contributors labels Jul 17, 2019
@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2019

I'm 90% certain that the problem is here:

(defun cider--file-string (file)
  "Read the contents of a FILE and return as a string."
  (with-current-buffer (find-file-noselect file)
    (substring-no-properties (buffer-string))))

That function is called internally by cider-load-buffer.
Likely buffer-string is affected by the narrowing and we'll have to wrap this call in a widen to avoid this problem.

glittershark added a commit to glittershark/cider that referenced this issue Jul 18, 2019
Wrap the (buffer-string) in cider--file-string in
a (save-restriction (widen)), so that if the current buffer is narrowed
by the user we still get the entire string during calls
to (cider-load-buffer)
@glittershark
Copy link
Contributor Author

Yep, that did it

glittershark added a commit to glittershark/cider that referenced this issue Jul 27, 2019
Wrap the (buffer-string) in cider--file-string in
a (save-restriction (widen)), so that if the current buffer is narrowed
by the user we still get the entire string during calls
to (cider-load-buffer)
@bbatsov bbatsov closed this as completed in 6a97422 Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue A simple tasks suitable for first-time contributors
Projects
None yet
Development

No branches or pull requests

2 participants