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

Unexpected newline character in the output #998

Closed
zelark opened this issue Jan 30, 2021 · 7 comments
Closed

Unexpected newline character in the output #998

zelark opened this issue Jan 30, 2021 · 7 comments
Labels

Comments

@zelark
Copy link
Contributor

zelark commented Jan 30, 2021

If a string you want to print is more than 1024 characters, Calva adds the newline character at the end of a chunk.

(->> (repeat 25 (apply str (repeat 50 \.)))
     (clojure.string/join \newline)
     (println))
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
....
..............................................
..................................................
..................................................
..................................................
..................................................
nil

calva/src/evaluate.ts

Lines 67 to 69 in 9185f16

stdout: (m) => {
outputWindow.append(normalizeNewLines(m));
},

Any idea how it can be fixed?

UPD. Tеsted it in Clover and lein repl, works as expected.

@bpringe
Copy link
Member

bpringe commented Jan 30, 2021

So expected behavior is to have no newline printed at any point, right? I have no idea off-hand without looking into it why it would print a newline. @PEZ Is this intentional for any reason? If not, a PR would be welcome if you want to look into it @zelark.

@PEZ
Copy link
Collaborator

PEZ commented Jan 30, 2021

I have tried to fix this before. Not really figured it out. Something with nrepl buffer size...

@bpringe bpringe added bug Something isn't working pr-welcome labels Jan 30, 2021
@zelark
Copy link
Contributor Author

zelark commented Jan 31, 2021

I also tried to fix it on Calva side but failed. Probably we need to look how it is arranged in other nrepl clients.

Maybe @bbatsov can suggest something.

@bbatsov
Copy link
Contributor

bbatsov commented Jan 31, 2021

I'm assuming that Calva is printing a new line on each chunk of the output or something like this. Generally it's a good idea to have check whether a chunk is just a chunk or the final chunk. Generally if a chunk is smaller than the max chunk size it's fairly certain that this is the final chunk.

@PEZ
Copy link
Collaborator

PEZ commented Jan 31, 2021

Thanks, @bbatsov . That's probably it.

I previously tried to tackle this by changing the chunk size, but failed at getting it to be anything else but 1024. But of course, that is not the right way to go about it anyway.

@bbatsov
Copy link
Contributor

bbatsov commented Jan 31, 2021

There's one more implication of streaming - how to syntax highlight results, while they are being streamed (you can't just apply font-locking to each chunk individually, as those are going to be partial Clojure forms). I'm guessing VS code is more flexible here and can re-highlight everything from the begining on each chunk delivered or something like this, but with Emacs it's very tricky and I've cheated a bit - I syntax-highlight in CIDER's REPL only single-chunk results and apply no syntax highligting otherwise.

@PEZ
Copy link
Collaborator

PEZ commented Jan 31, 2021

There are two parsers in play in Calva. But both will generally just render broken syntax highlighting while the structure is broken, and it will fix itself when the structure is ok again. 😄 None of them is particularly fond of long lines, so they will throw in the towel when a line exceeds 20K characters (configurable by the user).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants