avli / clojureVSCode

Clojure support for Visual Studio Code
https://avli.github.io/clojureVSCode/
MIT License
204 stars 34 forks source link

Random "////////"///// when editing script #150

Closed ghost closed 4 years ago

ghost commented 4 years ago

I am new to CLojure and have installed this VSCode extension. If I create a .clj file and open it in VSCode the REPL connects fine but when I start typing I get lots of "////"////////// added to my text.

e.g. If I type

(defn manhatten-distance)

this is transformed into

\\"\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"(defn manhatten-distance)\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\"\\\\\\\\"\\\\"\\"\""

without my doing anything.

avli commented 4 years ago

Hello @SteveLaycock,

Could you please provide more details? Is it just a single file or a project created with Leiningen or Boot? If it's a project what dependencies does it have? Does the issue reproduce if you disable all Visual Studio Code plugins but clojureVSCode?

Thanks in advance!

ghost commented 4 years ago

This was in a newly created workspace containing two empty files Opening either of the files and adding text gave the same issue.

I have the following extensions installed in VSCode.

VSCodeExtensions

THis is the workspace

image

avli commented 4 years ago

It seems like you're using Clojure Code which is another extension. It's better to create an issue in their repository or just give clojureVSCode a try :-)

ghost commented 4 years ago

Sorry No. I forgot I'd uninstalled your extension and was trying an alternative.

avli commented 4 years ago

OK, no probs. Unfortunately, I can't reproduce the issue locally. Do these slash characters appear immediately as you type or when you save the document?

Could you try to create a project with Leiningen:

$ lein new my-project

add

{:user {:plugins  [[cider/cider-nrepl "0.22.1"]]
       :dependencies [[cljfmt "0.5.7"]]}}

to project.clj and try to edit a file inside the project? Does the issue reproduce?

ghost commented 4 years ago

I executed lein new testproj

I opened project.clj with notepad++

((defproject testproj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :repl-options {:init-ns testproj.core}))

I added the requested text to get

(defproject testproj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :repl-options {:init-ns testproj.core})

{:user {:plugins  [[cider/cider-nrepl "0.22.1"]]
       :dependencies [[cljfmt "0.5.7"]]}}

and saved the file

I then loaded vscode and opened the folder testproj and in the src directory the the file core.clj

the code present was

(ns testproj.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

The output in the Output window was

java.lang.Exception: Error loading c:\Users\slayc\source\repos\Clojure\testproj\project.clj
 at leiningen.core.project$read_raw$fn__7295.invoke (project.clj:1046)
    leiningen.core.project$read_raw.invokeStatic (project.clj:1040)
    leiningen.core.project$read_raw.invoke (project.clj:1036)
    leiningen.core.project$read.invokeStatic (project.clj:1057)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.project$read.invokeStatic (project.clj:1058)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.main$_main$fn__6681.invoke (main.clj:447)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:491)
    clojure.main$main_opt.invoke (main.clj:487)
    clojure.main$main.invokeStatic (main.clj:598)
    clojure.main$main.doInvoke (main.clj:561)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:37)
Caused by: clojure.lang.Compiler$CompilerException: Syntax error compiling at (c:\Users\slayc\source\repos\Clojure\testproj\project.clj:0:0).
#:clojure.error{:phase :compile-syntax-check, :line 0, :column 0, :source "c:\\Users\\slayc\\source\\repos\\Clojure\\testproj\\project.clj"}
 at clojure.lang.Compiler.analyze (Compiler.java:6808)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3260)
    clojure.lang.Compiler.analyze (Compiler.java:6791)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3260)
    clojure.lang.Compiler.analyze (Compiler.java:6791)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$MapExpr.parse (Compiler.java:3104)
    clojure.lang.Compiler.analyze (Compiler.java:6797)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$MapExpr.parse (Compiler.java:3104)
    clojure.lang.Compiler.analyze (Compiler.java:6797)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:6120)
    clojure.lang.Compiler$FnMethod.parse (Compiler.java:5467)
    clojure.lang.Compiler$FnExpr.parse (Compiler.java:4029)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7104)
    clojure.lang.Compiler.analyze (Compiler.java:6789)
    clojure.lang.Compiler.eval (Compiler.java:7173)
    clojure.lang.Compiler.load (Compiler.java:7635)
    clojure.lang.Compiler.loadFile (Compiler.java:7573)
    clojure.lang.RT$3.invoke (RT.java:327)
    leiningen.core.project$read_raw$fn__7295.invoke (project.clj:1044)
    leiningen.core.project$read_raw.invokeStatic (project.clj:1040)
    leiningen.core.project$read_raw.invoke (project.clj:1036)
    leiningen.core.project$read.invokeStatic (project.clj:1057)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.project$read.invokeStatic (project.clj:1058)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.main$_main$fn__6681.invoke (main.clj:447)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:491)
    clojure.main$main_opt.invoke (main.clj:487)
    clojure.main$main.invokeStatic (main.clj:598)
    clojure.main$main.doInvoke (main.clj:561)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:37)
Caused by: java.lang.RuntimeException: No such namespace: cider
 at clojure.lang.Util.runtimeException (Util.java:221)
    clojure.lang.Compiler.resolveIn (Compiler.java:7383)
    clojure.lang.Compiler.resolve (Compiler.java:7357)
    clojure.lang.Compiler.analyzeSymbol (Compiler.java:7318)
    clojure.lang.Compiler.analyze (Compiler.java:6768)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3260)
    clojure.lang.Compiler.analyze (Compiler.java:6791)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3260)
    clojure.lang.Compiler.analyze (Compiler.java:6791)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$MapExpr.parse (Compiler.java:3104)
    clojure.lang.Compiler.analyze (Compiler.java:6797)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$MapExpr.parse (Compiler.java:3104)
    clojure.lang.Compiler.analyze (Compiler.java:6797)
    clojure.lang.Compiler.analyze (Compiler.java:6745)
    clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:6120)
    clojure.lang.Compiler$FnMethod.parse (Compiler.java:5467)
    clojure.lang.Compiler$FnExpr.parse (Compiler.java:4029)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7104)
    clojure.lang.Compiler.analyze (Compiler.java:6789)
    clojure.lang.Compiler.eval (Compiler.java:7173)
    clojure.lang.Compiler.load (Compiler.java:7635)
    clojure.lang.Compiler.loadFile (Compiler.java:7573)
    clojure.lang.RT$3.invoke (RT.java:327)
    leiningen.core.project$read_raw$fn__7295.invoke (project.clj:1044)
    leiningen.core.project$read_raw.invokeStatic (project.clj:1040)
    leiningen.core.project$read_raw.invoke (project.clj:1036)
    leiningen.core.project$read.invokeStatic (project.clj:1057)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.project$read.invokeStatic (project.clj:1058)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.main$_main$fn__6681.invoke (main.clj:447)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:491)
    clojure.main$main_opt.invoke (main.clj:487)
    clojure.main$main.invokeStatic (main.clj:598)
    clojure.main$main.doInvoke (main.clj:561)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:37)
nREPL exited with code 1

I then edited core.clj

(ns testproj.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

(println "Hellow World")

I received a notification 'Formatting functions don't work, connect to nREPL first.

I should note that I'm not a professional programmer. I normally dabble in VBA to massage Word documents that I work on. Last year I used VBA to solve the 2019 Advent of Code problems. For entertainment I'm translating my VBA code to other languages to broaden my horizons. Thus far I have been successful using C#, Rust, Nim, and Typescript.

irfanka commented 4 years ago

Hi.

I have the same issue.

My workspace contains only a single .clj file, and this is the entire content of that file: image

If I try to auto-format the document, cljfmt turns it into a weird string, like this:

image

I have disabled all of my VS Code extensions, except for this one. nREPL connects successfully, if that makes any difference.

irfanka commented 4 years ago

Forgot to mention that additional backslashes are sometimes added if cljfmt runs multiple times - probably to escape the double-quote signs added during first run (\")...

irfanka commented 4 years ago

I also tried with a lein-generated project, adding the cljfmt as a plugin to project.clj. I got the same result/exception as @SteveLaycock - but I did go a step further and started lein repl manually, and then connected to the running nREPL from vs code.

Formatting the document no longer converts code to a string - but it dosn't format the document either. Basically, nothing happens when I try to cljfmt through this extension now.

irfanka commented 4 years ago

Alright, sorry for spamming - but I managed to fix the issue by (properly) adding both cider-nrepl as well as lein-cljfmt plugins to my project.clj:

(defproject infosys "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :repl-options {:init-ns infosys.core}
  :plugins [[cider/cider-nrepl "0.22.1"] [lein-cljfmt "0.6.7"]])

After that, i just ran lein install and the Clojure extension is now able to properly start it's own nREPL server - and code formatting now works as expected.

ghost commented 4 years ago

This works for me too

:plugins [[cider/cider-nrepl "0.22.1"] [lein-cljfmt "0.6.7"]])

irfanka commented 4 years ago

Wonder why it didn't work with the default cljfmt (i.e. the one bundled with the vs code extension)...

This works only as long as lein is used. Good luck if you prefer boot :)

lffg commented 4 years ago

I am having this same problem. When I save this single file:

(def my-sum (+ 5 10))

(println "The sum is:" my-sum)

The extension changes the file contents to:

"\"(def my-sum (+ 5 10))\\n\\n(println \\\"The sum is:\\\" my-sum)\\n\"\n"
See some images ![image](https://user-images.githubusercontent.com/23662020/78817616-ccc33300-79a9-11ea-99e7-71eaa6fbded0.png) ![image](https://user-images.githubusercontent.com/23662020/78817657-da78b880-79a9-11ea-9784-bec28511ffac.png)

I've solved it by following this steps by @irfanka.

But I think that this issue should be adressed by the extension by default. Maybe these plugins should be installed automatically when the extension is downloaded, @avli?

avli commented 4 years ago

@lffg actually, these plugins are installed when the extension starts. The issue, I believe, is the version of cljfmt. Unfortunately, I cannot say for sure since I wasn't able to reproduce the bug.

Anyway, the internal version of the formatter has been updated. Also, a setting for the explicit definition of cljfmt has been added (see here). The changes will be available in the next minor release. After the release, I'm going to close this issue. Should anyone face with it, don't hesitate to leave a comment.

UPD: the new version has been released. Closing this one for now.