Skip to content

Commit 0fdc409

Browse files
committed
Prettier on scopes
1 parent 26b092c commit 0fdc409

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

lib_src/misc/scopes.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
11
/** @babel */
22

3-
import { Point, Range } from 'atom'
3+
import { Point, Range } from "atom"
44

5-
const juliaScopes = ['source.julia', 'source.embedded.julia']
5+
const juliaScopes = ["source.julia", "source.embedded.julia"]
66
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'
7+
"if",
8+
"while",
9+
"for",
10+
"begin",
11+
"function",
12+
"macro",
13+
"module",
14+
"baremodule",
15+
"type",
16+
"immutable",
17+
"struct",
18+
"mutable struct",
19+
"try",
20+
"let",
21+
"do",
22+
"quote",
23+
"abstract type",
24+
"primitive type"
925
]
10-
const reopeners = [ 'else', 'elseif', 'catch', 'finally' ]
26+
const reopeners = ["else", "elseif", "catch", "finally"]
1127

12-
function isKeywordScope (scopes) {
28+
function isKeywordScope(scopes) {
1329
// Skip 'source.julia'
1430
return scopes.slice(1).some(scope => {
15-
return scope.indexOf('keyword') > -1
31+
return scope.indexOf("keyword") > -1
1632
})
1733
}
1834

19-
export function isStringScope (scopes) {
35+
export function isStringScope(scopes) {
2036
let isString = false
2137
let isInterp = false
2238
for (const scope of scopes) {
23-
if (scope.indexOf('string') > -1) {
39+
if (scope.indexOf("string") > -1) {
2440
isString = true
2541
}
26-
if (scope.indexOf('interpolation') > -1) {
42+
if (scope.indexOf("interpolation") > -1) {
2743
isInterp = true
2844
}
2945
}
3046
return isString && !isInterp
3147
}
3248

33-
function forRange (editor, range) {
49+
function forRange(editor, range) {
3450
// this should happen here and not a top-level so that we aren't relying on
3551
// Atom to load packages in a specific order:
36-
const juliaGrammar = atom.grammars.grammarForScopeName('source.julia')
52+
const juliaGrammar = atom.grammars.grammarForScopeName("source.julia")
3753

3854
if (juliaGrammar === undefined) return []
3955

@@ -45,46 +61,46 @@ function forRange (editor, range) {
4561
lineTokens.forEach(token => {
4662
const { value } = token
4763
if (!isStringScope(token.scopes)) {
48-
if (n_parens > 0 && value === ')') {
64+
if (n_parens > 0 && value === ")") {
4965
n_parens -= 1
50-
scopes.splice(scopes.lastIndexOf('paren'), 1)
66+
scopes.splice(scopes.lastIndexOf("paren"), 1)
5167
return
52-
} else if (n_brackets > 0 && value === ']') {
68+
} else if (n_brackets > 0 && value === "]") {
5369
n_brackets -= 1
54-
scopes.splice(scopes.lastIndexOf('bracket'), 1)
70+
scopes.splice(scopes.lastIndexOf("bracket"), 1)
5571
return
56-
} else if (value === '(') {
72+
} else if (value === "(") {
5773
n_parens += 1
58-
scopes.push('paren')
74+
scopes.push("paren")
5975
return
60-
} else if (value === '[') {
76+
} else if (value === "[") {
6177
n_brackets += 1
62-
scopes.push('bracket')
78+
scopes.push("bracket")
6379
return
6480
}
6581
}
66-
if (!(isKeywordScope(token.scopes))) return
82+
if (!isKeywordScope(token.scopes)) return
6783
if (!(n_parens === 0 && n_brackets === 0)) return
6884

6985
const reopen = reopeners.includes(value)
70-
if (value === 'end' || reopen) scopes.pop()
86+
if (value === "end" || reopen) scopes.pop()
7187
if (openers.includes(value) || reopen) scopes.push(value)
7288
})
7389
})
7490
return scopes
7591
}
7692

77-
export function forLines (editor, start, end) {
93+
export function forLines(editor, start, end) {
7894
const startPoint = new Point(start, 0)
7995
const endPoint = new Point(end, Infinity)
8096
const range = new Range(startPoint, endPoint)
8197
return forRange(editor, range)
8298
}
8399

84-
export function isCommentScope (scopes) {
100+
export function isCommentScope(scopes) {
85101
// Skip 'source.julia'
86102
return scopes.slice(1).some(scope => {
87-
return scope.indexOf('comment') > -1
103+
return scope.indexOf("comment") > -1
88104
})
89105
}
90106

@@ -93,13 +109,13 @@ export function isCommentScope (scopes) {
93109
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
94110
* embedded scopes by default.
95111
*/
96-
export function isValidScopeToInspect (editor, bufferPosition) {
112+
export function isValidScopeToInspect(editor, bufferPosition) {
97113
const scopes = editor
98114
.scopeDescriptorForBufferPosition(bufferPosition)
99115
.getScopesArray()
100116
return scopes.some(scope => {
101117
return juliaScopes.includes(scope)
102-
}) ?
103-
!isCommentScope(scopes) && !isStringScope(scopes) :
104-
false
118+
})
119+
? !isCommentScope(scopes) && !isStringScope(scopes)
120+
: false
105121
}

0 commit comments

Comments
 (0)