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

Saving snippets does not work #247

Open
asteppke opened this issue Feb 15, 2023 · 6 comments
Open

Saving snippets does not work #247

asteppke opened this issue Feb 15, 2023 · 6 comments

Comments

@asteppke
Copy link

When running jupyterlab-code-snippets (version 2.1.0 from conda-forge) it looks like it is running fine, I get the side tab and can insert snippets into notebooks. When using the right-click "Save As Code Snippet" function though nothing happens. I do not see a popup window, an error message or any other indication.

Is there anything I can do to diagnose this better?

My JupyterLab setup looks as follows (running on Windows with Chrome browser):

(jupyter) PS C:\Users\Alexander> jupyter labextension list
Config option `kernel_spec_manager_class` not recognized by `ListLabExtensionsApp`.
[W 2023-02-15 17:51:17.510 LabApp] Config option `kernel_spec_manager_class` not recognized by `LabApp`.
JupyterLab v3.6.1
C:\Users\Alexander\AppData\Local\conda\conda\envs\jupyter\share\jupyter\labextensions
        jupyter-matplotlib v0.11.2 enabled ok
        jupyterlab-code-snippets v2.1.0 enabled ok (python, code_snippet)
        jupyterlab-jupytext v1.3.8+dev enabled ok (python, jupytext)
        jupyterlab_pygments v0.2.2 enabled ok (python, jupyterlab_pygments)
        @jupyter-widgets/jupyterlab-manager v5.0.5 enabled ok (python, jupyterlab_widgets)
        @ryantam626/jupyterlab_code_formatter v1.5.3 enabled ok (python, jupyterlab-code-formatter)
@meli-lewis
Copy link

meli-lewis commented Feb 17, 2023

Hi @asteppke, if I understand correctly, I had the same problem a few weeks ago and was able to fix it thanks to this answer in #237. Once an initial snippet with an ID of 1 exists, you should be able to use the standard interface as usual.

@asteppke
Copy link
Author

@meli-lewis: Thank you for the hint. I checked and there were three snippets with ID 0, 1, and 2 already defined. Removing them did not solve the issue either.

Upon checking the developer console I find this error message:

image

A jupyter lab clean, jupyter lab build unfortunately does not help either. Saving snippets still does not work, only recalling already existing ones from the sidebar.

@asteppke
Copy link
Author

So, I got to the bottom of this thanks to @meli-lewis hint. In the slightly older version (2.1.0 from conda-forge) the saving issue as above appears.

In the current version (2.2.1 from pip) the extension does not work here because of #237, which does not seem to be fixed in 2.2.1. The workaround indicated there to add an empty snippet to the user preferences works though and saving is also working.

@Laavaka
Copy link

Laavaka commented Mar 10, 2023

I have the same problem! Right click to save as code snippets doesn't work, no matter how i try. Also, click plus botton on panel, then clicking the 'Creat&Close’ button doesn't work either.It just can't creat a new snippet. That is weird. I found this extension very useful, but seems like it still have lots of bugs unsolved :(

@xiaoneimeng
Copy link

I also had the same problem, my installation process went well, and the plugin icon appeared, but it just couldn't be saved

@meli-lewis
Copy link

I have the same problem! Right click to save as code snippets doesn't work, no matter how i try. Also, click plus botton on panel, then clicking the 'Creat&Close’ button doesn't work either.It just can't creat a new snippet. That is weird. I found this extension very useful, but seems like it still have lots of bugs unsolved :(

Did you try adding an initial snippet through the JSON settings editor, as suggested by this answer? At the risk of explaining something you already know, you can do that either by

  • going to Settings -> Settings Editor -> Code Snippet Manager -> JSON Settings Editor (in the upper right corner of the window)

  • Editing the JupyterLab Code Snippet settings file directly in whatever text editor you prefer; if I understand correctly, it's likely located at ~/.jupyter/lab/user-settings/jupyterlab-code-snippets/snippets.jupyterlab-settings if your OS is Unix-based.

So, to start, the settings will probably look like this:

{
    // Code Snippet Manager
    // jupyterlab-code-snippets:snippets
    // Code Snippet Manager Settings
    // *********************************

    // Font Size of Preview
    // Change the font size of preview to see its content
    "snippetPreviewFontSize": 3,

    // List of code snippets
    // A snippet is defined by a 'id', 'name', and 'language'
    "snippets": []
}

Try replacing "snippets": [] with the following:

    "snippets": [
        {
            "tags": [],
            "name": "empty_snippet",
            "description": "https://github.com/jupytercalpoly/jupyterlab-code-snippets/issues/247",
            "language": "Python",
            "code": "",
            "id": 1
        },
    ]

Then, try adding a snippet as you'd expect to, e.g. through right-clicking.

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

No branches or pull requests

4 participants