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

Feature request: force notebook to always serialize with an indent. #9491

Closed
rchiodo opened this issue Mar 25, 2022 · 15 comments
Closed

Feature request: force notebook to always serialize with an indent. #9491

rchiodo opened this issue Mar 25, 2022 · 15 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Mar 25, 2022

@rchiodo , Can open and display it correctly.
Just when looking at the RAW file (Using text editors) it is one liner.

I wonder abut 2 things:

  1. How did it happen? Why did VS Code saved it like that?
  2. Is there a way to make it save again with all lines separated?

Originally posted by @RoyiAvital in #4576 (comment)

@RoyiAvital
Copy link

Is there a way to share the file with you in private? If that helps.

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

@RoyiAvital, what other extensions do you have installed?

What steps did you take to repro the problem?

For me I did this:

  1. File | New File ...
  2. Picked 'Jupyter notebook'
  3. Added some code to a cell
  4. Saved the file
  5. Opened with a text editor. I get this;
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(1)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

Tried the same thing with 'Create Jupyter Notebook' command from the command palette. Same results.

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

Does it repro for you with a new notebook?

@RoyiAvital
Copy link

I have many files which are fine and doesn't show this issue.
I only have 2 files where it happened. I only saw it on the GIT when pushing.

I only have the Python extension by MS and Spell Right:

image

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

Can you try editing one of the two files where it doesn't work and then send me the contents of the 'Help | Toggle Developer Tools' console tab?

It looks like this:

image

@RoyiAvital
Copy link

RoyiAvital commented Mar 25, 2022

Wouldn't it be easier if I just send you the files?
If you have an email or something.

Just to make sure I described thinks correctly, there is no error with those files.
On VS Code everything works as expected. They just look as one liner in Notepad++.

@RoyiAvital
Copy link

I have sent you the files. Let me know you got them.

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

Yes. I can repro with your files. Thanks.

@rchiodo rchiodo added bug Issue identified by VS Code Team member as probable bug upstream-vscode Blocked on upstream VS code labels Mar 25, 2022
@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

I believe this is by design. It maintains the indent of the original file. If the original file has no indentation, it won't create a new one.

Was the original file all on one line? If not can you e-mail me the original file?

If I reformat the ipynb file as a json file with VS code (so it has an indentation on each line of 4 spaces), reopen it as an ipynb, then save it again, it maintains the 4 spacing indentation and multiple lines.

@RoyiAvital
Copy link

RoyiAvital commented Mar 25, 2022

It was 1 liner since I used Git and VS Code on it.
Any way to restore the indention as you described?

Maybe add an option to auto do it on save? As this 1 line mode make it Git unfriendly.

By the way, it would be also great to have "Save without Output on HD" mode (Git friendly save mode).

@rchiodo rchiodo removed upstream-vscode Blocked on upstream VS code bug Issue identified by VS Code Team member as probable bug labels Mar 25, 2022
@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

Reopen the file as a text file, right click and 'Format document'.

image

The 1 line mode should not have been caused by us. That's the part I'm trying to verify. Do you have the file in git history to see if at some point it wasn't a single line?

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 25, 2022

By the way, it would be also great to have "Save without Output on HD" mode (Git friendly save mode).

I swear we've had this request already, but I can't seem to find it.

Ah this one would be how we'd do that:
microsoft/vscode#120432

@rchiodo rchiodo changed the title Notebook not serialized with multiple lines Request, force notebook to always serialize with an indent. Mar 25, 2022
@rchiodo rchiodo changed the title Request, force notebook to always serialize with an indent. Feature request: force notebook to always serialize with an indent. Mar 25, 2022
@RoyiAvital
Copy link

RoyiAvital commented Mar 26, 2022

@rchiodo , That's not what I meant.
I meant something like JupyText.

Namely on the HD I can save automatically a file with the output cleared yet, while I'm on the session, VS Code keeps the output visible (So it has a temp paired file for the output).

The motivation is having a GIT friendly file on the working folder while in VS Code temp cache the output is kept for the current session.

Currently what I do is that manually at the end of the session I click on Clear Outputs of All Cells.

@rchiodo
Copy link
Contributor Author

rchiodo commented Mar 28, 2022

I moved the suggestion for not saving output to another issue: #9514

We might add another setting to force VS code to save with multiple lines. That's what we'll leave this issue for.

@greazer greazer added feature-request Request for new features or functionality and removed enhancement labels May 4, 2022
@DonJayamanne DonJayamanne self-assigned this Aug 15, 2022
@DonJayamanne
Copy link
Contributor

This feature request hasn't received any upvotes since it was created.
We prioritize issues based on populariry (interest, guaged by number of upvotes),
Closing for now, if anyone feels this is useful, please upvote & comment on this and i'll be happy to re-open this issue or create a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants