Skip to content

Commit 183fa4c

Browse files
committed
scopes type definitions + remove babel + Prettier on scopes
Starting with misc/scopes.ts tsconfig Separate source-map Update tsconfig.json Update scopes.ts
1 parent 3530288 commit 183fa4c

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

lib_src/misc/scopes.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,104 @@
1-
/** @babel */
1+
import {Point, PointCompatible, Range, RangeCompatible, TextEditor} from "atom"
22

3-
import { Point, Range } from 'atom'
4-
5-
const juliaScopes = ['source.julia', 'source.embedded.julia']
3+
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' ]
24+
const reopeners = ["else", "elseif", "catch", "finally"]
1125

12-
function isKeywordScope (scopes) {
26+
function isKeywordScope(scopes: string[]) {
1327
// Skip 'source.julia'
1428
return scopes.slice(1).some(scope => {
15-
return scope.indexOf('keyword') > -1
29+
return scope.indexOf("keyword") > -1
1630
})
1731
}
1832

19-
export function isStringScope (scopes) {
33+
export function isStringScope(scopes: readonly string[]) {
2034
let isString = false
2135
let isInterp = false
2236
for (const scope of scopes) {
23-
if (scope.indexOf('string') > -1) {
37+
if (scope.indexOf("string") > -1) {
2438
isString = true
2539
}
26-
if (scope.indexOf('interpolation') > -1) {
40+
if (scope.indexOf("interpolation") > -1) {
2741
isInterp = true
2842
}
2943
}
3044
return isString && !isInterp
3145
}
3246

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

3852
if (juliaGrammar === undefined) return []
3953

40-
const scopes = []
54+
const scopes: string[] = []
4155
let n_parens = 0
4256
let n_brackets = 0
4357
const text = editor.getTextInBufferRange(range)
4458
juliaGrammar.tokenizeLines(text).forEach(lineTokens => {
4559
lineTokens.forEach(token => {
4660
const { value } = token
4761
if (!isStringScope(token.scopes)) {
48-
if (n_parens > 0 && value === ')') {
62+
if (n_parens > 0 && value === ")") {
4963
n_parens -= 1
50-
scopes.splice(scopes.lastIndexOf('paren'), 1)
64+
scopes.splice(scopes.lastIndexOf("paren"), 1)
5165
return
52-
} else if (n_brackets > 0 && value === ']') {
66+
} else if (n_brackets > 0 && value === "]") {
5367
n_brackets -= 1
54-
scopes.splice(scopes.lastIndexOf('bracket'), 1)
68+
scopes.splice(scopes.lastIndexOf("bracket"), 1)
5569
return
56-
} else if (value === '(') {
70+
} else if (value === "(") {
5771
n_parens += 1
58-
scopes.push('paren')
72+
scopes.push("paren")
5973
return
60-
} else if (value === '[') {
74+
} else if (value === "[") {
6175
n_brackets += 1
62-
scopes.push('bracket')
76+
scopes.push("bracket")
6377
return
6478
}
6579
}
66-
if (!(isKeywordScope(token.scopes))) return
80+
if (!isKeywordScope(token.scopes)) return
6781
if (!(n_parens === 0 && n_brackets === 0)) return
6882

6983
const reopen = reopeners.includes(value)
70-
if (value === 'end' || reopen) scopes.pop()
84+
if (value === "end" || reopen) scopes.pop()
7185
if (openers.includes(value) || reopen) scopes.push(value)
7286
})
7387
})
7488
return scopes
7589
}
7690

77-
export function forLines (editor, start, end) {
91+
export function forLines(editor: TextEditor, start: number, end: number) {
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+
export function isCommentScope(scopes: readonly string[]) {
8599
// Skip 'source.julia'
86100
return scopes.slice(1).some(scope => {
87-
return scope.indexOf('comment') > -1
101+
return scope.indexOf("comment") > -1
88102
})
89103
}
90104

@@ -93,13 +107,13 @@ export function isCommentScope (scopes) {
93107
* Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support
94108
* embedded scopes by default.
95109
*/
96-
export function isValidScopeToInspect (editor, bufferPosition) {
110+
export function isValidScopeToInspect(editor: TextEditor, bufferPosition: PointCompatible) {
97111
const scopes = editor
98112
.scopeDescriptorForBufferPosition(bufferPosition)
99113
.getScopesArray()
100114
return scopes.some(scope => {
101115
return juliaScopes.includes(scope)
102-
}) ?
103-
!isCommentScope(scopes) && !isStringScope(scopes) :
104-
false
116+
})
117+
? !isCommentScope(scopes) && !isStringScope(scopes)
118+
: false
105119
}

lib_src/tsconfig.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"esModuleInterop": true,
1818
"experimentalDecorators": true,
1919
"incremental": true,
20-
"inlineSourceMap": true,
20+
// "inlineSourceMap": false,
2121
// "preserveConstEnums": true,
22-
// "sourceMap": true,
22+
"sourceMap": true,
2323
"preserveSymlinks": true,
2424
// "removeComments": true,
2525
// "jsx": "react",
@@ -31,9 +31,8 @@
3131
// "noLib": false,
3232
// "importHelpers": true, // if true you should add tslib to deps
3333
// "skipLibCheck": false,
34-
35-
"outDir": "../lib",
36-
"files" : ["ui/selector.ts"]
34+
"outDir": "../lib/misc"
3735
},
36+
"files" : ["misc/scopes.ts"],
3837
"compileOnSave": true
3938
}

0 commit comments

Comments
 (0)