Skip to content

Commit e82fa0f

Browse files
committed
npm run build
1 parent b98e124 commit e82fa0f

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

lib/misc/scopes.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @babel */
2+
import { TextEditor, PointCompatible } from "atom";
3+
export declare function isStringScope(scopes: readonly string[]): boolean;
4+
export declare function forLines(editor: TextEditor, start: number, end: number): string[];
5+
export declare function isCommentScope(scopes: readonly string[]): boolean;
6+
/**
7+
* Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected.
8+
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
9+
* embedded scopes by default.
10+
*/
11+
export declare function isValidScopeToInspect(editor: TextEditor, bufferPosition: PointCompatible): boolean;

lib/misc/scopes.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
/** @babel */
2-
32
import { Point, Range } from 'atom'
4-
53
const juliaScopes = ['source.julia', 'source.embedded.julia']
64
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'
923
]
10-
const reopeners = [ 'else', 'elseif', 'catch', 'finally' ]
11-
12-
function isKeywordScope (scopes) {
24+
const reopeners = ['else', 'elseif', 'catch', 'finally']
25+
function isKeywordScope(scopes) {
1326
// Skip 'source.julia'
1427
return scopes.slice(1).some(scope => {
1528
return scope.indexOf('keyword') > -1
1629
})
1730
}
18-
19-
export function isStringScope (scopes) {
31+
export function isStringScope(scopes) {
2032
let isString = false
2133
let isInterp = false
2234
for (const scope of scopes) {
@@ -29,14 +41,11 @@ export function isStringScope (scopes) {
2941
}
3042
return isString && !isInterp
3143
}
32-
33-
function forRange (editor, range) {
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
@@ -63,43 +72,39 @@ 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)
7280
})
7381
})
7482
return scopes
7583
}
76-
77-
export function forLines (editor, start, end) {
84+
export function forLines(editor, start, end) {
7885
const startPoint = new Point(start, 0)
7986
const endPoint = new Point(end, Infinity)
8087
const range = new Range(startPoint, endPoint)
8188
return forRange(editor, range)
8289
}
83-
84-
export function isCommentScope (scopes) {
90+
export function isCommentScope(scopes) {
8591
// Skip 'source.julia'
8692
return scopes.slice(1).some(scope => {
8793
return scope.indexOf('comment') > -1
8894
})
8995
}
90-
9196
/**
9297
* Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected.
9398
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
9499
* embedded scopes by default.
95100
*/
96-
export function isValidScopeToInspect (editor, bufferPosition) {
101+
export function isValidScopeToInspect(editor, bufferPosition) {
97102
const scopes = editor
98103
.scopeDescriptorForBufferPosition(bufferPosition)
99104
.getScopesArray()
100105
return scopes.some(scope => {
101106
return juliaScopes.includes(scope)
102-
}) ?
103-
!isCommentScope(scopes) && !isStringScope(scopes) :
104-
false
107+
})
108+
? !isCommentScope(scopes) && !isStringScope(scopes)
109+
: false
105110
}

0 commit comments

Comments
 (0)