🐛 fix(vscode): 代码阅读注释里引用的语言内置名不再标成找不到:代码里写到的(raise ValueError)问那处的定义、点了跳到语言自带的定义,没写到的当普通文字不能点;内置名单由语言插件给(Python 补全 dir(builtins),TypeScript 是 ECMAScript 标准全局对象)
This commit is contained in:
1 parent
49a3854390
commit
e3c8c1b118
14 files changed
+544
-98
No files matched your search
@@ -541,6 +541,96 @@ const BUILTIN_EXCEPTIONS = new Set([
|
||||
'UnicodeWarning',
|
||||
'UserWarning',
|
||||
])
|
||||
/** Python 自带的其余名字(`dir(builtins)` 里公开的):内置类型、内置函数、常量。 */
|
||||
const BUILTIN_OTHERS = [
|
||||
// 内置类型
|
||||
'bool',
|
||||
'bytearray',
|
||||
'bytes',
|
||||
'classmethod',
|
||||
'complex',
|
||||
'dict',
|
||||
'enumerate',
|
||||
'filter',
|
||||
'float',
|
||||
'frozenset',
|
||||
'int',
|
||||
'list',
|
||||
'map',
|
||||
'memoryview',
|
||||
'object',
|
||||
'property',
|
||||
'range',
|
||||
'reversed',
|
||||
'set',
|
||||
'slice',
|
||||
'staticmethod',
|
||||
'str',
|
||||
'super',
|
||||
'tuple',
|
||||
'type',
|
||||
'zip',
|
||||
// 内置函数,含启动时 site 加进来的 help、exit、quit、copyright、credits、license
|
||||
'abs',
|
||||
'aiter',
|
||||
'all',
|
||||
'anext',
|
||||
'any',
|
||||
'ascii',
|
||||
'bin',
|
||||
'breakpoint',
|
||||
'callable',
|
||||
'chr',
|
||||
'compile',
|
||||
'copyright',
|
||||
'credits',
|
||||
'delattr',
|
||||
'dir',
|
||||
'divmod',
|
||||
'eval',
|
||||
'exec',
|
||||
'exit',
|
||||
'format',
|
||||
'getattr',
|
||||
'globals',
|
||||
'hasattr',
|
||||
'hash',
|
||||
'help',
|
||||
'hex',
|
||||
'id',
|
||||
'input',
|
||||
'isinstance',
|
||||
'issubclass',
|
||||
'iter',
|
||||
'len',
|
||||
'license',
|
||||
'locals',
|
||||
'max',
|
||||
'min',
|
||||
'next',
|
||||
'oct',
|
||||
'open',
|
||||
'ord',
|
||||
'pow',
|
||||
'print',
|
||||
'quit',
|
||||
'repr',
|
||||
'round',
|
||||
'setattr',
|
||||
'sorted',
|
||||
'sum',
|
||||
'vars',
|
||||
// 常量
|
||||
'None',
|
||||
'True',
|
||||
'False',
|
||||
'Ellipsis',
|
||||
'NotImplemented',
|
||||
]
|
||||
|
||||
/** Python 不用导入就能用的名字([LanguageAdapter.builtins]):自带的异常类加上 [BUILTIN_OTHERS]。 */
|
||||
const PYTHON_BUILTINS: ReadonlySet<string> = new Set([...BUILTIN_EXCEPTIONS, ...BUILTIN_OTHERS])
|
||||
|
||||
/** PEP 8 的命名习惯:异常类名以 Error 结尾(别的文件里的 `AppException`、`*Warning` 也常见)。 */
|
||||
const EXCEPTION_NAME = /(?:Error|Exception|Warning)$/
|
||||
|
||||
@@ -672,6 +762,7 @@ export function createPythonAdapter(wasmDir: string): LanguageAdapter {
|
||||
call: pythonCall,
|
||||
collection: pythonCollection,
|
||||
bindings: root => pythonBindings(root),
|
||||
builtins: PYTHON_BUILTINS,
|
||||
displayNames: pythonNameReader,
|
||||
}
|
||||
}
|
||||
@@ -530,6 +530,76 @@ const TYPESCRIPT_EXCEPTIONS: ExceptionRules = {
|
||||
constructorParameters: block => block.kind === 'function' && block.facts.name?.text === 'constructor' ? block.facts.parameters : undefined,
|
||||
}
|
||||
|
||||
// ─── 自带的名字 ───────────────────────────────────────────────────────────────
|
||||
|
||||
/** ECMAScript 标准的全局对象([LanguageAdapter.builtins]),国际化的 `Intl` 也算;浏览器、Node 另加的不算。 */
|
||||
const TYPESCRIPT_BUILTINS: ReadonlySet<string> = new Set([
|
||||
// 值
|
||||
'globalThis',
|
||||
'Infinity',
|
||||
'NaN',
|
||||
'undefined',
|
||||
// 函数
|
||||
'eval',
|
||||
'isFinite',
|
||||
'isNaN',
|
||||
'parseFloat',
|
||||
'parseInt',
|
||||
'decodeURI',
|
||||
'decodeURIComponent',
|
||||
'encodeURI',
|
||||
'encodeURIComponent',
|
||||
// 构造函数
|
||||
'AggregateError',
|
||||
'Array',
|
||||
'ArrayBuffer',
|
||||
'BigInt',
|
||||
'BigInt64Array',
|
||||
'BigUint64Array',
|
||||
'Boolean',
|
||||
'DataView',
|
||||
'Date',
|
||||
'Error',
|
||||
'EvalError',
|
||||
'FinalizationRegistry',
|
||||
'Float16Array',
|
||||
'Float32Array',
|
||||
'Float64Array',
|
||||
'Function',
|
||||
'Int8Array',
|
||||
'Int16Array',
|
||||
'Int32Array',
|
||||
'Iterator',
|
||||
'Map',
|
||||
'Number',
|
||||
'Object',
|
||||
'Promise',
|
||||
'Proxy',
|
||||
'RangeError',
|
||||
'ReferenceError',
|
||||
'RegExp',
|
||||
'Set',
|
||||
'SharedArrayBuffer',
|
||||
'String',
|
||||
'Symbol',
|
||||
'SyntaxError',
|
||||
'TypeError',
|
||||
'Uint8Array',
|
||||
'Uint8ClampedArray',
|
||||
'Uint16Array',
|
||||
'Uint32Array',
|
||||
'URIError',
|
||||
'WeakMap',
|
||||
'WeakRef',
|
||||
'WeakSet',
|
||||
// 命名空间对象
|
||||
'Atomics',
|
||||
'Intl',
|
||||
'JSON',
|
||||
'Math',
|
||||
'Reflect',
|
||||
])
|
||||
|
||||
// ─── 源码着色 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/** 流程关键字;其余字母关键字都算声明关键字(storage)。 */
|
||||
@@ -664,6 +734,7 @@ export function createTypeScriptAdapter(wasmDir: string): LanguageAdapter {
|
||||
call: typescriptCall,
|
||||
collection: typescriptCollection,
|
||||
bindings: root => typescriptBindings(root),
|
||||
builtins: TYPESCRIPT_BUILTINS,
|
||||
displayNames: typescriptNameReader,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user