Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
946b275e
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,体验更适合开发者的 AI 搜索 >>
提交
946b275e
编写于
11月 20, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restrict where jsdoc completion is shown
Fixes #33948
上级
4df58c09
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
62 addition
and
21 deletion
+62
-21
extensions/typescript/src/features/jsDocCompletionProvider.ts
...nsions/typescript/src/features/jsDocCompletionProvider.ts
+62
-21
未找到文件。
extensions/typescript/src/features/jsDocCompletionProvider.ts
浏览文件 @
946b275e
...
...
@@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Position
,
Range
,
CompletionItemProvider
,
CompletionItemKind
,
TextDocument
,
CancellationToken
,
CompletionItem
,
window
,
Uri
,
ProviderResult
,
TextEditor
,
SnippetString
,
workspace
}
from
'
vscode
'
;
import
{
Position
,
Range
,
CompletionItemProvider
,
CompletionItemKind
,
TextDocument
,
CancellationToken
,
CompletionItem
,
window
,
Uri
,
TextEditor
,
SnippetString
,
workspace
}
from
'
vscode
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
{
DocCommandTemplateResponse
}
from
'
../protocol
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
vsPositionToTsFileLocation
}
from
'
../utils/convert
'
;
import
{
vsPositionToTsFileLocation
,
tsTextSpanToVsRange
}
from
'
../utils/convert
'
;
import
{
Command
,
CommandManager
}
from
'
../utils/commandManager
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -55,25 +55,57 @@ export default class JsDocCompletionProvider implements CompletionItemProvider {
commandManager
.
register
(
new
TryCompleteJsDocCommand
(
client
));
}
public
provideCompletionItems
(
public
async
provideCompletionItems
(
document
:
TextDocument
,
position
:
Position
,
_
token
:
CancellationToken
):
Pro
viderResult
<
CompletionItem
[]
>
{
token
:
CancellationToken
):
Pro
mise
<
CompletionItem
[]
>
{
const
file
=
this
.
client
.
normalizePath
(
document
.
uri
);
if
(
!
file
)
{
return
[];
}
// TODO: unregister provider when disabled
const
enableJsDocCompletions
=
workspace
.
getConfiguration
(
configurationNamespace
,
document
.
uri
).
get
<
boolean
>
(
Configuration
.
enabled
,
true
);
if
(
!
enableJsDocCompletions
)
{
return
[];
}
// Only show the JSdoc completion when the everything before the cursor is whitespace
// or could be the opening of a comment
const
line
=
document
.
lineAt
(
position
.
line
).
text
;
const
prefix
=
line
.
slice
(
0
,
position
.
character
);
if
(
prefix
.
match
(
/^
\s
*$|
\/\*\*\s
*$|^
\s
*
\/\*\*
+
\s
*$/
))
{
const
enableJsDocCompletions
=
workspace
.
getConfiguration
(
configurationNamespace
,
document
.
uri
).
get
<
boolean
>
(
Configuration
.
enabled
,
true
);
return
[
new
JsDocCompletionItem
(
document
,
position
,
enableJsDocCompletions
)];
if
(
prefix
.
match
(
/^
\s
*$|
\/\*\*\s
*$|^
\s
*
\/\*\*
+
\s
*$/
)
===
null
)
{
return
[];
}
const
args
:
Proto
.
FileRequestArgs
=
{
file
};
const
response
=
await
this
.
client
.
execute
(
'
navtree
'
,
args
,
token
);
if
(
!
response
.
body
)
{
return
[];
}
const
body
=
response
.
body
;
function
matchesPosition
(
tree
:
Proto
.
NavigationTree
):
boolean
{
if
(
!
tree
.
spans
.
length
)
{
return
false
;
}
const
span
=
tsTextSpanToVsRange
(
tree
.
spans
[
0
]);
if
(
position
.
line
===
span
.
start
.
line
-
1
||
position
.
line
===
span
.
start
.
line
)
{
return
true
;
}
return
tree
.
childItems
?
tree
.
childItems
.
some
(
matchesPosition
)
:
false
;
}
if
(
!
matchesPosition
(
body
))
{
return
[];
}
return
[];
return
[
new
JsDocCompletionItem
(
document
,
position
,
enableJsDocCompletions
)];
}
public
resolveCompletionItem
(
item
:
CompletionItem
,
_token
:
CancellationToken
)
{
...
...
@@ -115,23 +147,32 @@ class TryCompleteJsDocCommand implements Command {
return
this
.
tryInsertDefaultDoc
(
editor
,
start
);
}
private
tryInsertJsDocFromTemplate
(
editor
:
TextEditor
,
file
:
string
,
position
:
Position
):
Promise
<
boolean
>
{
private
async
tryInsertJsDocFromTemplate
(
editor
:
TextEditor
,
file
:
string
,
position
:
Position
):
Promise
<
boolean
>
{
const
snippet
=
await
TryCompleteJsDocCommand
.
getSnippetTemplate
(
this
.
client
,
file
,
position
);
if
(
!
snippet
)
{
return
false
;
}
return
editor
.
insertSnippet
(
snippet
,
position
,
{
undoStopBefore
:
false
,
undoStopAfter
:
true
});
}
public
static
getSnippetTemplate
(
client
:
ITypeScriptServiceClient
,
file
:
string
,
position
:
Position
):
Promise
<
SnippetString
|
undefined
>
{
const
args
=
vsPositionToTsFileLocation
(
file
,
position
);
return
Promise
.
race
([
this
.
client
.
execute
(
'
docCommentTemplate
'
,
args
),
new
Promise
<
DocCommandTemplateResponse
>
((
_
,
reject
)
=>
setTimeout
(
reject
,
250
))
]).
then
((
res
:
DocCommandTemplateResponse
)
=>
{
client
.
execute
(
'
docCommentTemplate
'
,
args
),
new
Promise
<
Proto
.
DocCommandTemplateResponse
>
((
_
,
reject
)
=>
setTimeout
(
reject
,
250
))
]).
then
((
res
:
Proto
.
DocCommandTemplateResponse
)
=>
{
if
(
!
res
||
!
res
.
body
)
{
return
false
;
return
undefined
;
}
return
editor
.
insertSnippet
(
this
.
templateToSnippet
(
res
.
body
.
newText
),
position
,
{
undoStopBefore
:
false
,
undoStopAfter
:
true
});
},
()
=>
false
);
return
TryCompleteJsDocCommand
.
templateToSnippet
(
res
.
body
.
newText
);
},
()
=>
undefined
);
}
private
templateToSnippet
(
template
:
string
):
SnippetString
{
private
static
templateToSnippet
(
template
:
string
):
SnippetString
{
// TODO: use append placeholder
let
snippetIndex
=
1
;
template
=
template
.
replace
(
/^
\s
*
(?=(\/
|
[
]\*))
/gm
,
''
);
template
=
template
.
replace
(
/^
(\/\*\*\s
*
\*[
]
*
)
$/m
,
(
x
)
=>
x
+
`
\$
0`
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录