UNPKG

@jupyter-lsp/jupyterlab-lsp

Version:

Language Server Protocol integration for JupyterLab

84 lines (83 loc) 4.02 kB
import { IExtractedCode, IForeignCodeExtractor } from '@jupyterlab/lsp'; import { replacer } from '../overrides/tokens'; export declare function getIndexOfCaptureGroup(expression: RegExp, matchedString: string, valueOfCapturedGroup: string): number; export declare class RegExpForeignCodeExtractor implements IForeignCodeExtractor { options: RegExpForeignCodeExtractor.IOptions; language: string; globalExpression: RegExp; testExpression: RegExp; expression: RegExp; standalone: boolean; fileExtension: string; cellType: string[]; constructor(options: RegExpForeignCodeExtractor.IOptions); hasForeignCode(code: string): boolean; extractForeignCode(code: string): IExtractedCode[]; } declare namespace RegExpForeignCodeExtractor { interface IOptions { /** * The foreign language. */ language: string; /** * String giving regular expression to test cells for the foreign language presence. * * For example: * - `%%R( (.*))?\n(.*)` will match R cells of rpy2 * - `(.*)'<html>(.*)</html>'(.*)` will match html documents in strings of any language using single ticks */ pattern: string; /** * Array of numbers specifying match groups to be extracted from the regular expression match, * for the use in virtual document of the foreign language. * For the R example this should be `3`. Please not that these are 1-based, as the 0th index is the full match. * If multiple groups are given, those will be concatenated. * * If additional code is needed in between the groups, use `foreignReplacer` in addition to * `foreignCaptureGroups` (but not instead!). * * `foreignCaptureGroups` is required for proper offset calculation and will no longer be optional in 4.0. */ foreignCaptureGroups?: number[]; /** * Function to compose the foreign document code, in case if using a capture group alone is not sufficient; * If specified, `foreign_capture_group` should be specified as well, so that it points to the first occurrence * of the foreign code. When both are specified, `foreignReplacer` takes precedence. * * See: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter */ foreignReplacer?: replacer; /** * @deprecated `extractToForeign` will be removed in 4.0; use `foreign_capture_group` or `foreignReplacer` instead */ extractToForeign?: string | replacer; /** * If arguments from the cell or line magic are to be extracted and prepended before the extracted code, * set extractArguments to a replacer function taking the code and returning the string to be prepended. */ extractArguments?: replacer; /** * Boolean if everything (true, default) or nothing (false) should be kept in the host document. * * For the R example this should be empty if we wish to ignore the cell, * but usually a better option is to retain the foreign code and use language * specific overrides to suppress the magic in a more controlled way, providing * dummy python code to handle cell input/output. * * Setting to false is DEPRECATED as it breaks the edit feature (while it could be fixed, * it would make the code considerably more complex). * * @deprecated `keepInHost` will be removed in 4.0 */ keepInHost?: boolean; /** * Should the foreign code be appended (False) to the previously established virtual document of the same language, * or is it standalone snippet which requires separate connection? */ isStandalone: boolean; fileExtension: string; } } export {};