export function deactivate(): void { subscriptions.dispose(); subscriptions = (null: any); }
afterEach(() => { disposables.dispose(); // Restore viewed state of NUXes localStorage.setItem(NUX_SAVED_STORE, String(nuclideNuxState)); });
hideAllTooltips() { this.tooltipSubscriptions.dispose(); this.tooltipSubscriptions = null; }
dispose() { this._disposables.dispose(); }
consumeStatusBar (statusBar) { const statusBarView = new DeprecationCopStatusBarView() const statusBarTile = statusBar.addRightTile({item: statusBarView, priority: 150}) this.disposables.add(new Disposable(() => { statusBarView.destroy() })) this.disposables.add(new Disposable(() => { statusBarTile.destroy() })) }
dispose(): void { this._subscriptions.dispose(); }
this.tabs.forEach(function (tab) { disposable.add(tab.onDidChangeTab(callback)); });
destroy() { this.subscriptions.dispose(); }
export function consumeGadgetsService(gadgetsApi: GadgetsService): void { invariant(paneItemState$); const gadget: Gadget = (createHealthGadget(paneItemState$): any); subscriptions.add(gadgetsApi.registerGadget(gadget)); }
/** * deactivate all file watcher */ deactivate() { this.disposeNpmHandlers(); this.disposables.clear(); }
destroy() { this.subscriptions.dispose(); this.subscriptions = null; this.view.destroy(); this.view = null; }
componentWillUnmount(): void { if (this._commandsDisposables != null) { this._commandsDisposables.dispose(); } }
consumeGadgetsService(gadgetsApi: GadgetsService): void { const OutputGadget = createConsoleGadget(this._getStore()); this._disposables.add(gadgetsApi.registerGadget(((OutputGadget: any): Gadget))); }
destroy() { this.removeMessages(); this.markerLayer.destroy(); this.subscriptions.dispose(); }
remove() { this.subscriptions.dispose(); this.markers.clear(); this.oRefTextEditorView.classList.remove( "easy-motion-redux-editor" ); super.remove(); }
componentWillUnmount(): void { this._subscriptions.dispose(); }
export function provide(indexer, shouldGetSuggestionsFunction, getInferenceAtCursorPositionFunction, clearCursorInferenceFunction, setAutocompleteActiveFunction) { let subscriptions = new CompositeDisposable(); setTimeout(() => { const autocompletePackage = atom.packages.getActivePackage('autocomplete-plus'); if (autocompletePackage) { const autocompleteManager = autocompletePackage.mainModule.getAutocompleteManager(); subscriptions.add(autocompleteManager.suggestionList.onDidChangeItems((items) => { const editor = atom.workspace.getActiveTextEditor(); if (helper.isElmEditor(editor)) { const hasItems = items !== null; if (!hasItems) { setAutocompleteActiveFunction(editor, false); } } })); } }, 0); let usedEnterKeyToAutocomplete = false; let inferredType = null; subscriptions.add(atom.commands.onWillDispatch((event) => { // Determine if <kbd>enter</kbd> was used to choose a suggestion. if (event.type === 'autocomplete-plus:confirm' && event.originalEvent && event.target.getModel && helper.isElmEditor(event.target.getModel())) { usedEnterKeyToAutocomplete = (event.originalEvent.keyCode === 13); } })); return { selector: '.source.elm', disableForSelector: '.source.elm .string, .source.elm .comment', inclusionPriority: 1, excludeLowerPriority: false, getSuggestions({editor, bufferPosition}) { setAutocompleteActiveFunction(editor, true); if (!helper.isElmEditor(editor) || !shouldGetSuggestionsFunction() || !editor.getSelectedBufferRange().isEmpty()) { return; } return new Promise(resolve => { if (!atom.config.get('elmjutsu.autocompleteEnabled')) { return resolve([]); } const prefix = editor.getTextInRange([[bufferPosition.row, 0], bufferPosition]); let match; const activeToken = helper.getToken(editor) || ''; const typeAwareAutocompleteEnabled = atom.config.get('elmjutsu.typeAwareAutocompleteEnabled'); const replaceWithInferredTypeCompletionEnabled = atom.config.get('elmjutsu.replaceWithInferredTypeCompletionEnabled'); if (typeAwareAutocompleteEnabled || replaceWithInferredTypeCompletionEnabled) { const inference = getInferenceAtCursorPositionFunction(editor); inferredType = inference ? inference.tipe : null; } else { inferredType = null; } const getHintsForPartialPromise = new Promise((resolve) => { let preceedingToken = null; let succeedingToken = null; if (atom.config.get('elmjutsu.autocompleteSnippetsEnabled') || typeAwareAutocompleteEnabled) { [preceedingToken, succeedingToken] = getPreceedingAndSucceedingTokens(editor, bufferPosition, /(\S+)\s/, /\s(\S+)/); } let suffix = ''; const suffixRange = [bufferPosition, [bufferPosition.row, editor.getBuffer().lineLengthForRow(bufferPosition.row)]]; editor.scanInBufferRange(/(\S*)/, suffixRange, ({match, stop}) => { stop(); suffix = match[1]; }); // Check if filtering by regex (prefix starts with a slash (/)). const regexMatch = (prefix + suffix).match(/\s*(\/\S*)$/); let isRegex = false; if (regexMatch && regexMatch[1]) { try { // Validate regex expression. new RegExp(regexMatch[1]); isRegex = true; } catch(e) { } } // Check if filtering by type signature (prefix starts with a colon (:)). const typeSignatureMatch = (prefix + suffix).match(/\s*(:\S*)$/); let isTypeSignature = false; if (typeSignatureMatch && typeSignatureMatch[1]) { try { // Validate regex expressions. const parts = typeSignatureMatch[1].split('__'); parts.forEach((part) => { new RegExp(part); }); isTypeSignature = true; } catch(e) { } } const partial = isTypeSignature ? typeSignatureMatch[1] : (isRegex ? regexMatch[1] : activeToken); return getHintsForPartial(partial, suffix, typeAwareAutocompleteEnabled && inferredType ? inferredType : null , preceedingToken, succeedingToken, isRegex, isTypeSignature, indexer, editor, bufferPosition, resolve); }); const getInferredTypePromise = new Promise((resolve) => { if (inferredType && (activeToken.length === 0 || inferredType.startsWith(activeToken)) ) { return resolve([{ replacementPrefix: activeToken, text: inferredType, rightLabelHTML: specialCompletionIcon() + '<i>Replace with inferred type</i>', }]); } return resolve([]); }); // Construct if/then/else: if (atom.config.get('elmjutsu.insertIfThenElseCompletionEnabled')) { match = prefix.match(/\s+if\s*$/); if (match) { const constructIfThenPromise = new Promise((resolve) => { return resolve([{ replacementPrefix: match[0], snippet: helper.getLeadingSpaces(match[0]) + 'if ${1:} then\n' + helper.tabSpaces() + '${2:}\n' + 'else\n' + helper.tabSpaces() + '${3:}', rightLabelHTML: specialCompletionIcon() + '<i>Insert if/then/else</i>' }]); }); return Promise.all([ constructIfThenPromise, getHintsForPartialPromise ]).then((suggestions) => { return resolve(_.flatten(suggestions, true)); }); } } // Construct let/in: if (atom.config.get('elmjutsu.insertLetInCompletionEnabled')) { match = prefix.match(/\s+let\s*$/); if (match) { const constructLetInPromise = new Promise((resolve) => { return resolve([{ replacementPrefix: match[0], snippet: helper.getLeadingSpaces(match[0]) + // 'let\n' + // helper.tabSpaces() + '${1:} =\n' + // helper.tabSpaces() + helper.tabSpaces() + '${2:}\n' + // 'in\n' + // helper.tabSpaces() + '${3:}', 'let\n' + helper.tabSpaces() + '${1:}\n' + 'in\n' + helper.tabSpaces() + '${2:}', rightLabelHTML: specialCompletionIcon() + '<i>Insert let/in</i>' }]); }); return Promise.all([ constructLetInPromise, getHintsForPartialPromise ]).then((suggestions) => { return resolve(_.flatten(suggestions, true)); }); } } // Construct from type annotation (when cursor is below a type annotation): // e.g. `update : Msg -> Model -> ( Model, Cmd Msg )` will suggest `update msg model =` // e.g. `add3 : Int -> Int -> Int -> Int` will suggest `add3 int1 int2 int3 =` // e.g. `funWithInt : Int -> Int` will suggest `funWithInt int =` // e.g. `funWithTuple : (Int, Int) -> Int` will suggest `funWithTuple (int1, int2) =` // e.g. `funWithRecord : {a : Int, b : Int, c: Int} -> Int` will suggest `funWithRecord record =` // e.g. `funWithRecord2 : {a : Int, b : Int, c: Int} -> {a : Int, b : Int, c: Int} -> Int` will suggest `funWithRecord record1 record2 =` if (atom.config.get('elmjutsu.defineFromTypeAnnotationCompletionEnabled')) { const typeAnnotation = helper.getTypeAnnotationAbove(editor); if (typeAnnotation) { const constructFromTypeAnnotationPromise = new Promise((resolve) => { return constructFromTypeAnnotation(prefix, typeAnnotation, indexer, resolve); }); return Promise.all([ constructFromTypeAnnotationPromise, getHintsForPartialPromise ]).then((suggestions) => { return resolve(_.flatten(suggestions, true)); }); } } // e.g. `import ` (there's a space at the end) // e.g. `import Dict` match = prefix.match(/(?:^|\n)import\s([\w\S]*)$/); if (match) { return getSuggestionsForImport(prefix, match[1], indexer, resolve); } // e.g. `import Dict ` (there's a space at the end) match = prefix.match(/(?:^|\n)import\s([\w\.]+)\s$/); if (match) { return resolve([{text: 'exposing (..)'}, {text: 'exposing ('}, {text: 'as '}]); } // e.g. `import Dict exposing ` (there's a space at the end) match = prefix.match(/(?:^|\n)import\s([\w\.]+)(?:\s+as\s+(\w+))?\s+exposing\s$/); if (match) { return resolve([{text: '(..)'}]); } // Construct module: if (atom.config.get('elmjutsu.insertModuleCompletionEnabled')) { match = prefix.match(/(?:^|\n)((effect|port)\s+)?module(\s+)?$/); if (match) { return resolve([{ replacementPrefix: prefix, snippet: (match[1] || '') + 'module ${1:Main} exposing (${2:..})\n\n${3:}', rightLabelHTML: specialCompletionIcon() + '<i>Insert module</i>' }]); } } // Ending with space: match = prefix.match(/(?:\b)(\S+)\s$/); if (match) { const replacementPrefix = match[0]; const token = match[1]; let promises = []; // Construct default arguments: if (atom.config.get('elmjutsu.insertDefaultArgumentsCompletionEnabled')) { const constructDefaultArgumentsPromise = new Promise((resolve) => { const [preceedingToken, succeedingToken] = getPreceedingAndSucceedingTokens(editor, bufferPosition, /\s+(\S+)\s/, /\s(\S+)/); return constructDefaultArguments(token, shouldRemoveLastArgument(preceedingToken, succeedingToken), indexer, resolve); }); promises.push(constructDefaultArgumentsPromise); } // Construct "default value for type" replacement: // e.g. ` Position ` (there's a space at the end) => `{ x = 0.0, y = 0.0, z = 0.0 }` // TODO: Should check if text begins with capital letter after the dot (e.g. `Dict.Dict` will pass, but `Dict.empty` will not). if (atom.config.get('elmjutsu.replaceTypeWithDefaultCompletionEnabled')) { if (/[A-Z]\S+/.test(replacementPrefix)) { const constructDefaultValueForTypePromise = new Promise((resolve) => { return constructDefaultValueForType(replacementPrefix, token, indexer, resolve); }); promises.push(constructDefaultValueForTypePromise); } } // // Get aliases of type: // // e.g. ` String ` (there's a space at the end) => `StringAlias` // // TODO: Should check if text begins with capital letter after the dot (e.g. `Dict.Dict` will pass, but `Dict.empty` will not). // if (atom.config.get('elmjutsu.replaceTypeWithAliasCompletionEnabled')) { // if (/[A-Z]\S+/.test(replacementPrefix)) { // const getAliasesOfTypePromise = new Promise((resolve) => { // return getAliasesOfType(replacementPrefix, token, indexer, resolve); // }); // promises.push(getAliasesOfTypePromise); // } // } // Construct case/of: // e.g. ` case aBool ` // e.g. ` case aMaybe ` // e.g. ` case aMsg ` // e.g. ` case aMsg of` if (atom.config.get('elmjutsu.insertCaseOfCompletionEnabled')) { match = prefix.match(/\s+case\s(.+)\s+(|of)$/); if (match) { const constructCaseOfPromise = new Promise((resolve) => { return constructCaseOf(match[0], match[1], indexer, resolve); }); promises.unshift(constructCaseOfPromise); } } if (inferredType) { if (replaceWithInferredTypeCompletionEnabled) { promises.push(getInferredTypePromise); } promises.push(getHintsForPartialPromise); } return Promise.all(promises).then((suggestions) => { return resolve(_.flatten(suggestions, true)); }); } let promises = [getHintsForPartialPromise]; if (inferredType && replaceWithInferredTypeCompletionEnabled) { promises.unshift(getInferredTypePromise); } return Promise.all(promises).then((suggestions) => { return resolve(_.flatten(suggestions, true)); }); }); }, onDidInsertSuggestion({editor, triggerPosition, suggestion}) { if (inferredType) { clearCursorInferenceFunction(); } // HACK: If the typed text is equal to the chosen suggestion and <kbd>enter</kbd> was used, insert a newline. if (usedEnterKeyToAutocomplete && suggestion.replacementPrefix === suggestion.text && atom.config.get('autocomplete-plus.confirmCompletion') !== 'tab') { // `Keymap For Confirming A Suggestion` should be 'enter', 'tab and enter', or 'tab always, enter when suggestion explicitly selected'. editor.insertText('\n'); } if (suggestion.fromTypeAnnotationConstructed && editor.lineTextForBufferRow(editor.getCursorBufferPosition().row).trim() !== '') { editor.selectToFirstCharacterOfLine(); } if (suggestion.autoImportData) { // Replace inserted text (see notes in `getHintsForPartial`). const position = editor.getCursorBufferPosition(); editor.setTextInBufferRange([triggerPosition.translate([0, -suggestion.autoImportData.partial.length]), position], suggestion.autoImportData.text); editor.groupChangesSinceCheckpoint(suggestion.autoImportData.checkpoint); const filePath = editor.getPath(); const projectDirectory = helper.getProjectDirectory(filePath); indexer.ports.addImportSub.send([filePath, projectDirectory, suggestion.autoImportData.moduleName, suggestion.autoImportData.name]); } if (suggestion.deleteSuffixData) { // See `getHintsForPartial`. const bufferPosition = editor.getCursorBufferPosition(); if (suggestion.deleteSuffixData.suffix.length > 0) { editor.scanInBufferRange(new RegExp(_.escapeRegExp(suggestion.deleteSuffixData.suffix)), [bufferPosition, [bufferPosition.row, editor.getBuffer().lineLengthForRow(bufferPosition.row)]], ({match, stop, replace}) => { stop(); replace(''); }); } editor.groupChangesSinceCheckpoint(suggestion.deleteSuffixData.checkpoint); } }, dispose() { subscriptions.dispose(); subscriptions = null; } }; }
{children} </div> ); }, componentWillMount(): void { var allKeys = []; var keyToNode = {}; this.state.roots.forEach(root => { var rootKey = root.getKey(); allKeys.push(rootKey); keyToNode[rootKey] = root; }); var subscriptions = new CompositeDisposable(); subscriptions.add(atom.commands.add( this.props.eventHandlerSelector, { // Expand and collapse. 'core:move-right': () => this._expandSelection(), 'core:move-left': () => this._collapseSelection(), // Move selection up and down. 'core:move-up': () => this._moveSelectionUp(), 'core:move-down': () => this._moveSelectionDown(), 'core:confirm': () => this._confirmSelection(), })); this._allKeys = allKeys;
this.tabs.forEach(function (tab) { disposable.add(tab.onShouldTogglePanel(callback)); });
consumeTaskRunnerServiceApi(api: TaskRunnerServiceApi): void { this._disposables.add(api.register(this._getBuildSystem())); }
dispose(): void { this._isDisposed = true; this._subscriptions.dispose(); }
dispose(): void { this._disposables.dispose(); }
componentWillUnmount(): void { this._disposables.dispose(); }
dispose() { this.emitter.emit('did-destroy') this.subscriptions.dispose() }
describe('NuxTour', () => { function generateTestNuxTour( id: number, name: string, numViews: number = 1, ): NuxTourModel { const nuxViewModel = { content: 'Content', selector: '.something', position: 'auto', completionPredicate: null, }; return { id, name, nuxList: Array(numViews).fill(nuxViewModel), }; } let nuxStore; let disposables: CompositeDisposable; let nuclideNuxState; beforeEach(() => { disposables = new CompositeDisposable(); // Save viewed state of NUXes nuclideNuxState = localStorage.getItem(NUX_SAVED_STORE); localStorage.clear(); nuxStore = new NuxStore(); disposables.add(nuxStore); }); afterEach(() => { disposables.dispose(); // Restore viewed state of NUXes localStorage.setItem(NUX_SAVED_STORE, String(nuclideNuxState)); }); it("stores a NuxTour's state in the NuxStore", () => { nuxStore.addNewNux(generateTestNuxTour(-1, 'a')); nuxStore.addNewNux(generateTestNuxTour(-2, 'b')); expect(nuxStore._nuxMap.size).toBe(2); }); it('creates a NuxTour from a NuxTourModel', () => { const nuxManager = new NuxManager(nuxStore, () => {}); disposables.add(nuxManager); nuxStore.addNewNux( generateTestNuxTour( NUX_TOUR_SPEC_EXAMPLE_NUX_ID, NUX_TOUR_SPEC_EXAMPLE_NUX_NAME, ), ); expect(nuxStore._nuxMap.size).toBe(1); }); it('creates a NuxTour that waits for a trigger', () => { const nuxManager = new NuxManager(nuxStore, () => {}); disposables.add(nuxManager); const nuxTour = generateTestNuxTour( NUX_TOUR_SPEC_EXAMPLE_NUX_ID, NUX_TOUR_SPEC_EXAMPLE_NUX_NAME, ); nuxTour.trigger = { triggerType: 'editor', triggerCallback: () => false, }; nuxStore.addNewNux(nuxTour); expect(nuxStore._nuxMap.size).toBe(1); expect(nuxManager._readyToDisplayNuxes.length).toBe(0); expect(nuxManager._pendingNuxes.size).toBe(1); expect(nuxManager._activeNuxTour != null).toBeFalsy(); }); });
function deactivate(): void { gadgetsApi = null; allHomeFragmentsStream.onNext(Immutable.Set()); subscriptions.dispose(); subscriptions = (null: any); }
destroy() { if (this.subscriptions) this.subscriptions.dispose(); if (this.tooltipSubscriptions) this.tooltipSubscriptions.dispose(); }
dispose() { if(this.disposables.disposed) return; this.disposables.dispose(); this.clearMark(); [this.editor, this.marker, this.disposables] = []; }
detached () { this.subscriptions.dispose() }
dispose() { this.active = false this.subscriptions.dispose() }