|
| 1 | +function parseInfoFromFolder (folders, analysisLimit, responseChannel) |
| 2 | + % PARSEINFOFROMFOLDER Parses the MATLAB files in the provided folders and extracts |
| 3 | + % information about variables, functions, etc. |
| 4 | + % |
| 5 | + % Instead of returning the parsed results, this function will stream those results |
| 6 | + % over the response channel. This allows for these files to be processed without |
| 7 | + % blocking the MATLAB thread for the full duration. |
| 8 | + |
| 9 | + % Copyright 2025 The MathWorks, Inc. |
| 10 | + |
| 11 | + filesToParse = getAllMFilesToParse(folders); |
| 12 | + parfeval(backgroundPool, @doParseFiles, 0, filesToParse, analysisLimit, responseChannel); |
| 13 | +end |
| 14 | + |
| 15 | +function filesToParse = getAllMFilesToParse (folders) |
| 16 | + % Gathers a list of all M files within the given folders |
| 17 | + |
| 18 | + filesToParse = []; |
| 19 | + |
| 20 | + for n = 1:numel(folders) |
| 21 | + fileListing = dir([folders{n} '/**/*.m']); |
| 22 | + fileNames = strings(numel(fileListing), 1); |
| 23 | + for m = 1:numel(fileListing) |
| 24 | + fileNames(m) = fullfile(fileListing(m).folder, fileListing(m).name); |
| 25 | + end |
| 26 | + filesToParse = [filesToParse; fileNames]; %#ok<AGROW> |
| 27 | + end |
| 28 | +end |
| 29 | + |
| 30 | +function doParseFiles (filesToParse, analysisLimit, responseChannel) |
| 31 | + % Processes the given list of files. |
| 32 | + % |
| 33 | + % This can be executed in a separate thread (e.g. parfeval) to avoid blocking |
| 34 | + % the MATLAB thread. |
| 35 | + |
| 36 | + for n = 1:numel(filesToParse) |
| 37 | + filePath = filesToParse{n}; |
| 38 | + isLastFile = (n == numel(filesToParse)); |
| 39 | + parseFile(filePath, isLastFile, analysisLimit, responseChannel); |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +function parseFile (filePath, isLastFile, analysisLimit, responseChannel) |
| 44 | + % Parses an individual file and publishes the results over the response channel. |
| 45 | + % |
| 46 | + % If the file to be parsed is the last file, an `isDone` flag on the results is |
| 47 | + % set to true to indicate that the parsing process has completed. |
| 48 | + |
| 49 | + code = fileread(filePath); |
| 50 | + codeData = matlabls.handlers.indexing.parseInfoFromDocument(code, filePath, analysisLimit); |
| 51 | + |
| 52 | + % Send data for this file |
| 53 | + msg.filePath = filePath; |
| 54 | + msg.codeData = codeData; |
| 55 | + msg.isDone = isLastFile; |
| 56 | + |
| 57 | + matlabls.internal.CommunicationManager.publish(responseChannel, msg); |
| 58 | +end |
0 commit comments