Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 107 additions & 1 deletion _packages/native-preview/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import type {
InterfaceType,
IntersectionType,
IntrinsicType,
JSDocTagInfo,
LiteralType,
NumberLiteralType,
ObjectType,
Expand All @@ -101,7 +102,7 @@ import type {

export { CompletionItemKind, DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, BigIntLiteralType, BooleanLiteralType, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, NumberLiteralType, ObjectType, StringLiteralType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, BigIntLiteralType, BooleanLiteralType, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, JSDocTagInfo, LiteralType, NumberLiteralType, ObjectType, StringLiteralType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";

export class API<FromLSP extends boolean = false> {
Expand Down Expand Up @@ -1055,6 +1056,22 @@ export class Checker {
});
}

async isArrayType(type: Type): Promise<boolean> {
return this.client.apiRequest<boolean>("isArrayType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
}

async isTupleType(type: Type): Promise<boolean> {
return this.client.apiRequest<boolean>("isTupleType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
}

async getReturnTypeOfSignature(signature: Signature): Promise<Type | undefined> {
const data = await this.client.apiRequest<TypeResponse | null>("getReturnTypeOfSignature", {
snapshot: this.snapshotId,
Expand Down Expand Up @@ -1130,6 +1147,87 @@ export class Checker {
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
}

async getBaseConstraintOfType(type: Type): Promise<Type | undefined> {
const data = await this.client.apiRequest<TypeResponse | null>("getBaseConstraintOfType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
}

async getPropertyOfType(type: Type, name: string): Promise<Symbol | undefined> {
const data = await this.client.apiRequest<SymbolResponse | null>("getPropertyOfType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
name,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

async getConstantValue(node: Node): Promise<string | number | undefined> {
const data = await this.client.apiRequest<string | number | null>("getConstantValue", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ?? undefined;
}

async getSignatureFromDeclaration(node: Node): Promise<Signature | undefined> {
const data = await this.client.apiRequest<SignatureResponse | null>("getSignatureFromDeclaration", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ? this.objectRegistry.getOrCreateSignature(data) : undefined;
}

async getExportSpecifierLocalTargetSymbol(node: Node): Promise<Symbol | undefined> {
const data = await this.client.apiRequest<SymbolResponse | null>("getExportSpecifierLocalTargetSymbol", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

async getAliasedSymbol(symbol: Symbol): Promise<Symbol | undefined> {
const data = await this.client.apiRequest<SymbolResponse | null>("getAliasedSymbol", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

async getExportsOfModule(symbol: Symbol): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest<SymbolResponse[] | null>("getExportsOfModule", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

async getJsDocTagsOfSymbol(symbol: Symbol): Promise<readonly JSDocTagInfo[]> {
const data = await this.client.apiRequest<JSDocTagInfo[] | null>("getJsDocTags", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ?? [];
}

async getDocumentationCommentOfSymbol(symbol: Symbol): Promise<string> {
return this.client.apiRequest<string>("getDocumentationComment", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
}

async getTypeArguments(type: Type): Promise<readonly Type[]> {
const data = await this.client.apiRequest<TypeResponse[] | null>("getTypeArguments", {
snapshot: this.snapshotId,
Expand Down Expand Up @@ -1248,6 +1346,14 @@ export class Symbol {
if (!this.exportSymbol) return this;
return this.objectRegistry.fetchSymbol(this, "getExportSymbolOfSymbol", this.exportSymbol);
}

async getJsDocTags(checker: Checker): Promise<readonly JSDocTagInfo[]> {
return checker.getJsDocTagsOfSymbol(this);
}

async getDocumentationComment(checker: Checker): Promise<string> {
return checker.getDocumentationCommentOfSymbol(this);
}
}

class TypeObject implements Type {
Expand Down
10 changes: 10 additions & 0 deletions _packages/native-preview/src/api/async/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ export interface IndexInfo {
readonly declaration?: NodeHandle;
}

/**
* A single JSDoc tag attached to a symbol — e.g. `@param`, `@returns`.
*/
export interface JSDocTagInfo {
/** The tag name, without the leading `@` — e.g. `"param"`. */
readonly name: string;
/** The rendered tag text, if any — e.g. `"a the first number"` for `@param a the first number`. */
readonly text?: string;
}

export interface CompletionEntryLabelDetails {
detail?: string;
description?: string;
Expand Down
108 changes: 107 additions & 1 deletion _packages/native-preview/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import type {
InterfaceType,
IntersectionType,
IntrinsicType,
JSDocTagInfo,
LiteralType,
NumberLiteralType,
ObjectType,
Expand All @@ -109,7 +110,7 @@ import type {

export { CompletionItemKind, DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, BigIntLiteralType, BooleanLiteralType, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, NumberLiteralType, ObjectType, StringLiteralType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, BigIntLiteralType, BooleanLiteralType, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, JSDocTagInfo, LiteralType, NumberLiteralType, ObjectType, StringLiteralType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";

export class API<FromLSP extends boolean = false> {
Expand Down Expand Up @@ -1063,6 +1064,22 @@ export class Checker {
});
}

isArrayType(type: Type): boolean {
return this.client.apiRequest<boolean>("isArrayType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
}

isTupleType(type: Type): boolean {
return this.client.apiRequest<boolean>("isTupleType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
}

getReturnTypeOfSignature(signature: Signature): Type | undefined {
const data = this.client.apiRequest<TypeResponse | null>("getReturnTypeOfSignature", {
snapshot: this.snapshotId,
Expand Down Expand Up @@ -1138,6 +1155,87 @@ export class Checker {
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
}

getBaseConstraintOfType(type: Type): Type | undefined {
const data = this.client.apiRequest<TypeResponse | null>("getBaseConstraintOfType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
});
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
}

getPropertyOfType(type: Type, name: string): Symbol | undefined {
const data = this.client.apiRequest<SymbolResponse | null>("getPropertyOfType", {
snapshot: this.snapshotId,
project: this.projectId,
type: type.id,
name,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

getConstantValue(node: Node): string | number | undefined {
const data = this.client.apiRequest<string | number | null>("getConstantValue", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ?? undefined;
}

getSignatureFromDeclaration(node: Node): Signature | undefined {
const data = this.client.apiRequest<SignatureResponse | null>("getSignatureFromDeclaration", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ? this.objectRegistry.getOrCreateSignature(data) : undefined;
}

getExportSpecifierLocalTargetSymbol(node: Node): Symbol | undefined {
const data = this.client.apiRequest<SymbolResponse | null>("getExportSpecifierLocalTargetSymbol", {
snapshot: this.snapshotId,
project: this.projectId,
location: getNodeId(node),
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

getAliasedSymbol(symbol: Symbol): Symbol | undefined {
const data = this.client.apiRequest<SymbolResponse | null>("getAliasedSymbol", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

getExportsOfModule(symbol: Symbol): readonly Symbol[] {
const data = this.client.apiRequest<SymbolResponse[] | null>("getExportsOfModule", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

getJsDocTagsOfSymbol(symbol: Symbol): readonly JSDocTagInfo[] {
const data = this.client.apiRequest<JSDocTagInfo[] | null>("getJsDocTags", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
return data ?? [];
}

getDocumentationCommentOfSymbol(symbol: Symbol): string {
return this.client.apiRequest<string>("getDocumentationComment", {
snapshot: this.snapshotId,
project: this.projectId,
symbol: symbol.id,
});
}

getTypeArguments(type: Type): readonly Type[] {
const data = this.client.apiRequest<TypeResponse[] | null>("getTypeArguments", {
snapshot: this.snapshotId,
Expand Down Expand Up @@ -1256,6 +1354,14 @@ export class Symbol {
if (!this.exportSymbol) return this;
return this.objectRegistry.fetchSymbol(this, "getExportSymbolOfSymbol", this.exportSymbol);
}

getJsDocTags(checker: Checker): readonly JSDocTagInfo[] {
return checker.getJsDocTagsOfSymbol(this);
}

getDocumentationComment(checker: Checker): string {
return checker.getDocumentationCommentOfSymbol(this);
}
}

class TypeObject implements Type {
Expand Down
10 changes: 10 additions & 0 deletions _packages/native-preview/src/api/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ export interface IndexInfo {
readonly declaration?: NodeHandle;
}

/**
* A single JSDoc tag attached to a symbol — e.g. `@param`, `@returns`.
*/
export interface JSDocTagInfo {
/** The tag name, without the leading `@` — e.g. `"param"`. */
readonly name: string;
/** The rendered tag text, if any — e.g. `"a the first number"` for `@param a the first number`. */
readonly text?: string;
}

export interface CompletionEntryLabelDetails {
detail?: string;
description?: string;
Expand Down
Loading