Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d5843e55
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d5843e55
编写于
11月 20, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug for generating snippet if the object type contained a method signature
上级
1755715a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
6 deletion
+52
-6
extensions/typescript-language-features/src/features/completions.ts
.../typescript-language-features/src/features/completions.ts
+42
-5
extensions/typescript-language-features/src/test/functionCallSnippet.test.ts
...pt-language-features/src/test/functionCallSnippet.test.ts
+10
-1
未找到文件。
extensions/typescript-language-features/src/features/completions.ts
浏览文件 @
d5843e55
...
@@ -632,7 +632,6 @@ export function snippetForFunctionCall(
...
@@ -632,7 +632,6 @@ export function snippetForFunctionCall(
let
hasAddedParameters
=
false
;
let
hasAddedParameters
=
false
;
const
snippet
=
new
vscode
.
SnippetString
();
const
snippet
=
new
vscode
.
SnippetString
();
const
methodName
=
displayParts
.
find
(
part
=>
part
.
kind
===
'
methodName
'
);
if
(
item
.
insertText
)
{
if
(
item
.
insertText
)
{
if
(
typeof
item
.
insertText
===
'
string
'
)
{
if
(
typeof
item
.
insertText
===
'
string
'
)
{
snippet
.
appendText
(
item
.
insertText
);
snippet
.
appendText
(
item
.
insertText
);
...
@@ -640,17 +639,18 @@ export function snippetForFunctionCall(
...
@@ -640,17 +639,18 @@ export function snippetForFunctionCall(
return
item
.
insertText
;
return
item
.
insertText
;
}
}
}
else
{
}
else
{
snippet
.
appendText
(
(
methodName
&&
methodName
.
text
)
||
item
.
label
);
snippet
.
appendText
(
item
.
label
);
}
}
snippet
.
appendText
(
'
(
'
);
snippet
.
appendText
(
'
(
'
);
const
functionSignatureDisplayParts
=
getFunctionSignatureDisplayParts
(
displayParts
,
item
.
label
);
let
parenCount
=
0
;
let
parenCount
=
0
;
let
i
=
0
;
let
i
=
0
;
for
(;
i
<
d
isplayParts
.
length
;
++
i
)
{
for
(;
i
<
functionSignatureD
isplayParts
.
length
;
++
i
)
{
const
part
=
d
isplayParts
[
i
];
const
part
=
functionSignatureD
isplayParts
[
i
];
// Only take top level paren names
// Only take top level paren names
if
(
part
.
kind
===
'
parameterName
'
&&
parenCount
===
1
)
{
if
(
part
.
kind
===
'
parameterName
'
&&
parenCount
===
1
)
{
const
next
=
d
isplayParts
[
i
+
1
];
const
next
=
functionSignatureD
isplayParts
[
i
+
1
];
// Skip optional parameters
// Skip optional parameters
const
nameIsFollowedByOptionalIndicator
=
next
&&
next
.
text
===
'
?
'
;
const
nameIsFollowedByOptionalIndicator
=
next
&&
next
.
text
===
'
?
'
;
if
(
!
nameIsFollowedByOptionalIndicator
)
{
if
(
!
nameIsFollowedByOptionalIndicator
)
{
...
@@ -684,6 +684,43 @@ export function snippetForFunctionCall(
...
@@ -684,6 +684,43 @@ export function snippetForFunctionCall(
return
snippet
;
return
snippet
;
}
}
function
getFunctionSignatureDisplayParts
(
displayParts
:
ReadonlyArray
<
Proto
.
SymbolDisplayPart
>
,
label
:
string
,
):
ReadonlyArray
<
Proto
.
SymbolDisplayPart
>
{
let
start
:
number
|
undefined
;
let
end
:
number
|
undefined
;
let
index
=
0
;
let
nestingLevel
=
0
;
for
(;
index
<
displayParts
.
length
;
++
index
)
{
const
part
=
displayParts
[
index
];
if
(
part
.
kind
===
'
methodName
'
||
part
.
kind
===
'
functionName
'
||
part
.
kind
===
'
text
'
&&
part
.
text
===
label
)
{
if
(
nestingLevel
===
0
)
{
start
=
index
;
}
}
else
if
(
part
.
kind
===
'
punctuation
'
)
{
switch
(
part
.
text
)
{
case
'
(
'
:
++
nestingLevel
;
break
;
case
'
)
'
:
--
nestingLevel
;
if
(
nestingLevel
<=
0
)
{
end
=
index
;
}
break
;
}
}
}
if
(
typeof
start
===
'
number
'
&&
typeof
end
===
'
number
'
)
{
return
displayParts
.
slice
(
start
,
end
);
}
return
[];
}
function
shouldExcludeCompletionEntry
(
function
shouldExcludeCompletionEntry
(
element
:
Proto
.
CompletionEntry
,
element
:
Proto
.
CompletionEntry
,
completionConfiguration
:
CompletionConfiguration
completionConfiguration
:
CompletionConfiguration
...
...
extensions/typescript-language-features/src/test/functionCallSnippet.test.ts
浏览文件 @
d5843e55
...
@@ -81,7 +81,7 @@ suite('typescript function call snippets', () => {
...
@@ -81,7 +81,7 @@ suite('typescript function call snippets', () => {
'
foo(${1:a}, ${2:b})$0
'
);
'
foo(${1:a}, ${2:b})$0
'
);
});
});
test
(
'
Should skip over return type
'
,
async
()
=>
{
test
(
'
Should skip over return type
while extracting parameters
'
,
async
()
=>
{
assert
.
strictEqual
(
assert
.
strictEqual
(
snippetForFunctionCall
(
snippetForFunctionCall
(
{
label
:
'
foo
'
},
{
label
:
'
foo
'
},
...
@@ -89,4 +89,13 @@ suite('typescript function call snippets', () => {
...
@@ -89,4 +89,13 @@ suite('typescript function call snippets', () => {
).
value
,
).
value
,
'
foo(${1:a})$0
'
);
'
foo(${1:a})$0
'
);
});
});
test
(
'
Should skip over prefix type while extracting parameters
'
,
async
()
=>
{
assert
.
strictEqual
(
snippetForFunctionCall
(
{
label
:
'
foo
'
},
[{
"
text
"
:
"
(
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
method
"
,
"
kind
"
:
"
text
"
},
{
"
text
"
:
"
)
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
Array
"
,
"
kind
"
:
"
localName
"
},
{
"
text
"
:
"
<
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
{
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
dispose
"
,
"
kind
"
:
"
methodName
"
},
{
"
text
"
:
"
(
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
)
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
:
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
any
"
,
"
kind
"
:
"
keyword
"
},
{
"
text
"
:
"
;
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
}
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
>
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
.
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
foo
"
,
"
kind
"
:
"
methodName
"
},
{
"
text
"
:
"
(
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
searchElement
"
,
"
kind
"
:
"
parameterName
"
},
{
"
text
"
:
"
:
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
{
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
\n
"
,
"
kind
"
:
"
lineBreak
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
dispose
"
,
"
kind
"
:
"
methodName
"
},
{
"
text
"
:
"
(
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
)
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
:
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
any
"
,
"
kind
"
:
"
keyword
"
},
{
"
text
"
:
"
;
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
\n
"
,
"
kind
"
:
"
lineBreak
"
},
{
"
text
"
:
"
}
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
,
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
fromIndex
"
,
"
kind
"
:
"
parameterName
"
},
{
"
text
"
:
"
?
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
:
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
number
"
,
"
kind
"
:
"
keyword
"
},
{
"
text
"
:
"
)
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
:
"
,
"
kind
"
:
"
punctuation
"
},
{
"
text
"
:
"
"
,
"
kind
"
:
"
space
"
},
{
"
text
"
:
"
number
"
,
"
kind
"
:
"
keyword
"
}]
).
value
,
'
foo(${1:searchElement}$2)$0
'
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录