jupytercalpoly / jupyterlab-code-snippets

Save, reuse, and share code snippets using JupyterLab Code Snippets!
https://jupyterlab-code-snippets-documentation.readthedocs.io
Other
164 stars 25 forks source link

Saving snippets does not work #247

Open asteppke opened 1 year ago

asteppke commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 https://github.com/jupytercalpoly/jupyterlab-code-snippets/issues/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 commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago

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

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.