11/** @babel */
2-
32import { Point , Range } from 'atom'
4-
53const juliaScopes = [ 'source.julia' , 'source.embedded.julia' ]
64const openers = [
75 'if' , 'while' , 'for' , 'begin' , 'function' , 'macro' , 'module' , 'baremodule' , 'type' , 'immutable' ,
86 'struct' , 'mutable struct' , 'try' , 'let' , 'do' , 'quote' , 'abstract type' , 'primitive type'
97]
10- const reopeners = [ 'else' , 'elseif' , 'catch' , 'finally' ]
8+ const reopeners = [ 'else' , 'elseif' , 'catch' , 'finally' ]
119
12- function isKeywordScope ( scopes ) {
10+ /**
11+ *
12+ * @param {readonly string[] } scopes
13+ */
14+ function isKeywordScope ( scopes ) {
1315 // Skip 'source.julia'
14- return scopes . slice ( 1 ) . some ( scope => {
16+ return scopes . slice ( 1 ) . some ( ( scope ) => {
1517 return scope . indexOf ( 'keyword' ) > - 1
1618 } )
1719}
1820
19- export function isStringScope ( scopes ) {
21+ /**
22+ *
23+ * @param {readonly string[] } scopes
24+ */
25+ export function isStringScope ( scopes ) {
2026 let isString = false
2127 let isInterp = false
2228 for ( const scope of scopes ) {
@@ -30,19 +36,22 @@ export function isStringScope (scopes) {
3036 return isString && ! isInterp
3137}
3238
33- function forRange ( editor , range ) {
39+ /**
40+ *
41+ * @param {TextEditor } editor
42+ * @param {RangeCompatible } range
43+ */
44+ function forRange ( editor , range ) {
3445 // this should happen here and not a top-level so that we aren't relying on
3546 // Atom to load packages in a specific order:
3647 const juliaGrammar = atom . grammars . grammarForScopeName ( 'source.julia' )
37-
3848 if ( juliaGrammar === undefined ) return [ ]
39-
4049 const scopes = [ ]
4150 let n_parens = 0
4251 let n_brackets = 0
4352 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 ) => {
4655 const { value } = token
4756 if ( ! isStringScope ( token . scopes ) ) {
4857 if ( n_parens > 0 && value === ')' ) {
@@ -63,9 +72,8 @@ function forRange (editor, range) {
6372 return
6473 }
6574 }
66- if ( ! ( isKeywordScope ( token . scopes ) ) ) return
75+ if ( ! isKeywordScope ( token . scopes ) ) return
6776 if ( ! ( n_parens === 0 && n_brackets === 0 ) ) return
68-
6977 const reopen = reopeners . includes ( value )
7078 if ( value === 'end' || reopen ) scopes . pop ( )
7179 if ( openers . includes ( value ) || reopen ) scopes . push ( value )
@@ -74,16 +82,26 @@ function forRange (editor, range) {
7482 return scopes
7583}
7684
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 ) {
7892 const startPoint = new Point ( start , 0 )
7993 const endPoint = new Point ( end , Infinity )
8094 const range = new Range ( startPoint , endPoint )
8195 return forRange ( editor , range )
8296}
8397
84- export function isCommentScope ( scopes ) {
98+ /**
99+ *
100+ * @param {readonly string[] } scopes
101+ */
102+ export function isCommentScope ( scopes ) {
85103 // Skip 'source.julia'
86- return scopes . slice ( 1 ) . some ( scope => {
104+ return scopes . slice ( 1 ) . some ( ( scope ) => {
87105 return scope . indexOf ( 'comment' ) > - 1
88106 } )
89107}
@@ -92,14 +110,17 @@ export function isCommentScope (scopes) {
92110 * Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected.
93111 * Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
94112 * embedded scopes by default.
113+ *
114+ * @param {TextEditor } editor
115+ * @param {PointCompatible } bufferPosition
95116 */
96- export function isValidScopeToInspect ( editor , bufferPosition ) {
117+ export function isValidScopeToInspect ( editor , bufferPosition ) {
97118 const scopes = editor
98119 . scopeDescriptorForBufferPosition ( bufferPosition )
99120 . getScopesArray ( )
100- return scopes . some ( scope => {
121+ return scopes . some ( ( scope ) => {
101122 return juliaScopes . includes ( scope )
102- } ) ?
103- ! isCommentScope ( scopes ) && ! isStringScope ( scopes ) :
104- false
123+ } )
124+ ? ! isCommentScope ( scopes ) && ! isStringScope ( scopes )
125+ : false
105126}
0 commit comments