UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

82 lines (81 loc) 5.2 kB
import { FlowrAnalyzerPlugin, PluginType } from '../flowr-analyzer-plugin'; import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context'; import type { RParseRequest } from '../../../r-bridge/retriever'; import type { RProjectAnalysisRequest } from '../../context/flowr-analyzer-files-context'; import { SemVer } from 'semver'; import { type FlowrFile } from '../../context/flowr-file'; /** * This is the base class for all plugins that discover files in a project for analysis. * These plugins interplay with the {@link FlowrAnalyzerFilesContext} to gather information about the files in the project. * See {@link FlowrAnalyzerDefaultProjectDiscoveryPlugin} for the default implementation. * * In general, these plugins only trigger for a {@link RProjectAnalysisRequest} with the idea to discover all files in a project. */ export declare abstract class FlowrAnalyzerProjectDiscoveryPlugin extends FlowrAnalyzerPlugin<RProjectAnalysisRequest, (RParseRequest | FlowrFile<string>)[]> { readonly type = PluginType.ProjectDiscovery; static defaultPlugin(): FlowrAnalyzerProjectDiscoveryPlugin; } export declare const discoverRSourcesRegex: RegExp; export declare const ignorePathsWith: RegExp; export declare const excludeRequestsForPaths: RegExp; /** Options for {@link collectRequests}; unset fields fall back to the module defaults. */ export interface CollectRequestOptions { /** the regex marking a path as an R source to parse (default {@link discoverRSourcesRegex}) */ readonly supportedExtensions?: RegExp; /** directories whose R sources are collected as text rather than parsed (default {@link excludeRequestsForPaths}) */ readonly excludePathsRegex?: RegExp; /** if set, only paths matching this regex are parsed as R */ readonly onlyTraversePaths?: RegExp; } /** * Turn the walked `files` (absolute paths under `root`) into the discovery result: R sources become * {@link RParseRequest}s, everything else -- and R sources under an excluded directory -- becomes a * {@link FlowrTextFile}; `.Rprofile` files get both so they are tagged. This is the single emit implementation * shared by the greedy and the intelligent discovery plugins. */ export declare function collectRequests(files: Iterable<string>, root: string, opts?: CollectRequestOptions): (RParseRequest | FlowrFile<string>)[]; /** Configuration options for the {@link FlowrAnalyzerFullProjectDiscoveryPlugin}. */ export interface ProjectDiscoveryConfig { /** the regex to trigger R source file discovery on (and hence analyze them as R files) */ triggerOnExtensions?: RegExp; /** the regex to ignore certain paths entirely */ ignorePathsRegex?: RegExp; /** the regex to exclude certain paths from being requested as R files (they are still collected as text files) */ excludePathsRegex?: RegExp; /** if set, only paths matching this regex are traversed */ onlyTraversePaths?: RegExp; } /** * The greedy discovery implementation: every file below the root becomes a {@link RParseRequest} (R and Rmd files) * or a {@link FlowrTextFile} (the rest). This is what {@link FlowrAnalyzerDefaultProjectDiscoveryPlugin} falls back * to in `full` mode. */ export declare class FlowrAnalyzerFullProjectDiscoveryPlugin extends FlowrAnalyzerProjectDiscoveryPlugin { readonly name = "full-project-discovery-plugin"; readonly description = "Collects every file below the project root (greedy discovery)."; readonly version: SemVer; private readonly supportedExtensions; private readonly ignorePathsRegex; private readonly excludePathsRegex; private readonly onlyTraversePaths; /** * Creates a new instance of the greedy project discovery plugin. * @param triggerOnExtensions - the regex to trigger R source file discovery on (and hence analyze them as R files) * @param ignorePathsRegex - the regex to ignore certain paths entirely * @param excludePathsRegex - the regex to exclude certain paths from being requested as R files (they are still collected as text files) * @param onlyTraversePaths - if set, only paths matching this regex are traversed */ constructor({ triggerOnExtensions, ignorePathsRegex, excludePathsRegex, onlyTraversePaths }?: ProjectDiscoveryConfig); process(context: FlowrAnalyzerContext, args: RProjectAnalysisRequest): (RParseRequest | FlowrFile<string>)[]; } /** * flowR's default discovery: walk the project once (pruning noise directories), classify the {@link ProjectKind} * from what the walk sees, then keep only the files that kind needs. `project.discovery.full` restores the greedy * {@link FlowrAnalyzerFullProjectDiscoveryPlugin}, `project.discovery.perKind` overrides the kept set per kind. */ export declare class FlowrAnalyzerDefaultProjectDiscoveryPlugin extends FlowrAnalyzerProjectDiscoveryPlugin { readonly name = "default-project-discovery-plugin"; readonly description = "Detects the project kind and discovers only the files it needs (unless project.discovery.full)."; readonly version: SemVer; process(context: FlowrAnalyzerContext, args: RProjectAnalysisRequest): (RParseRequest | FlowrFile<string>)[]; }