Comments (2)
The current workaround of replacing line magics with "pass" (for Python) and skipping cell magics works but has a drawback: the imported cell/line magics are not included in the virtual document, thus there are false-positive linter messages like "X is imported but unused".
A more robust workaround would add a function call for the magic, reflecting what IPython would do (after initial parsing to determine the magic to be used) - thus the magic would be used in the code.
Ideally, we would allow the user to define custom regular expressions, for example parsing R-magic:
%%R -i input_variable -o output_variable
some R code
into
# noqa
output_variable = R(input_variable)
while this would not work if executed, this is not the goal here - what we want is that the linter registers the that
- R magic was used (though R magic, in particular, does not require importing but is rather loaded via another magic)
- a new variable (
output_variable
) of unknown type was registered in the namespace - the
input_variable
was used.
An initial set of rules (sensible defaults), per language, could be defined in the settings, allowing the user to disable any or all of them and add their own regular expression based rules.
Notes:
- In an alternative reality, we could ask linters to respect all the fancy features introduced by interactive kernels, but there will always be a gap between the introduction of new magic to a specific kernel and all the possible linters picking up on that:
- for example, LSP for Python depends on over a dozen different specialized linters, many of which may consider the ipython feature requests to be too specific for their scope.
- on the other hand, the LSP for R has much, much slower rate of development, possibly because most of the casual R users, while excelling in statistical programming are not programmers familiar with advanced general programming aspects.
- there are some transpiling solutions (IPython → plain python file), which we could use as a reference, to avoid re-inventing a wheel
Update: actually, using noqa is not needed as we can simply ignore the result of inspection for these lines. For simplicity, the regular expressions should return a single line as otherwise, the mapping between the virtual document and notebook gets more tricky.
from jupyterlab-lsp.
Current implementation demonstrated and explained in examples/Magics_and_rpy2.ipynb.
from jupyterlab-lsp.
Related Issues (20)
- Completion failure on `itemWidthHeuristic` when `item.type` is missing
- Unable to set pyright settings through overrides.json5 HOT 2
- Several inconsistencies found, trying to configure pylsp HOT 16
- Follow the XDG base directory specification for the .virtual_documents folder
- Only one "Code Completion" settings seen when enabling "Continuous hinting" HOT 2
- pycodestyle false positive HOT 2
- Is @krassowski/jupyterlab-lsp still need to be installed? HOT 1
- Acceptance tests are failing on Windows with Python 3.8 (but pass with Python 3.11) HOT 2
- Need to update mitigation of file editors `extensionFactory` issue before release
- IHaskell + HLS support HOT 2
- Consider using the `bin` field from `package.json` for specs derived from `NodeModuleSpec`
- Jupyterlab-lsp Error: Uncaught Exception GET /lsp/ws/pyls (::1) HOT 5
- jupyter_lsp - different location of jupyter-lsp-notebook.json between 2.2.2 and 2.2.3 HOT 3
- Markdown cells generate a lot of errors in browser logs and seem to block other extensions, like jupyterlab-spellchecker HOT 2
- GitHub release artifacts are not separate for jupyter-lsp and jupyterlab-lsp
- Code Jump only in the same notebook HOT 4
- Plugin has no transformers yet. HOT 2
- JSON completion introduces unexpected character HOT 1
- Environment variables set for lsp servers leak into the server/kernel
- Define custom code extractors in settings HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupyterlab-lsp.