question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formalize and extend language transclusion

See original GitHub issue

Elevator Pitch

Allow a user to define rules for finding parts of files in a host language that embed other languages. Additionally support referring to the outer language within the inner language. Language servers, libraries, and other things a user might have installed should be easily and robustly able to ship and activate these on installation.

Motivation

Much like with #190 for #189, there are more languages that embed other languages than we’ll be able to (or want to) define/maintain. The existing list includes things from IPython built-ins, but doesn’t fully capture the scope of other magics, much less what other languages do, especially extremely crazy things like allthekernels, sos or metakernel.

A number of these kinds of things also allow for referring to the outer language, such as {variable} references, up to full-blown templating languages, and having access to completion/diagostics/reference/hover for these nested scopes would be very valuable.

Design Ideas

Add a separate spec to the JSON schema, e.g. transclusions which can be defined/modified without re-compiling lab by traitlets config or entry_points. Move the existing “simple” ones from the hard-coded typescript into defaults on the python side, or simple JSON.

Notional “Simple” Example

LanguageServerManager:
  language_servers: ...
  transclusions:
    ipython-shell-magics:
      host:
        mime_types: 
          - text/x-python
        languages: 
          - python
        file_extensions:
          - .ipy
          - .ipynb
      guest:
        mime_types:
          - application/x-sh
        languages: 
          - sh
        file_extensions:
          - .sh
      patterns:
        line-magic:
          regex: "(?<=\\s)!(.*)$"
          extract: $1
          isolate: true
          host_inclusions:
            variable:
              pattern: "(?<!\\$)\\{([^\\}]+)\\}"
              extract: $1
        cell-magic:
          regex: "^%%bash[^\n]*\n([\n.]+)$"
          extract: $1
          isolate: true
          host_inclusions:
            variable:
              pattern: "(?<!\\$)\\{([^\\}]+)\\}"
              extract: $1

TODO: the ! magic can also be assigned to variables, etc.

x = !ls
# is secretly
x: str = some_function("""ls""")

while

%%bash --bg --proc foo --out foo_out
ls
# is actually
foo: Popen = some_function("""ls""")
foo_out = foo.stdout

More complex things

These would be insufficient for complicated tricks like what’s happening in the some of the r-in-python with declaring variables, and for this case being able to register these from an extension that depends on the to-be ILanguageServerManager (or a dedidcated ITransclusionManager) would be required.

User-serviceable and discoverable

Probably need to be configurable in the frontend, e.g.

  • adding/testing new transclusions
  • disabling installed ones
  • some kind of visual indication of them (gutter?)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bloiscommented, Jun 9, 2020

IPython includes some other magics as well, see https://ipython.readthedocs.io/en/stable/interactive/reference.html#automatic-parentheses-and-quotes

I do think it could be useful to expose an API on the kernel where you can ask for some code to be transformed into the underlying language then receive back the transformed code and a source map of the transformations. This is an established pattern for code transformations that can also be used for lint/format as well as highlighting appropriate locations of code errors from the runtime reported location.

This could even be done extensibly, so nested syntaxes could report their transformations- an embedded SQL query could use it to map SQL errors back to the original source code locations.

0reactions
bollwyvlcommented, Dec 1, 2021

Yeah, it’s a rather opinionated project. I don’t mean one should use that repo directly but rather the pattern for publishing it. You might get more leverage from https://github.com/jupyterlab/extension-cookiecutter-ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Architecture — Jupyter[Lab] Language Server documentation
Formalize and extend language transclusion #191¶ ... Built with Sphinx using a theme provided by Read the Docs. Read the Docs v: v3.5.0....
Read more >
T47096 Add a way to transclude template or other page in the ...
I think it would be helpful if it was possible to transclude Special:MyLanguage. For example, if a template is translated, the correct language...
Read more >
There and Here: Patterns of Content Transclusion in Wikipedia
Use is localised to subject areas, which differ between sampled languages. A limited number of patterns were observed including: Lists from transclusion, ...
Read more >
Extended Version of Elucidative Development for Model ...
to language specifications like the UML specification and help to avoid ... geneous kinds of software artefacts, e.g., formalised requirements ...
Read more >
20118057 Master's Thesis Advisors - Philip Tchernavskij
expand the notion of transclusion from hypertext documents to inter- ... computer-supported practice as strictly formalized and factory-like ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found