1
1
/** @babel */
2
2
3
- import { Point , Range } from ' atom'
3
+ import { Point , Range } from " atom"
4
4
5
- const juliaScopes = [ ' source.julia' , ' source.embedded.julia' ]
5
+ const juliaScopes = [ " source.julia" , " source.embedded.julia" ]
6
6
const openers = [
7
- 'if' , 'while' , 'for' , 'begin' , 'function' , 'macro' , 'module' , 'baremodule' , 'type' , 'immutable' ,
8
- 'struct' , 'mutable struct' , 'try' , 'let' , 'do' , 'quote' , 'abstract type' , 'primitive type'
7
+ "if" ,
8
+ "while" ,
9
+ "for" ,
10
+ "begin" ,
11
+ "function" ,
12
+ "macro" ,
13
+ "module" ,
14
+ "baremodule" ,
15
+ "type" ,
16
+ "immutable" ,
17
+ "struct" ,
18
+ "mutable struct" ,
19
+ "try" ,
20
+ "let" ,
21
+ "do" ,
22
+ "quote" ,
23
+ "abstract type" ,
24
+ "primitive type"
9
25
]
10
- const reopeners = [ ' else' , ' elseif' , ' catch' , ' finally' ]
26
+ const reopeners = [ " else" , " elseif" , " catch" , " finally" ]
11
27
12
- function isKeywordScope ( scopes ) {
28
+ function isKeywordScope ( scopes ) {
13
29
// Skip 'source.julia'
14
30
return scopes . slice ( 1 ) . some ( scope => {
15
- return scope . indexOf ( ' keyword' ) > - 1
31
+ return scope . indexOf ( " keyword" ) > - 1
16
32
} )
17
33
}
18
34
19
- export function isStringScope ( scopes ) {
35
+ export function isStringScope ( scopes ) {
20
36
let isString = false
21
37
let isInterp = false
22
38
for ( const scope of scopes ) {
23
- if ( scope . indexOf ( ' string' ) > - 1 ) {
39
+ if ( scope . indexOf ( " string" ) > - 1 ) {
24
40
isString = true
25
41
}
26
- if ( scope . indexOf ( ' interpolation' ) > - 1 ) {
42
+ if ( scope . indexOf ( " interpolation" ) > - 1 ) {
27
43
isInterp = true
28
44
}
29
45
}
30
46
return isString && ! isInterp
31
47
}
32
48
33
- function forRange ( editor , range ) {
49
+ function forRange ( editor , range ) {
34
50
// this should happen here and not a top-level so that we aren't relying on
35
51
// Atom to load packages in a specific order:
36
- const juliaGrammar = atom . grammars . grammarForScopeName ( ' source.julia' )
52
+ const juliaGrammar = atom . grammars . grammarForScopeName ( " source.julia" )
37
53
38
54
if ( juliaGrammar === undefined ) return [ ]
39
55
@@ -45,46 +61,46 @@ function forRange (editor, range) {
45
61
lineTokens . forEach ( token => {
46
62
const { value } = token
47
63
if ( ! isStringScope ( token . scopes ) ) {
48
- if ( n_parens > 0 && value === ')' ) {
64
+ if ( n_parens > 0 && value === ")" ) {
49
65
n_parens -= 1
50
- scopes . splice ( scopes . lastIndexOf ( ' paren' ) , 1 )
66
+ scopes . splice ( scopes . lastIndexOf ( " paren" ) , 1 )
51
67
return
52
- } else if ( n_brackets > 0 && value === ']' ) {
68
+ } else if ( n_brackets > 0 && value === "]" ) {
53
69
n_brackets -= 1
54
- scopes . splice ( scopes . lastIndexOf ( ' bracket' ) , 1 )
70
+ scopes . splice ( scopes . lastIndexOf ( " bracket" ) , 1 )
55
71
return
56
- } else if ( value === '(' ) {
72
+ } else if ( value === "(" ) {
57
73
n_parens += 1
58
- scopes . push ( ' paren' )
74
+ scopes . push ( " paren" )
59
75
return
60
- } else if ( value === '[' ) {
76
+ } else if ( value === "[" ) {
61
77
n_brackets += 1
62
- scopes . push ( ' bracket' )
78
+ scopes . push ( " bracket" )
63
79
return
64
80
}
65
81
}
66
- if ( ! ( isKeywordScope ( token . scopes ) ) ) return
82
+ if ( ! isKeywordScope ( token . scopes ) ) return
67
83
if ( ! ( n_parens === 0 && n_brackets === 0 ) ) return
68
84
69
85
const reopen = reopeners . includes ( value )
70
- if ( value === ' end' || reopen ) scopes . pop ( )
86
+ if ( value === " end" || reopen ) scopes . pop ( )
71
87
if ( openers . includes ( value ) || reopen ) scopes . push ( value )
72
88
} )
73
89
} )
74
90
return scopes
75
91
}
76
92
77
- export function forLines ( editor , start , end ) {
93
+ export function forLines ( editor , start , end ) {
78
94
const startPoint = new Point ( start , 0 )
79
95
const endPoint = new Point ( end , Infinity )
80
96
const range = new Range ( startPoint , endPoint )
81
97
return forRange ( editor , range )
82
98
}
83
99
84
- export function isCommentScope ( scopes ) {
100
+ export function isCommentScope ( scopes ) {
85
101
// Skip 'source.julia'
86
102
return scopes . slice ( 1 ) . some ( scope => {
87
- return scope . indexOf ( ' comment' ) > - 1
103
+ return scope . indexOf ( " comment" ) > - 1
88
104
} )
89
105
}
90
106
@@ -93,13 +109,11 @@ export function isCommentScope (scopes) {
93
109
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
94
110
* embedded scopes by default.
95
111
*/
96
- export function isValidScopeToInspect ( editor , bufferPosition ) {
97
- const scopes = editor
98
- . scopeDescriptorForBufferPosition ( bufferPosition )
99
- . getScopesArray ( )
112
+ export function isValidScopeToInspect ( editor , bufferPosition ) {
113
+ const scopes = editor . scopeDescriptorForBufferPosition ( bufferPosition ) . getScopesArray ( )
100
114
return scopes . some ( scope => {
101
115
return juliaScopes . includes ( scope )
102
- } ) ?
103
- ! isCommentScope ( scopes ) && ! isStringScope ( scopes ) :
104
- false
116
+ } )
117
+ ? ! isCommentScope ( scopes ) && ! isStringScope ( scopes )
118
+ : false
105
119
}
0 commit comments