@cspell/cspell-types
Version:
Types for cspell and cspell-lib
129 lines • 3.66 kB
TypeScript
//#region src/Parser/index.d.ts
type ParserOptions = Record<string, unknown>;
type ParserName = string;
interface Parser {
/** Name of parser */
readonly name: ParserName;
/**
* Parse Method
* @param content - full content of the file
* @param filename - filename
*/
parse(content: string, filename: string): ParseResult;
}
interface ParseResult {
readonly content: string;
readonly filename: string;
readonly parsedTexts: Iterable<ParsedText>;
}
interface ParsedText {
/**
* The text extracted and possibly transformed
*/
readonly text: string;
/**
* The raw text before it has been transformed
*/
readonly rawText?: string | undefined;
/**
* start and end offsets of the text
*/
readonly range: Range;
/**
* The Scope annotation for a segment of text.
* Used by the spell checker to apply spell checking options
* based upon the value of the scope.
*/
readonly scope?: Scope | undefined;
/**
* The source map is used to support text transformations.
*
* See: {@link SourceMap}
*/
readonly map?: SourceMap | undefined;
/**
* Used to delegate parsing the contents of `text` to another parser.
*
*/
readonly delegate?: DelegateInfo | undefined;
}
/**
* A SourceMap is used to map transform a piece of text back to its original text.
* This is necessary in order to report the correct location of a spelling issue.
* An empty source map indicates that it was a 1:1 transformation.
*
* The values in a source map are number pairs (even, odd) relative to the beginning of each
* string segment.
* - even - offset in the source text
* - odd - offset in the transformed text
*
* Offsets start a 0
*
* Example:
*
* - Original text: `Grand Caf\u00e9 Bj\u00f8rvika`
* - Transformed text: `Grand Café Bjørvika`
* - Map: [9, 9, 15, 10, 18, 13, 24, 14]
*
* | offset | original | offset | transformed |
* | ------ | ----------- | ------ | ----------- |
* | 0-9 | `Grand Caf` | 0-9 | `Grand Caf` |
* | 9-15 | `\u00e9` | 9-10 | `é` |
* | 15-18 | ` Bj` | 10-13 | ` Bj` |
* | 18-24 | `\u00f8` | 13-14 | `ø` |
* | 24-29 | `rvika` | 14-19 | `rvika` |
*
* <!--- cspell:ignore Bjørvika rvika --->
*/
type SourceMap = number[];
type Range = readonly [start: number, end: number];
/**
* DelegateInfo is used by a parser to delegate parsing a subsection of a document to
* another parser. The following information is used by the spell checker to match
* the parser.
*/
interface DelegateInfo {
/**
* Proposed virtual file name including the extension.
* Format: `./${source_filename}/${block_number}.${ext}
* Example: `./README.md/1.js`
*/
readonly filename: string;
/**
* The filename of the origin of the virtual file block.
* Example: `./README.md`
*/
readonly originFilename: string;
/**
* Proposed file extension
* Example: `.js`
*/
readonly extension: string;
/**
* Filetype to use
* Example: `javascript`
*/
readonly fileType?: string;
}
/**
* Scope - chain of scope going from local to global
*
* Example:
* ```
* `comment.block.documentation.ts` -> `meta.interface.ts` -> `source.ts`
* ```
*/
interface ScopeChain {
readonly value: string;
readonly parent?: ScopeChain | undefined;
}
/**
* A string representing a scope chain separated by spaces
*
* Example: `comment.block.documentation.ts meta.interface.ts source.ts`
*/
type ScopeString = string;
type Scope = ScopeChain | ScopeString;
//#endregion
export { DelegateInfo, ParseResult, ParsedText, Parser, ParserName, ParserOptions, Range, Scope, ScopeChain, ScopeString, SourceMap };
//# sourceMappingURL=index-CY-3Hv0u.d.ts.map