@zzzen/pyright-internal 1.2.0-dev.20260628 → 1.2.0-dev.20260712

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/analyzer/binder.js +51 -5
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +12 -2
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/dataClasses.js +7 -0
  6. package/dist/analyzer/dataClasses.js.map +1 -1
  7. package/dist/analyzer/typeUtils.js +10 -4
  8. package/dist/analyzer/typeUtils.js.map +1 -1
  9. package/dist/localization/localize.d.ts +3 -0
  10. package/dist/localization/localize.js +1 -0
  11. package/dist/localization/localize.js.map +1 -1
  12. package/dist/localization/package.nls.en-us.json +1 -0
  13. package/dist/tests/fourslash/completions.qualname.fourslash.d.ts +1 -0
  14. package/dist/tests/fourslash/completions.qualname.fourslash.js +34 -0
  15. package/dist/tests/fourslash/completions.qualname.fourslash.js.map +1 -0
  16. package/dist/tests/fourslash/import.multipartModuleClassShadow.fourslash.d.ts +1 -0
  17. package/dist/tests/fourslash/import.multipartModuleClassShadow.fourslash.js +39 -0
  18. package/dist/tests/fourslash/import.multipartModuleClassShadow.fourslash.js.map +1 -0
  19. package/dist/tests/typeEvaluator3.test.js +1 -1
  20. package/dist/tests/typeEvaluator4.test.js +1 -1
  21. package/dist/tests/typeEvaluator6.test.js +20 -0
  22. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  23. package/dist/tests/typeServer/inProcTypeServerTestUtils.d.ts +39 -0
  24. package/dist/tests/typeServer/inProcTypeServerTestUtils.js +366 -0
  25. package/dist/tests/typeServer/inProcTypeServerTestUtils.js.map +1 -0
  26. package/dist/tests/typeServer/notebook.typeServer.test.d.ts +1 -0
  27. package/dist/tests/typeServer/notebook.typeServer.test.js +315 -0
  28. package/dist/tests/typeServer/notebook.typeServer.test.js.map +1 -0
  29. package/dist/tests/typeServer/typeServer.inProc.test.d.ts +1 -0
  30. package/dist/tests/typeServer/typeServer.inProc.test.js +234 -0
  31. package/dist/tests/typeServer/typeServer.inProc.test.js.map +1 -0
  32. package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.d.ts +1 -0
  33. package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js +298 -0
  34. package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js.map +1 -0
  35. package/dist/typeServer/cancellation.d.ts +5 -0
  36. package/dist/typeServer/cancellation.js +14 -0
  37. package/dist/typeServer/cancellation.js.map +1 -0
  38. package/dist/typeServer/diagnosticUtils.d.ts +4 -0
  39. package/dist/typeServer/diagnosticUtils.js +71 -0
  40. package/dist/typeServer/diagnosticUtils.js.map +1 -0
  41. package/dist/typeServer/enums.d.ts +14 -0
  42. package/dist/typeServer/enums.js +524 -0
  43. package/dist/typeServer/enums.js.map +1 -0
  44. package/dist/typeServer/eventEmitter.d.ts +12 -0
  45. package/dist/typeServer/eventEmitter.js +32 -0
  46. package/dist/typeServer/eventEmitter.js.map +1 -0
  47. package/dist/typeServer/nodeMain.d.ts +1 -0
  48. package/dist/typeServer/nodeMain.js +65 -0
  49. package/dist/typeServer/nodeMain.js.map +1 -0
  50. package/dist/typeServer/notebookCellChain.d.ts +34 -0
  51. package/dist/typeServer/notebookCellChain.js +182 -0
  52. package/dist/typeServer/notebookCellChain.js.map +1 -0
  53. package/dist/typeServer/notebookDocumentHandler.d.ts +23 -0
  54. package/dist/typeServer/notebookDocumentHandler.js +158 -0
  55. package/dist/typeServer/notebookDocumentHandler.js.map +1 -0
  56. package/dist/typeServer/notebookUriMapper.d.ts +39 -0
  57. package/dist/typeServer/notebookUriMapper.js +164 -0
  58. package/dist/typeServer/notebookUriMapper.js.map +1 -0
  59. package/dist/typeServer/profilingStub.d.ts +10 -0
  60. package/dist/typeServer/profilingStub.js +12 -0
  61. package/dist/typeServer/profilingStub.js.map +1 -0
  62. package/dist/typeServer/programTypes.d.ts +136 -0
  63. package/dist/typeServer/programTypes.js +3 -0
  64. package/dist/typeServer/programTypes.js.map +1 -0
  65. package/dist/typeServer/programWrapper.d.ts +134 -0
  66. package/dist/typeServer/programWrapper.js +731 -0
  67. package/dist/typeServer/programWrapper.js.map +1 -0
  68. package/dist/typeServer/protocol/tspSupplemental.d.ts +43 -0
  69. package/dist/typeServer/protocol/tspSupplemental.js +48 -0
  70. package/dist/typeServer/protocol/tspSupplemental.js.map +1 -0
  71. package/dist/typeServer/protocol/typeServerProtocol.d.ts +1102 -0
  72. package/dist/typeServer/protocol/typeServerProtocol.js +290 -0
  73. package/dist/typeServer/protocol/typeServerProtocol.js.map +1 -0
  74. package/dist/typeServer/server.d.ts +54 -0
  75. package/dist/typeServer/server.js +620 -0
  76. package/dist/typeServer/server.js.map +1 -0
  77. package/dist/typeServer/serverUtils.d.ts +4 -0
  78. package/dist/typeServer/serverUtils.js +21 -0
  79. package/dist/typeServer/serverUtils.js.map +1 -0
  80. package/dist/typeServer/stubGenerator.d.ts +42 -0
  81. package/dist/typeServer/stubGenerator.js +895 -0
  82. package/dist/typeServer/stubGenerator.js.map +1 -0
  83. package/dist/typeServer/typeCache.d.ts +31 -0
  84. package/dist/typeServer/typeCache.js +54 -0
  85. package/dist/typeServer/typeCache.js.map +1 -0
  86. package/dist/typeServer/typeEvalUtils.d.ts +13 -0
  87. package/dist/typeServer/typeEvalUtils.js +83 -0
  88. package/dist/typeServer/typeEvalUtils.js.map +1 -0
  89. package/dist/typeServer/typeGuards.d.ts +3 -0
  90. package/dist/typeServer/typeGuards.js +55 -0
  91. package/dist/typeServer/typeGuards.js.map +1 -0
  92. package/dist/typeServer/typeServerConversionTypes.d.ts +39 -0
  93. package/dist/typeServer/typeServerConversionTypes.js +448 -0
  94. package/dist/typeServer/typeServerConversionTypes.js.map +1 -0
  95. package/dist/typeServer/typeServerConversionUtils.d.ts +35 -0
  96. package/dist/typeServer/typeServerConversionUtils.js +524 -0
  97. package/dist/typeServer/typeServerConversionUtils.js.map +1 -0
  98. package/dist/typeServer/typeServerEvaluator.d.ts +16 -0
  99. package/dist/typeServer/typeServerEvaluator.js +36 -0
  100. package/dist/typeServer/typeServerEvaluator.js.map +1 -0
  101. package/dist/typeServer/typeServerFileSystem.d.ts +47 -0
  102. package/dist/typeServer/typeServerFileSystem.js +129 -0
  103. package/dist/typeServer/typeServerFileSystem.js.map +1 -0
  104. package/dist/typeServer/typeServerProtocolUtils.d.ts +2 -0
  105. package/dist/typeServer/typeServerProtocolUtils.js +7 -0
  106. package/dist/typeServer/typeServerProtocolUtils.js.map +1 -0
  107. package/dist/typeServer/typeServerServiceKeys.d.ts +7 -0
  108. package/dist/typeServer/typeServerServiceKeys.js +20 -0
  109. package/dist/typeServer/typeServerServiceKeys.js.map +1 -0
  110. package/dist/typeServer/typeUtils.d.ts +4 -0
  111. package/dist/typeServer/typeUtils.js +31 -0
  112. package/dist/typeServer/typeUtils.js.map +1 -0
  113. package/dist/typeServer/virtualFileOverlayFileSystem.d.ts +87 -0
  114. package/dist/typeServer/virtualFileOverlayFileSystem.js +181 -0
  115. package/dist/typeServer/virtualFileOverlayFileSystem.js.map +1 -0
  116. package/package.json +1 -1
@@ -0,0 +1,1102 @@
1
+ import { MessageDirection, ProtocolNotificationType, ProtocolRequestType, ProtocolRequestType0, Range } from 'vscode-languageserver-protocol';
2
+ export declare namespace TypeServerProtocol {
3
+ const ReturnSymbolName = "__return__";
4
+ const InvalidHandle = -1;
5
+ /**
6
+ * Represents a location in source code (a node in the AST).
7
+ * Used to point to specific declarations, expressions, or statements in Python source files.
8
+ *
9
+ * Used for:
10
+ * - Pointing to where a type is declared
11
+ * - Identifying the location of expressions for type inference
12
+ * - Error reporting and diagnostics
13
+ * - Linking types back to their source definitions
14
+ *
15
+ * Examples:
16
+ * - For `def foo():`, the node points to the function declaration
17
+ * - For a variable `x = 42`, the node points to the assignment
18
+ * - For default parameter values in functions
19
+ */
20
+ interface Node {
21
+ uri: string;
22
+ range: Range;
23
+ }
24
+ /**
25
+ * Version of the type server protocol.
26
+ * Used for protocol negotiation between client and server to ensure compatibility.
27
+ *
28
+ * The version follows semantic versioning (semver), with the usual 0.x caveat:
29
+ * - Major version changes indicate breaking changes to the protocol
30
+ * - While the protocol is 0.x, minor version changes may indicate breaking changes
31
+ * - Patch version changes remain backward compatible
32
+ *
33
+ * Clients should check the server's supported version before making requests.
34
+ */
35
+ enum TypeServerVersion {
36
+ v0_1_0 = "0.1.0",// Initial protocol version
37
+ v0_2_0 = "0.2.0",// Added new request types and fields
38
+ v0_3_0 = "0.3.0",// Switch to more complex types
39
+ v0_4_0 = "0.4.0",// Switch to Type union and using stubs
40
+ current = "0.4.1"
41
+ }
42
+ /**
43
+ * Built-in transport kinds supported by the multi-connection protocol.
44
+ *
45
+ * The main connection may use any transport the server supports, but extra
46
+ * dynamically-opened connections are negotiated separately and are currently
47
+ * limited to local IPC.
48
+ */
49
+ enum ConnectionTransportKind {
50
+ Ipc = "ipc"
51
+ }
52
+ /**
53
+ * Capability shape exchanged via the LSP initialize request/response under
54
+ * `capabilities.experimental.typeServerMultiConnection`.
55
+ */
56
+ interface TypeServerMultiConnectionCapability {
57
+ supportedTransports: ConnectionTransportKind[];
58
+ }
59
+ /**
60
+ * Main-connection-only control request used to open or close extra read-only
61
+ * TSP channels after LSP initialization has completed.
62
+ */
63
+ interface ConnectionRequestParams {
64
+ type: 'open' | 'close';
65
+ kind: ConnectionTransportKind;
66
+ args?: string[];
67
+ }
68
+ interface ConnectionRequestResult {
69
+ success: boolean;
70
+ message?: string;
71
+ }
72
+ const enum TypeFlags {
73
+ None = 0,
74
+ Instantiable = 1,// Indicates if the type can be instantiated.
75
+ Instance = 2,// Indicates if the type represents an instance (as opposed to a class or type itself).
76
+ Callable = 4,// Indicates if an instance of the type can be called like a function. (It has a `__call__` method).
77
+ Literal = 8,// Indicates if the instance is a literal (like `42`, `"hello"`, etc.).
78
+ Interface = 16,// Indicates if the type is an interface (a type that defines a set of methods and properties). In Python this would be a Protocol.
79
+ Generic = 32,// Indicates if the type is a generic type (a type that can be parameterized with other types).
80
+ FromAlias = 64,// Indicates if the type came from an alias (a type that refers to another type).
81
+ Unpacked = 128,// Indicates if the type is unpacked (used with TypeVarTuple).
82
+ Optional = 256,// Indicates if the type is optional (used with Tuple type arguments).
83
+ Unbound = 512
84
+ }
85
+ /**
86
+ * Represents a Python module name, handling both absolute and relative imports.
87
+ *
88
+ * Used for:
89
+ * - Import statement resolution
90
+ * - Tracking module dependencies
91
+ * - Resolving relative imports (from . import, from .. import)
92
+ *
93
+ * Examples:
94
+ * - `import os.path`: leadingDots=0, nameParts=['os', 'path']
95
+ * - `from . import utils`: leadingDots=1, nameParts=['utils']
96
+ * - `from ...parent import module`: leadingDots=3, nameParts=['parent', 'module']
97
+ * - `import mymodule`: leadingDots=0, nameParts=['mymodule']
98
+ */
99
+ interface ModuleName {
100
+ leadingDots: number;
101
+ nameParts: string[];
102
+ }
103
+ const enum DeclarationCategory {
104
+ Intrinsic = 0,// An intrinsic refers to a symbol that has no actual declaration in the source code, such as built-in types or functions. One such example is a '__class__' declaration.
105
+ Variable = 1,// A variable is a named storage location that can hold a value.
106
+ Param = 2,// A parameter is a variable that is passed to a function or method.
107
+ TypeParam = 3,// This is for PEP 695 type parameters.
108
+ TypeAlias = 4,// This is for PEP 695 type aliases.
109
+ Function = 5,// A function is any construct that begins with the `def` keyword and has a body, which can be called with arguments.
110
+ Class = 6,// A class is any construct that begins with the `class` keyword and has a body, which can be instantiated.
111
+ Import = 7
112
+ }
113
+ /**
114
+ * Options for customizing import resolution behavior.
115
+ * Controls how the type server resolves import statements and accesses imported symbols.
116
+ *
117
+ * Used for:
118
+ * - Fine-tuning import resolution during type checking
119
+ * - Controlling access to private/hidden module members
120
+ * - Optimizing resolution by skipping file checks
121
+ *
122
+ * TODO: See if we can remove this as these are pretty specific to Pyright at the moment.
123
+ *
124
+ * Examples:
125
+ * ```python
126
+ * # resolveLocalNames affects whether local assignments are resolved:
127
+ * from module import name
128
+ * name = something_else # Does 'name' refer to import or local assignment?
129
+ *
130
+ * # allowExternallyHiddenAccess affects access to _private names:
131
+ * from module import _internal_function # Normally hidden from external access
132
+ * ```
133
+ */
134
+ interface ResolveImportOptions {
135
+ resolveLocalNames?: boolean;
136
+ allowExternallyHiddenAccess?: boolean;
137
+ skipFileNeededCheck?: boolean;
138
+ }
139
+ /**
140
+ * Parameters for the ResolveImportRequest.
141
+ * Provides the context needed to resolve a Python import statement to its file location.
142
+ *
143
+ * Used when:
144
+ * - Resolving `import` or `from...import` statements
145
+ * - Finding the file that contains an imported module
146
+ * - Navigating to imported symbols
147
+ *
148
+ * Examples:
149
+ * ```python
150
+ * # In file.py:
151
+ * from os.path import join # sourceUri = file.py, moduleDescriptor = os.path
152
+ * import mymodule # sourceUri = file.py, moduleDescriptor = mymodule
153
+ * from . import utils # sourceUri = file.py, moduleDescriptor = .utils (relative)
154
+ * ```
155
+ */
156
+ interface ResolveImportParams {
157
+ sourceUri: string;
158
+ moduleDescriptor: ModuleName;
159
+ snapshot: number;
160
+ }
161
+ /**
162
+ * Parameters for the GetPythonSearchPathsRequest.
163
+ * Requests the list of directories that Python searches for modules and packages.
164
+ *
165
+ * The search paths include:
166
+ * - Standard library directories
167
+ * - Site-packages directories (third-party packages)
168
+ * - Virtual environment paths (if active)
169
+ * - Project-specific paths (PYTHONPATH, src directories)
170
+ *
171
+ * Used for:
172
+ * - Resolving import statements to find module files
173
+ * - Auto-import suggestions
174
+ * - Determining which packages are available
175
+ *
176
+ * Example search paths:
177
+ * ```
178
+ * [
179
+ * "/usr/lib/python3.11", # Standard library
180
+ * "/venv/lib/python3.11/site-packages", # Virtual env packages
181
+ * "/project/src" # Project source
182
+ * ]
183
+ * ```
184
+ */
185
+ interface GetPythonSearchPathsParams {
186
+ fromUri: string;
187
+ snapshot: number;
188
+ }
189
+ /**
190
+ * Represents specialized (concrete) types for a generic function's parameters and return type.
191
+ * Used when generic type parameters are substituted with actual types.
192
+ *
193
+ * Fields:
194
+ * - parameterTypes: Concrete types for each parameter after type variable substitution
195
+ * - parameterDefaultTypes: Specialized types for default values (if different from declared)
196
+ * - returnType: Specialized return type after type variable substitution
197
+ *
198
+ * Examples:
199
+ * ```python
200
+ * # Generic function
201
+ * def identity[T](x: T) -> T:
202
+ * return x
203
+ *
204
+ * # When called as identity[int](42):
205
+ * # - parameterTypes = [int] (T substituted with int)
206
+ * # - returnType = int (T substituted with int)
207
+ *
208
+ * # For list.append bound to list[str]:
209
+ * # - parameterTypes = [str] (specialized from generic T)
210
+ * ```
211
+ */
212
+ interface SpecializedFunctionTypes {
213
+ parameterTypes: Type[];
214
+ parameterDefaultTypes: (Type | undefined)[] | undefined;
215
+ returnType: Type | undefined;
216
+ }
217
+ /**
218
+ * Represents a literal value from an Enum.
219
+ * Used to track specific enum members as literal types.
220
+ *
221
+ * Fields:
222
+ * - className: Name of the enum class
223
+ * - itemName: Name of the specific enum member
224
+ * - itemType: Type of the enum member's value
225
+ *
226
+ * Examples:
227
+ * ```python
228
+ * from enum import Enum
229
+ *
230
+ * class Color(Enum):
231
+ * RED = 1
232
+ * GREEN = 2
233
+ * BLUE = 3
234
+ *
235
+ * # Color.RED is an EnumLiteral:
236
+ * # className="Color", itemName="RED", itemType=int (for value 1)
237
+ *
238
+ * def process(color: Literal[Color.RED]) -> None:
239
+ * pass # EnumLiteral tracks that it's specifically Color.RED
240
+ * ```
241
+ */
242
+ interface EnumLiteral {
243
+ className: string;
244
+ itemName: string;
245
+ itemType: Type;
246
+ }
247
+ /**
248
+ * Represents a sentinel value (a unique object used as a marker).
249
+ * Used for special singleton values that act as sentinels in APIs.
250
+ *
251
+ * Fields:
252
+ * - classNode: AST node where the sentinel class is defined
253
+ * - moduleName: Module containing the sentinel
254
+ * - className: Name of the sentinel class
255
+ *
256
+ * Examples:
257
+ * ```python
258
+ * # Common sentinel pattern
259
+ * class _Sentinel:
260
+ * pass
261
+ * MISSING = _Sentinel()
262
+ *
263
+ * def get_value(key: str, default: int | _Sentinel = MISSING) -> int:
264
+ * ...
265
+ *
266
+ * # MISSING is a SentinelLiteral pointing to the _Sentinel class instance
267
+ *
268
+ * # Used in standard library (e.g., dataclasses.MISSING)
269
+ * from dataclasses import field, MISSING
270
+ * # MISSING is tracked as a SentinelLiteral
271
+ * ```
272
+ */
273
+ interface SentinelLiteral {
274
+ classNode: Node;
275
+ moduleName: string;
276
+ className: string;
277
+ }
278
+ /**
279
+ * Represents the value of a literal type in Python.
280
+ * A literal type has a specific, known value at type-checking time.
281
+ *
282
+ * Literal types include:
283
+ * - Primitive literals: numbers, booleans, strings
284
+ * - Enum members: specific values from an Enum class
285
+ * - Sentinel values: unique marker objects (e.g., dataclasses.MISSING)
286
+ *
287
+ * Used for:
288
+ * - Type narrowing with specific values
289
+ * - Overload resolution based on literal arguments
290
+ * - TypedDict key validation
291
+ * - Literal types in function signatures
292
+ *
293
+ * Examples:
294
+ * ```python
295
+ * # Primitive literals
296
+ * x: Literal[42] = 42 # number literal
297
+ * y: Literal["hello"] = "hello" # string literal
298
+ * z: Literal[True] = True # boolean literal
299
+ * big: Literal[999999999999999] = 999999999999999 # bigint literal
300
+ *
301
+ * # Enum literal
302
+ * class Color(Enum):
303
+ * RED = 1
304
+ * color: Literal[Color.RED] = Color.RED # EnumLiteral
305
+ *
306
+ * # Sentinel literal
307
+ * from dataclasses import MISSING
308
+ * def field(default=MISSING): ... # SentinelLiteral
309
+ * ```
310
+ */
311
+ type LiteralValue = number | bigint | boolean | string | EnumLiteral | SentinelLiteral;
312
+ /**
313
+ * Discriminator for the Union type.
314
+ * Identifies which variant of Type is being used.
315
+ *
316
+ * Used for type narrowing when processing Type objects:
317
+ * ```typescript
318
+ * if (handle.kind === TypeKind.Function) {
319
+ * // TypeScript knows this is FunctionType
320
+ * const returnType = handle.returnType;
321
+ * }
322
+ * ```
323
+ *
324
+ * Categories:
325
+ * - BuiltIn: Special types (unknown, any, never, etc.)
326
+ * - Declared: Base type for source declarations (rarely used directly)
327
+ * - Function: Function or method types from def statements
328
+ * - Class: Class types from class statements
329
+ * - Union: Multiple types combined (T1 | T2 | ...)
330
+ * - Module: Python module types
331
+ * - TypeVar: Generic type parameters (T, P, Ts)
332
+ * - Overloaded: Functions with @overload decorators
333
+ * - Synthesized: Generated stub content for type server created types
334
+ * - TypeReference: Reference to another type by ID
335
+ */
336
+ const enum TypeKind {
337
+ BuiltIn = 0,// unknown, any, never, etc.
338
+ Declared = 1,// Base for source-declared types (rarely used directly)
339
+ Function = 2,// Functions and methods from def statements
340
+ Class = 3,// Classes from class statements
341
+ Union = 4,// int | str | None
342
+ Module = 5,// import os -> os is ModuleType
343
+ TypeVar = 6,// T, P, Ts in generics
344
+ Overloaded = 7,// Functions with multiple @overload signatures
345
+ Synthesized = 8,// Types that are synthesized by the type checker
346
+ TypeReference = 9
347
+ }
348
+ /**
349
+ * Discriminator for the Declaration union type.
350
+ * Distinguishes between declarations that exist in source code versus those created by the type checker.
351
+ *
352
+ * Used to determine whether a declaration:
353
+ * - Has an actual AST node in the parse tree (Regular)
354
+ * - Was created implicitly by the type system (Synthesized)
355
+ *
356
+ * Examples:
357
+ * - Regular: `def my_function():` - has source code node
358
+ * - Synthesized: `__init__` method generated by @dataclass - no source node
359
+ * - Regular: `class MyClass:` - has source code node
360
+ * - Synthesized: Built-in `len` function - no user source code
361
+ */
362
+ const enum DeclarationKind {
363
+ Regular = 0,// Declaration exists in source code with AST node
364
+ Synthesized = 1
365
+ }
366
+ /**
367
+ * Base interface for all declaration types.
368
+ * Provides the discriminator field for the Declaration union.
369
+ *
370
+ * This is a generic interface that is extended by:
371
+ * - RegularDeclaration (kind = Regular)
372
+ * - SynthesizedDeclaration (kind = Synthesized)
373
+ *
374
+ * The type parameter T ensures that the kind field matches the implementing interface.
375
+ *
376
+ * Used for type-safe discrimination:
377
+ * ```typescript
378
+ * if (declaration.kind === DeclarationKind.Regular) {
379
+ * // TypeScript knows this is RegularDeclaration
380
+ * const node = declaration.node;
381
+ * }
382
+ * ```
383
+ */
384
+ interface DeclarationBase<T extends DeclarationKind> {
385
+ kind: T;
386
+ }
387
+ /**
388
+ * Represents a declaration that exists in source code.
389
+ * Points to the actual AST node where a symbol is declared.
390
+ *
391
+ * Fields:
392
+ * - category: Type of declaration (Variable, Function, Class, etc.)
393
+ * - node: AST node pointing to the declaration location
394
+ * - name: Name of the declared symbol (undefined for anonymous/implicit declarations)
395
+ *
396
+ * Examples:
397
+ * ```python
398
+ * def my_function(x: int) -> str: # Function declaration
399
+ * return str(x)
400
+ *
401
+ * class MyClass: # Class declaration
402
+ * x: int # Variable declaration
403
+ *
404
+ * T = TypeVar('T') # TypeParam declaration
405
+ * ```
406
+ */
407
+ interface RegularDeclaration extends DeclarationBase<DeclarationKind.Regular> {
408
+ category: DeclarationCategory;
409
+ node: Node;
410
+ name: string | undefined;
411
+ }
412
+ /**
413
+ * Represents a synthesized declaration (not in source code).
414
+ * Used for implicitly created symbols like built-in types or decorator-generated members.
415
+ *
416
+ * Fields:
417
+ * - uri: The file URI where this is conceptually declared (often the module using it)
418
+ *
419
+ * Examples:
420
+ * ```python
421
+ * # Built-in functions have synthesized declarations
422
+ * len([1, 2, 3]) # len is synthesized, not from source
423
+ *
424
+ * # @dataclass generates __init__, __eq__, etc. - synthesized declarations
425
+ * @dataclass
426
+ * class Point:
427
+ * x: int
428
+ * y: int
429
+ * # Point.__init__ is synthesized
430
+ * ```
431
+ */
432
+ interface SynthesizedDeclaration extends DeclarationBase<DeclarationKind.Synthesized> {
433
+ uri: string;
434
+ }
435
+ /**
436
+ * Union type representing any kind of declaration.
437
+ * A declaration describes where and how a symbol (variable, function, class, etc.) is defined.
438
+ *
439
+ * Contains either:
440
+ * - RegularDeclaration: For declarations in source code with AST nodes
441
+ * - SynthesizedDeclaration: For declarations created by the type checker
442
+ *
443
+ * Used for:
444
+ * - Tracking where symbols are defined
445
+ * - Navigating to declaration locations (Go to Definition)
446
+ * - Distinguishing user code from generated/built-in code
447
+ * - Providing context for type information
448
+ *
449
+ * Examples:
450
+ * ```python
451
+ * # Regular declaration
452
+ * def my_function(x: int) -> str: # RegularDeclaration
453
+ * return str(x)
454
+ *
455
+ * # Synthesized declaration
456
+ * @dataclass
457
+ * class Point:
458
+ * x: int
459
+ * y: int
460
+ * # Point.__init__ has SynthesizedDeclaration (generated by @dataclass)
461
+ *
462
+ * # Built-in function
463
+ * len([1, 2, 3]) # len has SynthesizedDeclaration
464
+ * ```
465
+ */
466
+ type Declaration = RegularDeclaration | SynthesizedDeclaration;
467
+ /**
468
+ * Describes the variance of a type parameter in a generic type.
469
+ * Variance controls how subtyping relationships work with generic types.
470
+ *
471
+ * Variance rules:
472
+ * - Covariant: If A is a subtype of B, then Generic[A] is a subtype of Generic[B]
473
+ * - Used when the type parameter appears only in output positions (return types)
474
+ * - Example: Tuple[T] is covariant in T
475
+ *
476
+ * - Contravariant: If A is a subtype of B, then Generic[B] is a subtype of Generic[A]
477
+ * - Used when the type parameter appears only in input positions (parameters)
478
+ * - Example: Callable[[T], None] is contravariant in T
479
+ *
480
+ * - Invariant: No subtyping relationship exists regardless of T
481
+ * - Used when the type parameter appears in both input and output positions
482
+ * - Example: List[T] is invariant in T
483
+ *
484
+ * Examples:
485
+ * ```python
486
+ * from typing import TypeVar, Generic
487
+ *
488
+ * T_co = TypeVar('T_co', covariant=True) # Covariant
489
+ * T_contra = TypeVar('T_contra', contravariant=True) # Contravariant
490
+ * T = TypeVar('T') # Invariant by default
491
+ *
492
+ * class Container(Generic[T_co]): # Covariant
493
+ * def get(self) -> T_co: ... # T_co in output position only
494
+ *
495
+ * class Consumer(Generic[T_contra]): # Contravariant
496
+ * def accept(self, value: T_contra) -> None: ... # T_contra in input only
497
+ * ```
498
+ */
499
+ const enum Variance {
500
+ Auto = 0,// Variance not yet determined, will be inferred
501
+ Unknown = 1,// Variance cannot be determined
502
+ Invariant = 2,// No subtyping relationship (default for mutable types)
503
+ Covariant = 3,// Preserves subtyping: Generic[Child] <: Generic[Parent]
504
+ Contravariant = 4
505
+ }
506
+ /**
507
+ * Contains metadata about a type alias.
508
+ * Used when a type is created through a type alias statement (PEP 613) or traditional assignment.
509
+ *
510
+ * Fields:
511
+ * - name: Short name of the alias
512
+ * - fullName: Fully qualified name including module path
513
+ * - moduleName: Module where the alias is defined
514
+ * - fileUri: File location of the alias definition
515
+ * - scopeId: Scope identifier for the alias (for scoped type variables)
516
+ * - isTypeAliasType: True if this uses the `type` keyword (PEP 695)
517
+ * - typeParams: Generic type parameters declared by the alias
518
+ * - typeArgs: Concrete type arguments when the alias is specialized
519
+ * - computedVariance: Inferred variance for type parameters
520
+ *
521
+ * Examples:
522
+ * ```python
523
+ * # PEP 695 style (isTypeAliasType=true)
524
+ * type IntList = list[int]
525
+ *
526
+ * # Traditional style (isTypeAliasType=false)
527
+ * IntList = list[int]
528
+ *
529
+ * # Generic alias with type parameters
530
+ * type Pair[T] = tuple[T, T]
531
+ * # typeParams=[T], can be specialized to Pair[int]
532
+ *
533
+ * # Using typing.TypeAlias
534
+ * from typing import TypeAlias
535
+ * UserId: TypeAlias = int
536
+ * ```
537
+ */
538
+ interface TypeAliasInfo {
539
+ readonly name: string;
540
+ readonly fullName: string;
541
+ readonly moduleName: string;
542
+ readonly fileUri: string;
543
+ readonly scopeId: string;
544
+ readonly isTypeAliasType: boolean;
545
+ readonly typeParams?: Type[];
546
+ readonly typeArgs?: Type[];
547
+ readonly computedVariance?: Variance[];
548
+ }
549
+ /**
550
+ * Base interface for all Type variants.
551
+ * Provides common fields shared by all type representations in the protocol.
552
+ *
553
+ * This is the foundation interface extended by all Type types:
554
+ * - BuiltInType
555
+ * - RegularType (and its subclasses FunctionType, ClassType)
556
+ * - UnionType
557
+ * - ModuleType
558
+ * - TypeVarType
559
+ * - OverloadedType
560
+ * - SynthesizedType
561
+ * - TypeReference
562
+ *
563
+ * The type parameter T constrains the `kind` field to match the implementing type.
564
+ *
565
+ * Common fields:
566
+ * - id: Unique identifier for cycle detection and caching
567
+ * - kind: Discriminator for the Type union
568
+ * - flags: Characteristics of the type (Instantiable, Instance, Callable, etc.)
569
+ * - typeAliasInfo: Optional alias information if type comes from a type alias
570
+ *
571
+ * Used throughout the protocol to represent Python types in a serializable format.
572
+ */
573
+ interface TypeBase<T extends TypeKind> {
574
+ readonly id: number;
575
+ readonly kind: T;
576
+ readonly flags: TypeFlags;
577
+ readonly typeAliasInfo?: TypeAliasInfo;
578
+ }
579
+ /**
580
+ * Represents special built-in types that are fundamental to Python's type system.
581
+ * These are not regular classes but represent special semantic meanings.
582
+ *
583
+ * Used for:
584
+ * - Type inference failures (unknown)
585
+ * - Gradual typing (any)
586
+ * - Uninitialized variables (unbound)
587
+ * - Special literals (ellipsis for ...)
588
+ * - Non-returning functions (never/noreturn)
589
+ *
590
+ * Examples:
591
+ * - `unknown`: `x` in `def foo(x):` with no type hints and no usage to infer from
592
+ * - `any`: Explicit `Any` annotation or from untyped imports
593
+ * - `unbound`: Variable declared but not yet assigned: `x: int` (before assignment)
594
+ * - `ellipsis`: The `...` in `def foo(...): ...` or `Tuple[int, ...]`
595
+ * - `never`: `def raise_error() -> Never:` or function with only raise statements
596
+ */
597
+ interface BuiltInType extends TypeBase<TypeKind.BuiltIn> {
598
+ readonly declaration?: Declaration;
599
+ readonly name: 'unknown' | 'any' | 'unbound' | 'ellipsis' | 'never' | 'noreturn';
600
+ readonly possibleType?: Type;
601
+ }
602
+ /**
603
+ * Base type for symbols that have a declaration in source code.
604
+ * This is the common parent for FunctionType and ClassType when the type
605
+ * comes from an actual declaration node in the parse tree.
606
+ *
607
+ * The type parameter T allows subtypes to specify their own TypeKind
608
+ * (e.g., Function or Class) while sharing the common declaration field.
609
+ *
610
+ * Used for:
611
+ * - Functions and methods with actual `def` statements (TypeKind.Function)
612
+ * - Classes with actual `class` statements (TypeKind.Class)
613
+ * - Variables with declarations in source (TypeKind.Declared)
614
+ *
615
+ * Not used for:
616
+ * - Synthesized types (use SynthesizedType)
617
+ * - Built-in types (use BuiltInType)
618
+ *
619
+ * Example:
620
+ * ```python
621
+ * def my_function(x: int) -> str: # FunctionType with TypeKind.Function
622
+ * return str(x)
623
+ * class MyClass: # ClassType with TypeKind.Class
624
+ * pass
625
+ * ```
626
+ */
627
+ interface DeclaredType<T extends TypeKind = TypeKind.Declared> extends TypeBase<T> {
628
+ readonly declaration: Declaration;
629
+ }
630
+ /**
631
+ * Represents a function or method that has a declaration in the source code.
632
+ * Used for functions parsed from actual `def` statements.
633
+ *
634
+ * Uses TypeKind.Function for discrimination from ClassType and other types.
635
+ *
636
+ * Binding behavior:
637
+ * - boundToType: Contains the class/instance the method is bound to.
638
+ *
639
+ * Used for:
640
+ * - User-defined functions with `def` statements
641
+ * - Methods declared in source classes
642
+ * - Lambda functions (though simple ones)
643
+ *
644
+ * Not used for:
645
+ * - Built-in functions like `len`, `print` (use SynthesizedType)
646
+ * - Synthesized methods from decorators like @dataclass (use SynthesizedType)
647
+ *
648
+ * Example:
649
+ * ```python
650
+ * def calculate(x: int, y: int) -> int:
651
+ * return x + y
652
+ *
653
+ * class MyClass:
654
+ * def method(self, value: str) -> None:
655
+ * pass
656
+ * ```
657
+ */
658
+ interface FunctionType extends DeclaredType<TypeKind.Function> {
659
+ readonly returnType?: Type;
660
+ readonly specializedTypes?: SpecializedFunctionTypes;
661
+ readonly boundToType?: Type;
662
+ }
663
+ /**
664
+ * Represents a class or class instance that has a declaration in the source code.
665
+ * Used for classes parsed from actual `class` statements.
666
+ *
667
+ * Uses TypeKind.Class for discrimination from FunctionType and other types.
668
+ *
669
+ * Used for:
670
+ * - User-defined classes with `class` statements
671
+ * - Class instances (instances of user-defined classes)
672
+ * - Specialized generic classes (e.g., `MyClass[int]`)
673
+ * - Literal instances (e.g., the number `42` is an instance of `int`)
674
+ *
675
+ * Not used for:
676
+ * - Built-in classes like `int`, `str`, `list` (use SynthesizedType)
677
+ * - Classes synthesized by decorators (use SynthesizedType)
678
+ *
679
+ * Example:
680
+ * ```python
681
+ * class Point:
682
+ * x: int
683
+ * y: int
684
+ *
685
+ * class Container[T]:
686
+ * value: T
687
+ *
688
+ * # point has ClassType (instance of Point)
689
+ * point = Point()
690
+ * # container has ClassType with typeArgs=[int]
691
+ * container: Container[int] = Container()
692
+ * ```
693
+ */
694
+ interface ClassType extends DeclaredType<TypeKind.Class> {
695
+ readonly literalValue?: LiteralValue;
696
+ readonly typeArgs?: Type[];
697
+ }
698
+ /**
699
+ * Represents a union of multiple types (Type1 | Type2 | ...).
700
+ * Used when a value can be one of several different types.
701
+ *
702
+ * Used for:
703
+ * - Explicit union type annotations using `|` or `Union[...]`
704
+ * - Optional types (which are unions with None)
705
+ * - Type narrowing results (e.g., after isinstance checks)
706
+ * - Inferred types from multiple branches
707
+ *
708
+ * Examples:
709
+ * ```python
710
+ * # Explicit union annotation
711
+ * def process(value: int | str) -> None:
712
+ * pass
713
+ *
714
+ * # Optional (union with None)
715
+ * def find(key: str) -> str | None:
716
+ * return None
717
+ *
718
+ * # Inferred union from branches
719
+ * if condition:
720
+ * x = 42 # int
721
+ * else:
722
+ * x = "hello" # str
723
+ * # x has type int | str
724
+ * ```
725
+ */
726
+ interface UnionType extends TypeBase<TypeKind.Union> {
727
+ readonly subTypes: Type[];
728
+ }
729
+ /**
730
+ * Represents a Python module as a type.
731
+ * Used when a module object itself is referenced (not its contents).
732
+ *
733
+ * Used for:
734
+ * - Module imports: `import os` makes `os` a ModuleType
735
+ * - Module attributes accessed via __file__, __name__, etc.
736
+ * - Submodule references: `os.path` is also a ModuleType
737
+ *
738
+ * The loaderFields contain all the symbols exported by the module that would
739
+ * be accessible via attribute access (module.symbol_name).
740
+ *
741
+ * Examples:
742
+ * ```python
743
+ * import os
744
+ * import os.path as path
745
+ * from typing import Protocol
746
+ *
747
+ * # `os` has ModuleType with loaderFields containing {"path": ..., "getcwd": ..., etc.}
748
+ * # `path` has ModuleType for the os.path module
749
+ * # In type stubs, Protocol is a module symbol that gets loaded
750
+ * ```
751
+ */
752
+ interface ModuleType extends TypeBase<TypeKind.Module> {
753
+ readonly moduleName: string;
754
+ readonly uri: string;
755
+ }
756
+ /**
757
+ * Represents a type variable (generic type parameter).
758
+ * Used for generic programming where types are parameterized.
759
+ *
760
+ * Used for:
761
+ * - Explicit TypeVar declarations: `T = TypeVar('T')`
762
+ * - PEP 695 type parameters: `def func[T](x: T) -> T`
763
+ * - ParamSpec for callable signatures: `P = ParamSpec('P')`
764
+ * - TypeVarTuple for variadic generics: `Ts = TypeVarTuple('Ts')`
765
+ * - Constrained type variables: `T = TypeVar('T', int, str)`
766
+ * - Bounded type variables: `T = TypeVar('T', bound=Number)`
767
+ *
768
+ * Examples:
769
+ * ```python
770
+ * # Classic TypeVar
771
+ * T = TypeVar('T')
772
+ * def identity[T](x: T) -> T:
773
+ * return x
774
+ *
775
+ * # Bounded TypeVar
776
+ * T_num = TypeVar('T_num', bound=int)
777
+ * def double[T_num](x: T_num) -> T_num:
778
+ * return x * 2
779
+ *
780
+ * # Constrained TypeVar
781
+ * T_str_or_bytes = TypeVar('T_str_or_bytes', str, bytes)
782
+ *
783
+ * # ParamSpec
784
+ * P = ParamSpec('P')
785
+ * def decorator(func: Callable[P, R]) -> Callable[P, R]:
786
+ * ...
787
+ * ```
788
+ */
789
+ type TypeVarType = DeclaredType<TypeKind.TypeVar>;
790
+ /**
791
+ * Represents an overloaded function with multiple signatures.
792
+ * Used when a function has multiple `@overload` decorators defining different call signatures.
793
+ *
794
+ * Used for:
795
+ * - Functions with @overload decorators
796
+ * - Built-in functions with multiple signatures (e.g., `range(stop)` vs `range(start, stop, step)`)
797
+ * - Methods with different signatures for different argument types
798
+ *
799
+ * The `overloads` array contains all the @overload signatures, and `implementation`
800
+ * contains the actual implementation (if present).
801
+ *
802
+ * Examples:
803
+ * ```python
804
+ * from typing import overload
805
+ *
806
+ * @overload
807
+ * def process(value: int) -> str: ...
808
+ * @overload
809
+ * def process(value: str) -> int: ...
810
+ * def process(value: int | str) -> int | str:
811
+ * if isinstance(value, int):
812
+ * return str(value)
813
+ * return len(value)
814
+ *
815
+ * # The type of `process` is OverloadedType with:
816
+ * # - overloads = [signature for (int)->str, signature for (str)->int]
817
+ * # - implementation = signature for (int|str)->(int|str)
818
+ * ```
819
+ */
820
+ interface OverloadedType extends TypeBase<TypeKind.Overloaded> {
821
+ overloads: Type[];
822
+ implementation?: Type;
823
+ }
824
+ /**
825
+ * Metadata about a synthesized type that provides additional context.
826
+ * This information is used by the client to enhance IntelliSense and type checking.
827
+ */
828
+ interface SynthesizedTypeMetadata {
829
+ /**
830
+ * Module where the synthesized type is defined.
831
+ * Used to provide context about the origin of the synthesized type.
832
+ *
833
+ * Examples:
834
+ * - For a synthesized `__init__` method from a @dataclass, this is the module containing the dataclass.
835
+ * - For a NewType declaration, this is the module where the NewType is defined.
836
+ */
837
+ module: ModuleType;
838
+ /**
839
+ * Character offset into the stubContent where the primary/target definition starts.
840
+ * When the stub contains multiple definitions (e.g., base classes and the main class,
841
+ * or a class with multiple methods), this points to the specific definition that
842
+ * represents the synthesized type.
843
+ *
844
+ * The offset is a zero-based character index from the start of stubContent.
845
+ *
846
+ * Examples:
847
+ * - For a function stub, points to the 'def' keyword
848
+ * - For a class stub, points to the 'class' keyword of the target class
849
+ * - For a method in a class, points to the 'def' keyword of that method
850
+ * - For a NewType assignment, points to the start of the assignment
851
+ *
852
+ * Example:
853
+ * ```python
854
+ * # stubContent:
855
+ * from typing import NewType
856
+ * UserId = NewType('UserId', int)
857
+ * # ^offset points here (start of 'UserId')
858
+ * ```
859
+ */
860
+ primaryDefinitionOffset: number;
861
+ }
862
+ /**
863
+ * Represents synthesized/generated types.
864
+ *
865
+ * When the type server generates its own types that do not directly correspond
866
+ * to source code declarations, it uses this handle.
867
+ *
868
+ * The stub content should be a complete, valid Python stub (.pyi) that includes:
869
+ * 1. All necessary imports (typing module, collections.abc, etc.)
870
+ * 2. TypeVar and ParamSpec declarations used in the type
871
+ * 3. Type aliases or class definitions
872
+ * 4. Function signatures with full parameter and return type annotations
873
+ *
874
+ * This approach is particularly useful for:
875
+ * - Synthesized methods from decorators like @dataclass.__init__
876
+ * - NewType declarations
877
+ * - Generic type specializations
878
+ *
879
+ * Examples:
880
+ *
881
+ * # Example 1: Synthesized dataclass __init__
882
+ * from dataclasses import dataclass
883
+ * @dataclass
884
+ * class Point:
885
+ * x: int
886
+ * y: int
887
+ * # Stub content for Point.__init__:
888
+ * """
889
+ * def __init__(self, x: int, y: int) -> None:
890
+ * '''Initialize Point'''
891
+ * """
892
+ * # metadata: { primaryDefinitionOffset: 0 }
893
+ *
894
+ * # Example 2: Generic function with TypeVar
895
+ * from typing import TypeVar
896
+ * T = TypeVar('T')
897
+ * def identity(x: T) -> T:
898
+ * return x
899
+ * # Stub content:
900
+ * """
901
+ * from typing import TypeVar
902
+ * T = TypeVar('T')
903
+ * def identity(x: T) -> T: ...
904
+ * """
905
+ * # metadata: { primaryDefinitionOffset: 45 } (offset points to 'def')
906
+ *
907
+ * # Example 3: ParamSpec function
908
+ * from typing import ParamSpec, Callable
909
+ * P = ParamSpec('P')
910
+ * def wrapper(func: Callable[P, int]) -> Callable[P, str]:
911
+ * ...
912
+ * # Stub content:
913
+ * """
914
+ * from typing import ParamSpec, Callable
915
+ * P = ParamSpec('P')
916
+ * def wrapper(func: Callable[P, int]) -> Callable[P, str]: ...
917
+ * """
918
+ * # metadata: { primaryDefinitionOffset: 67 }
919
+ *
920
+ * # Example 4: NewType
921
+ * from typing import NewType
922
+ * UserId = NewType('UserId', int)
923
+ * # Stub content:
924
+ * """
925
+ * from typing import NewType
926
+ * UserId = NewType('UserId', int)
927
+ * """
928
+ * # metadata: { primaryDefinitionOffset: 25 } (offset points to 'UserId')
929
+ *
930
+ * # Example 5: Complex generic specialization with ParamSpec
931
+ * class Wrapper[P, R]:
932
+ * func: Callable[P, R]
933
+ * def example(x: int, y: str) -> bool: ...
934
+ * w: Wrapper[(x: int, y: str), bool] = Wrapper()
935
+ * # Stub content for Wrapper[(x: int, y: str), bool]:
936
+ * """
937
+ * from typing import ParamSpec, TypeVar, Generic, Callable
938
+ * P = ParamSpec('P')
939
+ * R = TypeVar('R')
940
+ * class Wrapper(Generic[P, R]):
941
+ * func: Callable[P, R]
942
+ * """
943
+ * # metadata: { primaryDefinitionOffset: 87 } (offset points to 'class Wrapper')
944
+ * ```
945
+ *
946
+ * Important: The stub content is used to reconstruct the type on the client side by:
947
+ * 1. Parsing the stub as a Python type stub file
948
+ * 2. Evaluating the type expressions within the stub
949
+ * 3. Extracting the resulting type for use in type checking and IntelliSense
950
+ */
951
+ interface SynthesizedType extends TypeBase<TypeKind.Synthesized> {
952
+ /**
953
+ * Python stub file content (.pyi format) generated for this type.
954
+ *
955
+ * Must include:
956
+ * - Import statements for all typing constructs used (TypeVar, ParamSpec, Callable, etc.)
957
+ * - TypeVar/ParamSpec declarations that appear in the type signature
958
+ * - The complete type definition (function, class, or type alias)
959
+ * - Proper Python stub syntax with ellipsis (...) for function bodies
960
+ *
961
+ * The stub should be minimal but complete - include only what's necessary to
962
+ * reconstruct the type. Avoid including unrelated definitions.
963
+ *
964
+ * Example for a generic function:
965
+ * ```
966
+ * from typing import TypeVar
967
+ * T = TypeVar('T')
968
+ * def identity(x: T) -> T: ...
969
+ * ```
970
+ *
971
+ * Example for a dataclass synthesized method:
972
+ * ```
973
+ * def __init__(self, x: int, y: int, z: str = "") -> None: ...
974
+ * ```
975
+ */
976
+ readonly stubContent: string;
977
+ /**
978
+ * Additional metadata about the synthesized type.
979
+ */
980
+ readonly metadata: SynthesizedTypeMetadata;
981
+ }
982
+ /**
983
+ * Represents a reference to another type by its ID.
984
+ * Used to avoid duplicating large type structures and to handle forward references.
985
+ *
986
+ * Used for:
987
+ * - Deduplication: When the same type appears multiple times, subsequent occurrences
988
+ * can reference the first occurrence instead of duplicating all fields
989
+ * - Cyclic references: Breaking cycles in recursive type definitions
990
+ * - Large types: Reducing payload size for complex types used repeatedly
991
+ *
992
+ * This is an optimization mechanism in the protocol to keep type handles compact
993
+ * when transmitting over the wire.
994
+ *
995
+ * Examples:
996
+ * ```python
997
+ * # Recursive type definition
998
+ * class Node:
999
+ * value: int
1000
+ * next: Node | None # 'Node' references back to itself
1001
+ *
1002
+ * # When serializing the type of 'next', the second occurrence of Node
1003
+ * # uses TypeReferenceType pointing to the first Node's ID
1004
+ *
1005
+ * # Repeated complex type
1006
+ * def process_lists(
1007
+ * list1: list[dict[str, int]],
1008
+ * list2: list[dict[str, int]], # Can reference the type from list1
1009
+ * list3: list[dict[str, int]] # Can reference the type from list1
1010
+ * ) -> None:
1011
+ * pass
1012
+ * ```
1013
+ */
1014
+ interface TypeReferenceType extends TypeBase<TypeKind.TypeReference> {
1015
+ readonly typeReferenceId: number;
1016
+ }
1017
+ type Type = BuiltInType | DeclaredType | FunctionType | ClassType | UnionType | ModuleType | TypeVarType | OverloadedType | SynthesizedType | TypeReferenceType;
1018
+ namespace GetComputedTypeRequest {
1019
+ const method: "typeServer/getComputedType";
1020
+ const messageDirection = MessageDirection.clientToServer;
1021
+ const type: ProtocolRequestType<{
1022
+ arg: Declaration | Node;
1023
+ snapshot: number;
1024
+ }, Type | undefined, never, void, void>;
1025
+ }
1026
+ namespace GetDeclaredTypeRequest {
1027
+ const method: "typeServer/getDeclaredType";
1028
+ const messageDirection = MessageDirection.clientToServer;
1029
+ const type: ProtocolRequestType<{
1030
+ arg: Declaration | Node;
1031
+ snapshot: number;
1032
+ }, Type | undefined, never, void, void>;
1033
+ }
1034
+ namespace GetExpectedTypeRequest {
1035
+ const method: "typeServer/getExpectedType";
1036
+ const messageDirection = MessageDirection.clientToServer;
1037
+ const type: ProtocolRequestType<{
1038
+ arg: Declaration | Node;
1039
+ snapshot: number;
1040
+ }, Type | undefined, never, void, void>;
1041
+ }
1042
+ /**
1043
+ * Request to get the search paths that the type server uses for Python modules.
1044
+ */
1045
+ namespace GetPythonSearchPathsRequest {
1046
+ const method: "typeServer/getPythonSearchPaths";
1047
+ const messageDirection = MessageDirection.clientToServer;
1048
+ const type: ProtocolRequestType<GetPythonSearchPathsParams, string[] | undefined, never, void, void>;
1049
+ }
1050
+ /**
1051
+ * Request from client to get the current snapshot of the type server.
1052
+ * A snapshot is a point-in-time representation of the type server's state, including all loaded files and their types.
1053
+ * A type server should change its snapshot whenever any type it might have returned is no longer valid. Meaning types are
1054
+ * only usable for the snapshot they were returned with.
1055
+ *
1056
+ * Snapshots are not meant to survive any changes that would make the type server throw away its internal cache. They are merely an
1057
+ * identifier to indicate to the client that the type server will accept requests for types from that snapshot.
1058
+ */
1059
+ namespace GetSnapshotRequest {
1060
+ const method: "typeServer/getSnapshot";
1061
+ const messageDirection = MessageDirection.clientToServer;
1062
+ const type: ProtocolRequestType0<number, never, void, void>;
1063
+ }
1064
+ /**
1065
+ * Request to get the version of the protocol the type server supports.
1066
+ *
1067
+ * Returns a string representation of the protocol version (should be semver format)
1068
+ */
1069
+ namespace GetSupportedProtocolVersionRequest {
1070
+ const method: "typeServer/getSupportedProtocolVersion";
1071
+ const messageDirection = MessageDirection.clientToServer;
1072
+ const type: ProtocolRequestType0<string, never, void, void>;
1073
+ }
1074
+ /**
1075
+ * Request to resolve an import. This is used to resolve the import name to its location in the file system.
1076
+ */
1077
+ namespace ResolveImportRequest {
1078
+ const method: "typeServer/resolveImport";
1079
+ const messageDirection = MessageDirection.clientToServer;
1080
+ const type: ProtocolRequestType<ResolveImportParams, string | undefined, never, void, void>;
1081
+ }
1082
+ /**
1083
+ * Main-connection-only request used to open or close an extra TSP transport.
1084
+ * Extra transports must remain read-only and must not be used for LSP traffic.
1085
+ */
1086
+ namespace ConnectionRequest {
1087
+ const method: "typeServer/connection";
1088
+ const messageDirection = MessageDirection.clientToServer;
1089
+ const type: ProtocolRequestType<ConnectionRequestParams, ConnectionRequestResult, never, void, void>;
1090
+ }
1091
+ /**
1092
+ * Notification sent by the server to indicate any outstanding snapshots are invalid.
1093
+ */
1094
+ namespace SnapshotChangedNotification {
1095
+ const method: "typeServer/snapshotChanged";
1096
+ const messageDirection = MessageDirection.serverToClient;
1097
+ const type: ProtocolNotificationType<{
1098
+ old: number;
1099
+ new: number;
1100
+ }, void>;
1101
+ }
1102
+ }