Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
14 changes: 11 additions & 3 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import {
type RootedFilePath,
type SourceFile,
type StringLiteralLikeNode,
symbolName,
type SyntaxKind,
type TypeNode,
type TypeParameterDeclaration,
unescapeLeadingUnderscores,
} from "../../ast/index.ts";
import { assertNever } from "../../internal/utils.ts";
import {
Expand Down Expand Up @@ -103,6 +103,7 @@ import type {
DocumentPosition,
EmitOutputResponse as ProtocolEmitOutputResponse,
FileNotifications,
FormatCodeSettings,
ImportAdderAction,
InferredProjectId,
IntrinsicTypeMethod,
Expand Down Expand Up @@ -237,6 +238,7 @@ export type {
EmitOutputFile,
EmitResult,
FileNotifications,
FormatCodeSettings,
FormatDiagnosticsHost,
FreshableType,
GenericType,
Expand Down Expand Up @@ -525,6 +527,12 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
return orchestrator;
}

/** Gets the compiler's default formatting settings, independent of snapshot preferences. */
async getDefaultFormatCodeSettings(): Promise<FormatCodeSettings> {
await this.ensureInitialized();
return this.client.apiRequest("getDefaultFormatCodeSettings", null);
}

/** Returns configured type roots or ancestor node_modules/@types candidates, without checking directory existence. */
async getEffectiveTypeRoots(compilerOptions: RawCompilerOptions): Promise<readonly RootedDirectoryPath[]> {
await this.ensureInitialized();
Expand Down Expand Up @@ -3659,7 +3667,7 @@ export class Symbol {
}
/** The escaped (`__String`) name, used as the key in member/export tables. */
readonly escapedName: __String;
/** The display name (escaped underscores removed). */
/** The display name, including the source spelling of private identifiers. */
readonly name: string;
readonly flags: SymbolFlags;
readonly checkFlags: CheckFlags;
Expand All @@ -3681,7 +3689,7 @@ export class Symbol {
this.reference = data.reference;

this.escapedName = data.name as __String;
this.name = unescapeLeadingUnderscores(data.name as __String);
this.name = symbolName(this);
this.flags = data.flags;
this.checkFlags = data.checkFlags ?? 0;
this.declarationHandles = data.declarations;
Expand Down
6 changes: 6 additions & 0 deletions packages/typescript/src/api/node/node.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
getTokenPosOfNode,
isJSDoc,
type JSDoc,
type Modifier,
ModifierFlags,
type Node,
type NodeArray,
type SourceFile,
SyntaxKind,
} from "../../ast/index.ts";
import { getModifiers } from "../../ast/modifiers.ts";
import {
modifierToFlag,
NODE_CHILD_MASK,
Expand Down Expand Up @@ -963,6 +965,10 @@ export class RemoteNode extends RemoteNodeBase implements Node {

// ═══ Generated extended data property getters ═══

getModifiers(): readonly Modifier[] | undefined {
return getModifiers(this as unknown as Node);
}

// ═══ Other property getters ═══

get flags(): number {
Expand Down
10 changes: 8 additions & 2 deletions packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import type {
CompilerOptions,
PluginImport,
} from "./compilerOptions.generated.ts";
import type { UserPreferences } from "./userPreferences.generated.ts";
import type {
FormatCodeSettings,
UserPreferences,
} from "./userPreferences.generated.ts";

export { CaseSensitivity } from "../../enums/caseSensitivity.js";
export { JsxEmit } from "../../enums/jsxEmit.js";
Expand All @@ -33,7 +36,7 @@ export { SymbolOwnerKind } from "../../enums/symbolOwnerKind.js";
export type { PathKey, RootedDirectoryPath, RootedFilePath, RootedPath } from "../ast/index.ts";
export type { CompilerOptions, PluginImport } from "./compilerOptions.generated.ts";
export * from "./compilerOptions.generated.ts";
export type { UserPreferences } from "./userPreferences.generated.ts";
export type { FormatCodeSettings, UserPreferences } from "./userPreferences.generated.ts";

export type APIMethod<TParams, TResult> = { params: TParams; result: TResult; };

Expand All @@ -45,6 +48,7 @@ export interface APIMethodInfo {
getSymbolOfDeclaration: APIMethod<GetSymbolOfDeclarationParams, SymbolResponse>;
batchRequests: APIMethod<BatchRequestsParams, BatchRequestsResponse>;
initialize: APIMethod<null, InitializeResponse>;
getDefaultFormatCodeSettings: APIMethod<null, FormatCodeSettings>;
createSnapshot: APIMethod<CreateSnapshotParams, CreateSnapshotResponse>;
updateSnapshot: APIMethod<UpdateSnapshotParams, CreateSnapshotResponse>;
getCurrentLanguageServerSnapshot: APIMethod<GetCurrentLanguageServerSnapshotParams, CreateSnapshotResponse>;
Expand Down Expand Up @@ -1366,6 +1370,7 @@ export interface BatchRequest {
| "getDeclarationDiagnostics"
| "getDeclarationEmit"
| "getDeclaredTypeOfSymbol"
| "getDefaultFormatCodeSettings"
| "getDefaultFromTypeParameter"
| "getDefaultProjectForFile"
| "getDocumentationComment"
Expand Down Expand Up @@ -1579,6 +1584,7 @@ export interface BatchResponse {
| "getDeclarationDiagnostics"
| "getDeclarationEmit"
| "getDeclaredTypeOfSymbol"
| "getDefaultFormatCodeSettings"
| "getDefaultFromTypeParameter"
| "getDefaultProjectForFile"
| "getDocumentationComment"
Expand Down
28 changes: 25 additions & 3 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ import {
type RootedFilePath,
type SourceFile,
type StringLiteralLikeNode,
symbolName,
type SyntaxKind,
type TypeNode,
type TypeParameterDeclaration,
unescapeLeadingUnderscores,
} from "../../ast/index.ts";
import { assertNever } from "../../internal/utils.ts";
import {
Expand Down Expand Up @@ -122,6 +122,7 @@ import type {
DocumentPosition,
EmitOutputResponse as ProtocolEmitOutputResponse,
FileNotifications,
FormatCodeSettings,
ImportAdderAction,
InferredProjectId,
IntrinsicTypeMethod,
Expand Down Expand Up @@ -255,6 +256,7 @@ export type {
EmitOutputFile,
EmitResult,
FileNotifications,
FormatCodeSettings,
FormatDiagnosticsHost,
FreshableType,
GenericType,
Expand Down Expand Up @@ -652,6 +654,26 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
);
}

/** Gets the compiler's default formatting settings, independent of snapshot preferences. */
get getDefaultFormatCodeSettings(): {
(): FormatCodeSettings;
gen(): Generator<ProtocolRequest, FormatCodeSettings, ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"getDefaultFormatCodeSettings",
function (): FormatCodeSettings {
owner.ensureInitialized();
return owner.client.apiRequest("getDefaultFormatCodeSettings", null);
},
function* (): Generator<ProtocolRequest, FormatCodeSettings, ProtocolResponse["result"]> {
yield* owner.ensureInitialized.gen();
return yield* apiRequest("getDefaultFormatCodeSettings", null);
},
);
}

/** Returns configured type roots or ancestor node_modules/@types candidates, without checking directory existence. */
get getEffectiveTypeRoots(): {
(compilerOptions: RawCompilerOptions): readonly RootedDirectoryPath[];
Expand Down Expand Up @@ -7650,7 +7672,7 @@ export class Symbol {
}
/** The escaped (`__String`) name, used as the key in member/export tables. */
readonly escapedName: __String;
/** The display name (escaped underscores removed). */
/** The display name, including the source spelling of private identifiers. */
readonly name: string;
readonly flags: SymbolFlags;
readonly checkFlags: CheckFlags;
Expand All @@ -7672,7 +7694,7 @@ export class Symbol {
this.reference = data.reference;

this.escapedName = data.name as __String;
this.name = unescapeLeadingUnderscores(data.name as __String);
this.name = symbolName(this);
this.flags = data.flags;
this.checkFlags = data.checkFlags ?? 0;
this.declarationHandles = data.declarations;
Expand Down
60 changes: 60 additions & 0 deletions packages/typescript/src/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,53 @@ import type { NodeFlags } from "../../enums/nodeFlags.js";
import type { ScriptKind } from "../../enums/scriptKind.js";
import { SyntaxKind } from "../../enums/syntaxKind.js";
import type {
ArrowFunction,
AssertionExpression,
BindingElement,
BindingPattern,
CallExpression,
CaseClause,
ClassDeclaration,
ClassExpression,
ComputedPropertyName,
ConstructorDeclaration,
ConstructorTypeNode,
Decorator,
DoStatement,
ElementAccessExpression,
EndOfFile,
EntityName,
EnumDeclaration,
EnumMember,
ExportAssignment,
ExportDeclaration,
ExportSpecifier,
Expression,
ExpressionStatement,
ForInStatement,
ForOfStatement,
ForStatement,
FunctionDeclaration,
FunctionExpression,
GetAccessorDeclaration,
Identifier,
IfStatement,
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
ImportSpecifier,
IndexSignatureDeclaration,
InterfaceDeclaration,
JSDoc,
JsxAttribute,
JsxExpression,
JsxSpreadAttribute,
KeywordSyntaxKind,
MethodDeclaration,
MethodSignatureDeclaration,
Modifier,
ModifierSyntaxKind,
ModuleDeclaration,
NamedExports,
NamedImports,
NamespaceExport,
Expand All @@ -51,6 +68,7 @@ import type {
PunctuationSyntaxKind,
ReturnStatement,
SatisfiesExpression,
SetAccessorDeclaration,
ShorthandPropertyAssignment,
SpreadAssignment,
Statement,
Expand All @@ -59,7 +77,10 @@ import type {
ThisExpression,
ThrowStatement,
Token,
TypeAliasDeclaration,
TypeParameterDeclaration,
VariableDeclaration,
VariableStatement,
WhileStatement,
WithStatement,
} from "./ast.generated.ts";
Expand All @@ -71,6 +92,43 @@ export { TokenFlags } from "../../enums/tokenFlags.js";
export * from "./ast.generated.ts";
export * as factory from "./factory.generated.ts";

export type CanHaveDecorators =
| ParameterDeclaration
| PropertyDeclaration
| MethodDeclaration
| GetAccessorDeclaration
| SetAccessorDeclaration
| ClassExpression
| ClassDeclaration;

export type CanHaveModifiers =
| TypeParameterDeclaration
| ParameterDeclaration
| PropertySignatureDeclaration
| PropertyDeclaration
| MethodSignatureDeclaration
| MethodDeclaration
| ConstructorDeclaration
| GetAccessorDeclaration
| SetAccessorDeclaration
| IndexSignatureDeclaration
| ConstructorTypeNode
| FunctionExpression
| ArrowFunction
| ClassExpression
| VariableStatement
| FunctionDeclaration
| ClassDeclaration
| InterfaceDeclaration
| TypeAliasDeclaration
| EnumDeclaration
| ModuleDeclaration
| ImportEqualsDeclaration
| ImportDeclaration
| (Omit<ImportDeclaration, "kind"> & { readonly kind: SyntaxKind.JSImportDeclaration; })
| ExportAssignment
| ExportDeclaration;

declare const autoAccessorBrand: unique symbol;
export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration {
readonly [autoAccessorBrand]: void;
Expand Down Expand Up @@ -222,6 +280,8 @@ export interface Node extends ReadonlyTextRange {
getChildren(sourceFile?: SourceFile): readonly Node[];
getFirstToken(sourceFile?: SourceFile): Node | undefined;
getLastToken(sourceFile?: SourceFile): Node | undefined;
/** Gets syntactic modifiers without decorators, or `undefined` if there are none. */
getModifiers(): readonly Modifier[] | undefined;
}

export interface FileReference extends TextRange {
Expand Down
10 changes: 9 additions & 1 deletion packages/typescript/src/ast/factory.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ import type {
MethodSignatureDeclaration,
MinusToken,
MissingDeclaration,
Modifier,
ModifierLike,
ModuleBlock,
ModuleBody,
Expand Down Expand Up @@ -266,7 +267,10 @@ import {
getLastToken,
getTokenPosOfNode,
} from "./astnav.ts";
import { modifierToFlag } from "./modifiers.ts";
import {
getModifiers,
modifierToFlag,
} from "./modifiers.ts";
import { cloneSourceFileData } from "./utils.ts";
import {
forEachChildOfJSDocParameterTag,
Expand Down Expand Up @@ -700,6 +704,10 @@ export class NodeObject {
return flags;
}

getModifiers(): readonly Modifier[] | undefined {
return getModifiers(this as unknown as Node);
}

forEachChild<T>(visitor: (node: Node) => T, visitArray?: (nodes: NodeArray<Node>) => T): T | undefined {
const fn = forEachChildTable[this.kind];
return fn ? fn(this._data, visitor, visitArray) : undefined;
Expand Down
Loading
Loading