From e82fa0fb26188adaf41b80acbab33d6b439ad3ca Mon Sep 17 00:00:00 2001 From: aminya Date: Mon, 13 Apr 2020 11:31:11 -0500 Subject: [PATCH] npm run build --- lib/misc/scopes.d.ts | 11 +++++++++ lib/misc/scopes.js | 53 ++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 lib/misc/scopes.d.ts diff --git a/lib/misc/scopes.d.ts b/lib/misc/scopes.d.ts new file mode 100644 index 00000000..4cdf0cf9 --- /dev/null +++ b/lib/misc/scopes.d.ts @@ -0,0 +1,11 @@ +/** @babel */ +import { TextEditor, PointCompatible } from "atom"; +export declare function isStringScope(scopes: readonly string[]): boolean; +export declare function forLines(editor: TextEditor, start: number, end: number): string[]; +export declare function isCommentScope(scopes: readonly string[]): boolean; +/** + * Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected. + * Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support + * embedded scopes by default. + */ +export declare function isValidScopeToInspect(editor: TextEditor, bufferPosition: PointCompatible): boolean; diff --git a/lib/misc/scopes.js b/lib/misc/scopes.js index 83efecc7..cc107a18 100644 --- a/lib/misc/scopes.js +++ b/lib/misc/scopes.js @@ -1,22 +1,34 @@ /** @babel */ - import { Point, Range } from 'atom' - const juliaScopes = ['source.julia', 'source.embedded.julia'] const openers = [ - 'if', 'while', 'for', 'begin', 'function', 'macro', 'module', 'baremodule', 'type', 'immutable', - 'struct', 'mutable struct', 'try', 'let', 'do', 'quote', 'abstract type', 'primitive type' + 'if', + 'while', + 'for', + 'begin', + 'function', + 'macro', + 'module', + 'baremodule', + 'type', + 'immutable', + 'struct', + 'mutable struct', + 'try', + 'let', + 'do', + 'quote', + 'abstract type', + 'primitive type' ] -const reopeners = [ 'else', 'elseif', 'catch', 'finally' ] - -function isKeywordScope (scopes) { +const reopeners = ['else', 'elseif', 'catch', 'finally'] +function isKeywordScope(scopes) { // Skip 'source.julia' return scopes.slice(1).some(scope => { return scope.indexOf('keyword') > -1 }) } - -export function isStringScope (scopes) { +export function isStringScope(scopes) { let isString = false let isInterp = false for (const scope of scopes) { @@ -29,14 +41,11 @@ export function isStringScope (scopes) { } return isString && !isInterp } - -function forRange (editor, range) { +function forRange(editor, range) { // this should happen here and not a top-level so that we aren't relying on // Atom to load packages in a specific order: const juliaGrammar = atom.grammars.grammarForScopeName('source.julia') - if (juliaGrammar === undefined) return [] - const scopes = [] let n_parens = 0 let n_brackets = 0 @@ -63,9 +72,8 @@ function forRange (editor, range) { return } } - if (!(isKeywordScope(token.scopes))) return + if (!isKeywordScope(token.scopes)) return if (!(n_parens === 0 && n_brackets === 0)) return - const reopen = reopeners.includes(value) if (value === 'end' || reopen) scopes.pop() if (openers.includes(value) || reopen) scopes.push(value) @@ -73,33 +81,30 @@ function forRange (editor, range) { }) return scopes } - -export function forLines (editor, start, end) { +export function forLines(editor, start, end) { const startPoint = new Point(start, 0) const endPoint = new Point(end, Infinity) const range = new Range(startPoint, endPoint) return forRange(editor, range) } - -export function isCommentScope (scopes) { +export function isCommentScope(scopes) { // Skip 'source.julia' return scopes.slice(1).some(scope => { return scope.indexOf('comment') > -1 }) } - /** * Returns `true` if the scope at `bufferPosition` in `editor` is valid code scope to be inspected. * Supposed to be used within Atom-IDE integrations, whose `grammarScopes` setting doesn't support * embedded scopes by default. */ -export function isValidScopeToInspect (editor, bufferPosition) { +export function isValidScopeToInspect(editor, bufferPosition) { const scopes = editor .scopeDescriptorForBufferPosition(bufferPosition) .getScopesArray() return scopes.some(scope => { return juliaScopes.includes(scope) - }) ? - !isCommentScope(scopes) && !isStringScope(scopes) : - false + }) + ? !isCommentScope(scopes) && !isStringScope(scopes) + : false }