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

Not working for JupyterLab 4.0? #4

Open
hugetim opened this issue Aug 28, 2023 · 14 comments
Open

Not working for JupyterLab 4.0? #4

hugetim opened this issue Aug 28, 2023 · 14 comments

Comments

@hugetim
Copy link
Owner

hugetim commented Aug 28, 2023

It's not working for me with a new install of JupyterLab 4.0.5.

@ideabucket
Copy link

You may have already found this, but this discussion thread appears to identify why it stopped working—breaking API changes in the new version of CodeMirror that shipped with JL 4. :(

@hugetim
Copy link
Owner Author

hugetim commented Nov 19, 2023

Right, it should be possible to make it work, but it didn't look like a quick fix when I initially looked into it. So I've just been using JupyterLab 3.x myself, for the time being.

Here are my notes from back then, which I should have posted here:

@ticoneva
Copy link

ticoneva commented Jan 17, 2024

I got a hack working. It should be possible to implement the changes into an extension, but this hack provides me with something that is working in the meantime:

  1. stata.js requires changes based on examples from @codemirror/legacy-modes, in particular those that run on simple mode, e.g. Factor. The modified script I use is available here. The file then needs to be put in $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/.
  2. Modify $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/src/language.js and add a new stata mode. Where to put the snippet should be obvious once you open the file:
    {
      name: 'stata',
      displayName: trans.__('Stata'),
      mime: 'text/x-stata',
      extensions: ['do','ado'],
      async load() {
        const m = await import('@codemirror/legacy-modes/mode/stata');
        return legacy(m.stata);
      }
      },
    
  3. Run jupyter lab build

@hugetim
Copy link
Owner Author

hugetim commented Jan 29, 2024

Thank you for your work on this! I probably won't be able to dig into it myself, to try it out, for several months, but I really appreciate it.

@arnonerba
Copy link

The workaround suggested by @ticoneva doesn't seem to work for me. I may be misreading the instructions, but I made the following changes on my server:

  1. I installed the new syntax highlighting extension with /opt/tljh/user/bin/pip install jupyterlab_stata_highlight2.
  2. I downloaded stata.js to /opt/tljh/user/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/stata.js.
  3. I merged the suggested changes from language.ts into /opt/tljh/user/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/src/language.ts.

I'm pinging @ozak as well since they opened a similar issue.

@ozak
Copy link

ozak commented Apr 12, 2024

I also tried it but it didn't work.

@ticoneva
Copy link

ticoneva commented Apr 12, 2024

I posted the wrong locations in my original instructions. Thanks @arnonerba for pointing that out. I have modified the instructions accordingly.

I would also like to point out that the modification might require---or at least would be a lot easier to apply to---non-minified CodeMirror files, which does not seem to come with some versions of Jupyter Lab. Finally, after the modifications you might need to rebuild Jupyter Lab for this to work:

jupyter lab build

@arnonerba
Copy link

@ticoneva thanks for responding and for updating your original instructions. I've tried jupyter lab build in my environment, but syntax highlighting still doesn't seem to work. Do you have any other suggestions?

@ticoneva
Copy link

What OS are you using?

It has been a while since I implemented the hack and honestly, I messed around with a lot things, so I cannot confirm with 100% certainty that these steps are all that it takes. I will start fresh on a VM and see if I can provide better instructions.

@arnonerba
Copy link

I'm running TLJH on Ubuntu Server 22.04 LTS with Stata 18.

Thank you for your help!

@ozak
Copy link

ozak commented Apr 12, 2024

I'm on MacOS 14.3.
Thanks for looking into this!

@ticoneva
Copy link

ticoneva commented Aug 13, 2024

I have verified that the following steps should work:

  1. Create and activate conda environment.
    conda create -n jupyterlab4 pip nodejs -c conda-forge
    conda activate jupyterlab4
  2. Install Jupyter Lab 4.
    conda install jupyterlab -c conda-forge
    or
    pip install jupyterlab
  3. Set up the staging files. Make sure you are the owner of the environment, otherwise this will fail.
    jupyter lab build --dev-build
  4. Download Stata syntax highlighting Javascript file.
    wget https://raw.githubusercontent.com/ticoneva/codemirror-legacy-stata/main/stata.js -P $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/
  5. Modify $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/lib/language.js. Search for Squirrel and add the following entry after that one:
           {
                name: 'stata',
                displayName: trans.__('Stata'),
                mime: 'text/x-stata',
                extensions: ['do','ado'],
                async load() {
                    const m = await import('@codemirror/legacy-modes/mode/stata');
                    return legacy(m.stata);
                }
            },
  1. Run jupyter lab build again.

@lutherbu
Copy link

lutherbu commented Dec 6, 2024

Just a wrapper package for solution offered by @ticoneva

pip install jupyterlab_stata_highlight3

Apparently, Stata syntax can be well handled using legacy mode. Migrating to codemirror6 using lezer seems too complicated: see https://lezer.codemirror.net/

@ticoneva
Copy link

ticoneva commented Dec 7, 2024

@lutherbu Thanks for putting together the package! That would make things so much easier for everyone.

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

6 participants