Skip to content

Commit 05b49d4

Browse files
committed
npm run build
1 parent 17e277b commit 05b49d4

File tree

2 files changed

+70
-21
lines changed

2 files changed

+70
-21
lines changed

lib/misc/scopes.d.ts

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

lib/misc/scopes.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
/** @babel */
2-
32
import { Point, Range } from 'atom'
4-
53
const juliaScopes = ['source.julia', 'source.embedded.julia']
64
const 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

Comments
 (0)