🐛 fix(vscode): 代码阅读跳到参数、导入项、多变量声明里的一个时只闪属性表里那一行,按源码位置判断
This commit is contained in:
1 parent
5b4ca903c5
commit
3ac1c783fb
14 files changed
+367
-47
No files matched your search
@@ -55,9 +55,9 @@ function texts(map: Map<number, Translated>): Record<number, string> {
|
||||
return Object.fromEntries([...map].map(([line, { segments }]) => [line, text(segments)]))
|
||||
}
|
||||
|
||||
/** 只看文字和着色:去掉各段的源码下标(下标另有用例)。 */
|
||||
/** 只看文字和着色:去掉各段的源码下标、属性行讲的定义(这两样另有用例)。 */
|
||||
function colors<T>(value: T): T {
|
||||
return JSON.parse(JSON.stringify(value, (key, field: unknown) => key === 'offset' ? undefined : field)) as T
|
||||
return JSON.parse(JSON.stringify(value, (key, field: unknown) => key === 'offset' || key === 'defines' ? undefined : field)) as T
|
||||
}
|
||||
|
||||
const CJK = /\p{Script=Han}/u
|
||||
@@ -578,6 +578,35 @@ describe('源码下标(跳到定义用)', () => {
|
||||
expect(linked(map.get(4)?.segments)).toEqual([['opts', at('opts ===')]])
|
||||
})
|
||||
|
||||
it('属性行、子行标出它讲的定义:参数名(连前缀、整个解构模式)、导入项的名称到别名、每个声明的变量名,其余行不标', async () => {
|
||||
/** 标了 defines 的行写成「属性名: 那段源码」,子行缩进两格只写那段源码。 */
|
||||
const marked = (source: string, rows: PropertyRow[] | undefined): string[] => (rows ?? []).flatMap(row => [
|
||||
...(row.defines ? [`${row.label}: ${source.slice(row.defines.startIndex, row.defines.endIndex)}`] : []),
|
||||
...(row.items ?? []).flatMap(item => item.defines ? [` ${source.slice(item.defines.startIndex, item.defines.endIndex)}`] : []),
|
||||
])
|
||||
const pySource = [
|
||||
'from m import a as b, c',
|
||||
'import os.path as p',
|
||||
'def f(self, *args, key: int = 1, **kw): pass',
|
||||
'x = 1',
|
||||
].join('\n')
|
||||
const pyRows = await describeAll(py, 'python', pythonZhTranslator, pySource)
|
||||
expect(marked(pySource, pyRows.get(1))).toEqual([' a as b', ' c'])
|
||||
expect(marked(pySource, pyRows.get(2))).toEqual([' os.path as p'])
|
||||
expect(marked(pySource, pyRows.get(3))).toEqual([' self', ' *args', ' key', ' **kw'])
|
||||
expect(marked(pySource, pyRows.get(4))).toEqual(['名称: x'])
|
||||
|
||||
const tsSource = [
|
||||
'import d, * as ns from \'m\'',
|
||||
'function g({ u, v }: T, w?: number) {}',
|
||||
'let i = 0, j',
|
||||
].join('\n')
|
||||
const tsRows = await describeAll(ts, 'typescript', typescriptZhTranslator, tsSource)
|
||||
expect(marked(tsSource, tsRows.get(1))).toEqual([' d', ' ns'])
|
||||
expect(marked(tsSource, tsRows.get(2))).toEqual([' { u, v }', ' w'])
|
||||
expect(marked(tsSource, tsRows.get(3))).toEqual(['名称: i', '名称: j'])
|
||||
})
|
||||
|
||||
it('样例全文:带下标的只有照抄的名字和字符串,下标处的源码就是这段;变量名、函数名都带,译词、说明词都不带', async () => {
|
||||
const samples: [LanguageAdapter, string, Translator, string][] = [
|
||||
[ts, 'typescript', typescriptZhTranslator, 'envLock.ts.txt'],
|
||||
|
||||
Reference in new issue
Block a user