feat: add the semantic version to TSLanguage, and expose an API for retrieving it
This commit is contained in:
parent
f0222107b8
commit
8bb1448a6f
24 changed files with 371 additions and 77 deletions
|
|
@ -1,10 +1,17 @@
|
|||
import { C, INTERNAL, Internal, assertInternal, SIZE_OF_INT, SIZE_OF_SHORT } from './constants';
|
||||
import { LookaheadIterator } from './lookahead_iterator';
|
||||
import { unmarshalLanguageMetadata } from './marshal';
|
||||
import { TRANSFER_BUFFER } from './parser';
|
||||
import { Query } from './query';
|
||||
|
||||
const LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/;
|
||||
|
||||
export class LanguageMetadata {
|
||||
readonly major_version: number;
|
||||
readonly minor_version: number;
|
||||
readonly patch_version: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* An opaque object that defines how to parse a particular language.
|
||||
* The code for each `Language` is generated by the Tree-sitter CLI.
|
||||
|
|
@ -46,7 +53,7 @@ export class Language {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the language.
|
||||
*/
|
||||
|
|
@ -57,11 +64,33 @@ export class Language {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 0.25.0, use {@link Language#abiVersion} instead
|
||||
* Gets the version of the language.
|
||||
*/
|
||||
get version(): number {
|
||||
return C._ts_language_version(this[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ABI version of the language.
|
||||
*/
|
||||
get abiVersion(): number {
|
||||
return C._ts_language_abi_version(this[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata for this language. This information is generated by the
|
||||
* CLI, and relies on the language author providing the correct metadata in
|
||||
* the language's `tree-sitter.json` file.
|
||||
*/
|
||||
get metadata(): LanguageMetadata | null {
|
||||
C._ts_language_metadata(this[0]);
|
||||
const length = C.getValue(TRANSFER_BUFFER, 'i32');
|
||||
const address = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
if (length === 0) return null;
|
||||
return unmarshalLanguageMetadata(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of fields in the language.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue