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