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', () => {
76
76
expect ( reverse ) . to . equal ( line ) ;
77
77
} ) ;
78
78
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
+
79
85
it ( 'works with the long form arguments' , ( ) => {
80
86
let line = '%R --input x' ;
81
87
let override = line_magics . override_for ( line ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,18 @@ import {
6
6
rpy2_reverse_pattern ,
7
7
rpy2_reverse_replacement
8
8
} from './rpy2' ;
9
+ import { LINE_MAGIC_PREFIX } from '../ipython/overrides' ;
9
10
10
11
export let overrides : IScopedCodeOverride [ ] = [
11
12
{
12
13
// 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 ) => {
15
17
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 } )` ;
17
21
} ,
18
22
scope : 'line' ,
19
23
reverse : {
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ function empty_or_escaped(x: string) {
36
36
* This will not always work: e.g.:
37
37
* x['a = !ls'] = !ls
38
38
* 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%.
39
42
*/
40
43
export const LINE_MAGIC_PREFIX = '^(\\s*|\\s*\\S+\\s*=\\s*)' ;
41
44
You can’t perform that action at this time.
0 commit comments