mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-11-15 04:21:31 +08:00
`items: Item[]` was read as an `Item`: the annotation's capture stopped at `[`, so `items.find(…)` linked to `Item.find` whenever the class declares a method of that name. On vscode that was 16 wrong edges, like `distinctElements.find(…)` on an `ExplorerItem[]` reaching `ExplorerItem.find` and `ranges.map(…)` on an `OffsetRange[]` reaching `OffsetRange.map`. The annotation pattern now captures a bracket suffix with the type. On an array of a type, a method arrays have links to nothing and isn't matched by its name either. Any other method can't be called on the array, so it is called on an element that shares its name, as in `d.forEach(d => d.dispose())`, and keeps the element's type as before. An indexed type (`Element["groupIds"]`) is still read as the type it indexes. The sync parking that came with the previous change now reads arrays from the type inference gives instead of re-reading the declaration line: an array method on an array keeps its member's tail, and an element's or an indexed type's call waits for that type's module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
3.3 KiB
TypeScript
62 lines
3.3 KiB
TypeScript
/** Shared JS/TS built-ins for direct references and inferred receiver types. */
|
|
export const JS_BUILT_INS = new Set([
|
|
'console', 'window', 'document', 'global', 'process',
|
|
'Promise', 'Array', 'Object', 'String', 'Number', 'Boolean',
|
|
'Date', 'Math', 'JSON', 'RegExp', 'Error', 'Map', 'Set', 'WeakMap', 'WeakSet',
|
|
'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
|
|
'fetch', 'require', 'module', 'exports', '__dirname', '__filename',
|
|
]);
|
|
|
|
/** Method names that require receiver evidence before linking to project code. */
|
|
export const JS_BUILTIN_METHODS = new Set([
|
|
// Array / typed arrays and collections.
|
|
'at', 'concat', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find',
|
|
'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap', 'forEach',
|
|
'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'pop', 'push',
|
|
'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice',
|
|
'toReversed', 'toSorted', 'toSpliced', 'unshift', 'values', 'with', 'subarray',
|
|
'get', 'set', 'has', 'add', 'delete', 'clear',
|
|
// String.
|
|
'charAt', 'charCodeAt', 'codePointAt', 'endsWith', 'localeCompare', 'match',
|
|
'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll',
|
|
'search', 'split', 'startsWith', 'substring', 'substr', 'toLowerCase',
|
|
'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase', 'trim', 'trimStart',
|
|
'trimEnd', 'trimLeft', 'trimRight', 'toString', 'toLocaleString', 'valueOf',
|
|
// Promise, Function, EventTarget / EventEmitter and iterators.
|
|
'then', 'catch', 'finally', 'call', 'apply', 'bind',
|
|
'addEventListener', 'removeEventListener', 'dispatchEvent', 'on', 'once',
|
|
'off', 'emit', 'addListener', 'removeListener', 'removeAllListeners',
|
|
'prependListener', 'prependOnceListener', 'listeners', 'rawListeners',
|
|
'listenerCount', 'eventNames', 'setMaxListeners', 'getMaxListeners',
|
|
'next', 'return', 'throw', 'drop', 'take', 'toArray',
|
|
// fetch's Response / Request / Blob bodies.
|
|
'text', 'json', 'arrayBuffer', 'blob', 'formData',
|
|
]);
|
|
|
|
/**
|
|
* The methods an array has: `Array.prototype`'s and those every object
|
|
* inherits. On a local annotated as an array (`items: Item[]`) a call of one
|
|
* is the array's, never a method of the element's class.
|
|
*/
|
|
export const JS_ARRAY_METHODS = new Set([
|
|
'at', 'concat', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find',
|
|
'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap', 'forEach',
|
|
'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'pop', 'push',
|
|
'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice',
|
|
'toReversed', 'toSorted', 'toSpliced', 'unshift', 'values', 'with',
|
|
'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf',
|
|
'propertyIsEnumerable',
|
|
]);
|
|
|
|
/**
|
|
* TypeScript primitive type names. Distinct from JS_BUILT_INS on purpose: those
|
|
* are runtime globals a receiver can be constructed from, these only ever come
|
|
* from a type annotation. A receiver typed `string` calls a built-in string
|
|
* method — never a project method — so the resolver declines rather than
|
|
* guessing a same-named one (#1840).
|
|
*/
|
|
export const TS_PRIMITIVE_TYPES = new Set([
|
|
'string', 'number', 'boolean', 'bigint', 'symbol',
|
|
'void', 'undefined', 'null', 'never', 'unknown', 'any', 'object',
|
|
]);
|