Skip to content

Commit a58d885

Browse files
authored
API: Add declaration property to IndexInfo. (#4273)
1 parent f0113b7 commit a58d885

8 files changed

Lines changed: 26 additions & 5 deletions

File tree

_packages/native-preview/src/api/async/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ export class Checker {
902902
keyType: this.objectRegistry.getOrCreateType(d.keyType),
903903
valueType: this.objectRegistry.getOrCreateType(d.valueType),
904904
isReadonly: d.isReadonly ?? false,
905+
declaration: d.declaration ? new NodeHandle(d.declaration) : undefined,
905906
}));
906907
}
907908

_packages/native-preview/src/api/async/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { ElementFlags } from "#enums/elementFlags";
33
import type { ObjectFlags } from "#enums/objectFlags";
44
import type { TypeFlags } from "#enums/typeFlags";
55
import type { TypePredicateKind } from "#enums/typePredicateKind";
6-
import type { Symbol } from "./api.ts";
6+
import type {
7+
NodeHandle,
8+
Symbol,
9+
} from "./api.ts";
710

811
/**
912
* A TypeScript type.
@@ -198,6 +201,8 @@ export interface IndexInfo {
198201
readonly valueType: Type;
199202
/** Whether the index signature is readonly */
200203
readonly isReadonly: boolean;
204+
/** The index signature declaration, if any */
205+
readonly declaration?: NodeHandle;
201206
}
202207

203208
/**

_packages/native-preview/src/api/proto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export interface IndexInfoResponse {
184184
keyType: TypeResponse;
185185
valueType: TypeResponse;
186186
isReadonly?: boolean;
187+
declaration?: string;
187188
}
188189

189190
export interface ProfileParams {

_packages/native-preview/src/api/sync/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ export class Checker {
910910
keyType: this.objectRegistry.getOrCreateType(d.keyType),
911911
valueType: this.objectRegistry.getOrCreateType(d.valueType),
912912
isReadonly: d.isReadonly ?? false,
913+
declaration: d.declaration ? new NodeHandle(d.declaration) : undefined,
913914
}));
914915
}
915916

_packages/native-preview/src/api/sync/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import type { ElementFlags } from "#enums/elementFlags";
1111
import type { ObjectFlags } from "#enums/objectFlags";
1212
import type { TypeFlags } from "#enums/typeFlags";
1313
import type { TypePredicateKind } from "#enums/typePredicateKind";
14-
import type { Symbol } from "./api.ts";
14+
import type {
15+
NodeHandle,
16+
Symbol,
17+
} from "./api.ts";
1518

1619
/**
1720
* A TypeScript type.
@@ -206,6 +209,8 @@ export interface IndexInfo {
206209
readonly valueType: Type;
207210
/** Whether the index signature is readonly */
208211
readonly isReadonly: boolean;
212+
/** The index signature declaration, if any */
213+
readonly declaration?: NodeHandle;
209214
}
210215

211216
/**

internal/api/proto.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,10 @@ type TypePredicateResponse struct {
911911

912912
// IndexInfoResponse represents a single index signature.
913913
type IndexInfoResponse struct {
914-
KeyType TypeResponse `json:"keyType"`
915-
ValueType TypeResponse `json:"valueType"`
916-
IsReadonly bool `json:"isReadonly,omitempty"`
914+
KeyType TypeResponse `json:"keyType"`
915+
ValueType TypeResponse `json:"valueType"`
916+
IsReadonly bool `json:"isReadonly,omitempty"`
917+
Declaration NodeHandle `json:"declaration,omitempty"`
917918
}
918919

919920
// SourceFileResponse contains the binary-encoded AST data for a source file.

internal/api/session.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,9 @@ func (s *Session) handleGetIndexInfosOfType(ctx context.Context, params *Checker
19321932
ValueType: *setup.sd.registerType(info.ValueType()),
19331933
IsReadonly: info.IsReadonly(),
19341934
}
1935+
if info.Declaration() != nil {
1936+
results[i].Declaration = setup.sd.nodeHandleFrom(info.Declaration())
1937+
}
19351938
}
19361939

19371940
return results, nil

internal/checker/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,10 @@ func (info *IndexInfo) IsReadonly() bool {
13781378
return info.isReadonly
13791379
}
13801380

1381+
func (info *IndexInfo) Declaration() *ast.Node {
1382+
return info.declaration
1383+
}
1384+
13811385
/**
13821386
* Ternary values are defined such that
13831387
* x & y picks the lesser in the order False < Unknown < Maybe < True, and

0 commit comments

Comments
 (0)