setInScopeLines.js (1542B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 import { 6 hasInScopeLines, 7 getSourceTextContentForLocation, 8 getVisibleSelectedFrame, 9 } from "../../selectors/index"; 10 11 import { isFulfilled } from "../../utils/async-value"; 12 13 /** 14 * Get and store the in scope lines in the reducer 15 * 16 * @param {object} editor - The editor provides an API to retrieve the in scope location 17 * details based on lezer in CM6. 18 * @returns 19 */ 20 export function setInScopeLines(editor) { 21 return async thunkArgs => { 22 const { getState, dispatch } = thunkArgs; 23 const visibleFrame = getVisibleSelectedFrame(getState()); 24 25 if (!visibleFrame) { 26 return; 27 } 28 29 const { location } = visibleFrame; 30 const sourceTextContent = getSourceTextContentForLocation( 31 getState(), 32 location 33 ); 34 35 // Ignore if in scope lines have already be computed, or if the selected location 36 // doesn't have its content already fully fetched. 37 // The ParserWorker will only have the source text content once the source text content is fulfilled. 38 if ( 39 hasInScopeLines(getState(), location) || 40 !sourceTextContent || 41 !isFulfilled(sourceTextContent) || 42 !editor 43 ) { 44 return; 45 } 46 47 const lines = await editor.getInScopeLines(location); 48 49 dispatch({ 50 type: "IN_SCOPE_LINES", 51 location, 52 lines, 53 }); 54 }; 55 }