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
5
'if' , 'while' , 'for' , 'begin' , 'function' , 'macro' , 'module' , 'baremodule' , 'type' , 'immutable' ,
8
6
'struct' , 'mutable struct' , 'try' , 'let' , 'do' , 'quote' , 'abstract type' , 'primitive type'
9
7
]
10
- const reopeners = [ 'else' , 'elseif' , 'catch' , 'finally' ]
8
+ const reopeners = [ 'else' , 'elseif' , 'catch' , 'finally' ]
11
9
12
- function isKeywordScope ( scopes ) {
10
+ /**
11
+ *
12
+ * @param {readonly string[] } scopes
13
+ */
14
+ function isKeywordScope ( scopes ) {
13
15
// Skip 'source.julia'
14
- return scopes . slice ( 1 ) . some ( scope => {
16
+ return scopes . slice ( 1 ) . some ( ( scope ) => {
15
17
return scope . indexOf ( 'keyword' ) > - 1
16
18
} )
17
19
}
18
20
19
- export function isStringScope ( scopes ) {
21
+ /**
22
+ *
23
+ * @param {readonly string[] } scopes
24
+ */
25
+ export function isStringScope ( scopes ) {
20
26
let isString = false
21
27
let isInterp = false
22
28
for ( const scope of scopes ) {
@@ -30,19 +36,22 @@ export function isStringScope (scopes) {
30
36
return isString && ! isInterp
31
37
}
32
38
33
- function forRange ( editor , range ) {
39
+ /**
40
+ *
41
+ * @param {TextEditor } editor
42
+ * @param {RangeCompatible } range
43
+ */
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
43
52
const text = editor . getTextInBufferRange ( range )
44
- juliaGrammar . tokenizeLines ( text ) . forEach ( lineTokens => {
45
- lineTokens . forEach ( token => {
53
+ juliaGrammar . tokenizeLines ( text ) . forEach ( ( lineTokens ) => {
54
+ lineTokens . forEach ( ( token ) => {
46
55
const { value } = token
47
56
if ( ! isStringScope ( token . scopes ) ) {
48
57
if ( n_parens > 0 && value === ')' ) {
@@ -63,9 +72,8 @@ 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 )
@@ -74,16 +82,26 @@ function forRange (editor, range) {
74
82
return scopes
75
83
}
76
84
77
- export function forLines ( editor , start , end ) {
85
+ /**
86
+ *
87
+ * @param {TextEditor } editor
88
+ * @param {number } start
89
+ * @param {number } end
90
+ */
91
+ export function forLines ( editor , start , end ) {
78
92
const startPoint = new Point ( start , 0 )
79
93
const endPoint = new Point ( end , Infinity )
80
94
const range = new Range ( startPoint , endPoint )
81
95
return forRange ( editor , range )
82
96
}
83
97
84
- export function isCommentScope ( scopes ) {
98
+ /**
99
+ *
100
+ * @param {readonly string[] } scopes
101
+ */
102
+ export function isCommentScope ( scopes ) {
85
103
// Skip 'source.julia'
86
- return scopes . slice ( 1 ) . some ( scope => {
104
+ return scopes . slice ( 1 ) . some ( ( scope ) => {
87
105
return scope . indexOf ( 'comment' ) > - 1
88
106
} )
89
107
}
@@ -92,14 +110,17 @@ export function isCommentScope (scopes) {
92
110
* Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected.
93
111
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
94
112
* embedded scopes by default.
113
+ *
114
+ * @param {TextEditor } editor
115
+ * @param {PointCompatible } bufferPosition
95
116
*/
96
- export function isValidScopeToInspect ( editor , bufferPosition ) {
117
+ export function isValidScopeToInspect ( editor , bufferPosition ) {
97
118
const scopes = editor
98
119
. scopeDescriptorForBufferPosition ( bufferPosition )
99
120
. getScopesArray ( )
100
- return scopes . some ( scope => {
121
+ return scopes . some ( ( scope ) => {
101
122
return juliaScopes . includes ( scope )
102
- } ) ?
103
- ! isCommentScope ( scopes ) && ! isStringScope ( scopes ) :
104
- false
123
+ } )
124
+ ? ! isCommentScope ( scopes ) && ! isStringScope ( scopes )
125
+ : false
105
126
}
0 commit comments