File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
packages/jupyterlab-lsp/src/transclusions Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ describe('rpy2 IPython overrides', () => {
7676 expect ( reverse ) . to . equal ( line ) ;
7777 } ) ;
7878
79+ it ( 'does not substitute magic-like constructs' , ( ) => {
80+ let line = 'print("%R -i x")' ;
81+ let override = line_magics . override_for ( line ) ;
82+ expect ( override ) . to . equal ( null ) ;
83+ } ) ;
84+
7985 it ( 'works with the long form arguments' , ( ) => {
8086 let line = '%R --input x' ;
8187 let override = line_magics . override_for ( line ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,18 @@ import {
66 rpy2_reverse_pattern ,
77 rpy2_reverse_replacement
88} from './rpy2' ;
9+ import { LINE_MAGIC_PREFIX } from '../ipython/overrides' ;
910
1011export let overrides : IScopedCodeOverride [ ] = [
1112 {
1213 // support up to 10 arguments
13- pattern : '%R' + rpy2_args_pattern ( RPY2_MAX_ARGS ) + '(.*)(\n)?' ,
14- replacement : ( match , ...args ) => {
14+ pattern :
15+ LINE_MAGIC_PREFIX + '%R' + rpy2_args_pattern ( RPY2_MAX_ARGS ) + '(.*)(\n)?' ,
16+ replacement : ( match , prefix , ...args ) => {
1517 let r = parse_r_args ( args , - 4 ) ;
16- return `${ r . outputs } rpy2.ipython.rmagic.RMagics.R("${ r . content } ", "${ r . others } "${ r . inputs } )` ;
18+ // note: only supports assignment or -o/--output, not both
19+ // TODO assignment like in x = %R 1 should be distinguished from -o
20+ return `${ prefix } ${ r . outputs } rpy2.ipython.rmagic.RMagics.R("${ r . content } ", "${ r . others } "${ r . inputs } )` ;
1721 } ,
1822 scope : 'line' ,
1923 reverse : {
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ function empty_or_escaped(x: string) {
3636 * This will not always work: e.g.:
3737 * x['a = !ls'] = !ls
3838 * is perfectly valid IPython, but regular expressions cannot help here.
39+ *
40+ * Look behind could be used to avoid capturing the group,
41+ * but at the time of writing support is only at 77%.
3942 */
4043export const LINE_MAGIC_PREFIX = '^(\\s*|\\s*\\S+\\s*=\\s*)' ;
4144
You can’t perform that action at this time.
0 commit comments