hugetim / jupyterlab_stata_highlight2

JupyterLab extension for Stata syntax highlighting similar to the Stata IDE's
MIT License
3 stars 3 forks source link

Not working for JupyterLab 4.0? #4

Open hugetim opened 1 year ago

hugetim commented 1 year ago

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

ideabucket commented 10 months ago

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

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

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);
      }
      },
    1. Run jupyter lab build
hugetim commented 7 months ago

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

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

I also tried it but it didn't work.

ticoneva commented 5 months ago

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

@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 commented 5 months ago

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

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

Thank you for your help!

ozak commented 5 months ago

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

ticoneva commented 1 month ago

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);
                }
            },
  6. Run jupyter lab build again.