Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
c9147062
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c9147062
编写于
10月 25, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
speed up getSnippets, getSnippetsSync, and updateSnippets, #36427
上级
1a4f6b9f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
36 deletion
+60
-36
src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts
...kbench/parts/snippets/electron-browser/snippetsService.ts
+21
-10
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
...orkbench/parts/snippets/electron-browser/tabCompletion.ts
+39
-26
未找到文件。
src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts
浏览文件 @
c9147062
...
...
@@ -95,13 +95,15 @@ class SnippetsService implements ISnippetsService {
private
readonly
_extensionSnippets
=
new
Map
<
LanguageId
,
Snippet
[]
>
();
private
readonly
_userSnippets
=
new
Map
<
LanguageId
,
Snippet
[]
>
();
private
readonly
_userSnippetsFolder
:
string
;
private
readonly
_wait
:
Promise
<
any
>
;
private
readonly
_disposables
:
IDisposable
[]
=
[];
constructor
(
@
IModeService
readonly
_modeService
:
IModeService
,
@
IExtensionService
readonly
_
extensionService
:
IExtensionService
,
@
IExtensionService
extensionService
:
IExtensionService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
)
{
this
.
_wait
=
Promise
.
resolve
(
extensionService
.
onReady
());
this
.
_userSnippetsFolder
=
join
(
environmentService
.
appSettingsHome
,
'
snippets
'
);
this
.
_prepUserSnippetsWatching
();
this
.
_prepExtensionSnippets
();
...
...
@@ -115,25 +117,34 @@ class SnippetsService implements ISnippetsService {
getSnippets
(
languageId
:
LanguageId
):
Promise
<
Snippet
[]
>
{
let
result
:
Snippet
[]
=
[];
return
Promise
.
all
([
this
.
_extensionService
.
onReady
(),
this
.
_getOrLoadUserSnippets
(
languageId
,
result
),
this
.
_getOrLoadExtensionSnippets
(
languageId
,
result
)
]
).
then
(()
=>
{
return
this
.
_wait
.
then
(()
=>
{
return
this
.
_getOrLoadUserSnippets
(
languageId
,
result
);
}).
then
(()
=>
{
return
this
.
_getOrLoadExtensionSnippets
(
languageId
,
result
);
}
).
then
(()
=>
{
return
result
;
});
}
getSnippetsSync
(
languageId
:
LanguageId
):
Snippet
[]
{
// just kick off snippet loading for this language such
// that subseqent calls to this method return more
// that subseq
u
ent calls to this method return more
// correct results
this
.
getSnippets
(
languageId
).
catch
(
undefined
);
// collect and return what we already have
let
userSnippets
=
this
.
_userSnippets
.
get
(
languageId
);
let
extensionSnippets
=
this
.
_extensionSnippets
.
get
(
languageId
);
return
(
userSnippets
||
[]).
concat
(
extensionSnippets
||
[]);
const
userSnippets
=
this
.
_userSnippets
.
get
(
languageId
);
const
extensionSnippets
=
this
.
_extensionSnippets
.
get
(
languageId
);
if
(
userSnippets
&&
extensionSnippets
)
{
return
userSnippets
.
concat
(
extensionSnippets
);
}
else
if
(
!
userSnippets
)
{
return
extensionSnippets
;
}
else
if
(
!
extensionSnippets
)
{
return
userSnippets
;
}
else
{
return
undefined
;
}
}
// --- extension snippet logic ---
...
...
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
浏览文件 @
c9147062
...
...
@@ -15,6 +15,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import
{
endsWith
}
from
'
vs/base/common/strings
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
CommonEditorRegistry
,
commonEditorContribution
,
EditorCommand
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
SnippetController2
}
from
'
vs/editor/contrib/snippet/browser/snippetController2
'
;
import
{
showSimpleSuggestions
}
from
'
vs/editor/contrib/suggest/browser/suggest
'
;
...
...
@@ -32,9 +33,8 @@ export class TabCompletionController implements editorCommon.IEditorContribution
return
editor
.
getContribution
<
TabCompletionController
>
(
TabCompletionController
.
ID
);
}
private
readonly
_hasSnippets
:
IContextKey
<
boolean
>
;
private
_snippets
:
Snippet
[]
=
[];
private
_hasSnippets
:
IContextKey
<
boolean
>
;
private
_activeSnippets
:
Snippet
[]
=
[];
private
_selectionListener
:
IDisposable
;
private
_configListener
:
IDisposable
;
...
...
@@ -68,53 +68,66 @@ export class TabCompletionController implements editorCommon.IEditorContribution
dispose
(
this
.
_selectionListener
);
}
else
{
this
.
_selectionListener
=
this
.
_editor
.
onDidChangeCursorSelection
(
e
=>
this
.
_updateSnippets
());
this
.
_updateSnippets
();
if
(
this
.
_editor
.
getModel
())
{
this
.
_updateSnippets
();
}
}
}
private
_updateSnippets
():
void
{
let
selection
=
this
.
_editor
.
getSelection
();
let
model
=
this
.
_editor
.
getModel
();
let
selectFn
:
(
snippet
:
Snippet
)
=>
boolean
;
// reset first
this
.
_activeSnippets
=
[];
if
(
!
selection
||
!
model
)
{
// too early
// lots of dance for getting the
const
selection
=
this
.
_editor
.
getSelection
();
const
model
=
this
.
_editor
.
getModel
();
model
.
tokenizeIfCheap
(
selection
.
positionLineNumber
);
const
id
=
model
.
getLanguageIdAtPosition
(
selection
.
positionLineNumber
,
selection
.
positionColumn
);
const
snippets
=
this
.
_snippetService
.
getSnippetsSync
(
id
);
if
(
!
snippets
)
{
// nothing for this language
this
.
_hasSnippets
.
set
(
false
);
this
.
_snippets
=
undefined
;
return
;
}
if
(
selection
.
isEmpty
(
))
{
if
(
Range
.
isEmpty
(
selection
))
{
// empty selection -> real text (no whitespace) left of cursor
const
prefix
=
getNonWhitespacePrefix
(
model
,
this
.
_editor
.
getPosition
());
selectFn
=
prefix
&&
(
snippet
=>
endsWith
(
prefix
,
snippet
.
prefix
));
const
prefix
=
getNonWhitespacePrefix
(
model
,
selection
.
getPosition
());
if
(
prefix
)
{
for
(
const
snippet
of
snippets
)
{
if
(
endsWith
(
prefix
,
snippet
.
prefix
))
{
this
.
_activeSnippets
.
push
(
snippet
);
}
}
}
}
else
if
(
selection
.
startLineNumber
===
selection
.
endLineNumber
&&
model
.
getValueLengthInRange
(
selection
)
<=
100
)
{
}
else
if
(
!
Range
.
spansMultipleLines
(
selection
)
&&
model
.
getValueLengthInRange
(
selection
)
<=
100
)
{
// actual selection -> snippet must be a full match
const
selected
=
model
.
getValueInRange
(
selection
);
selectFn
=
snippet
=>
selected
===
snippet
.
prefix
;
}
if
(
selectFn
)
{
model
.
tokenizeIfCheap
(
selection
.
positionLineNumber
);
const
id
=
model
.
getLanguageIdAtPosition
(
selection
.
positionLineNumber
,
selection
.
positionColumn
);
this
.
_snippets
=
this
.
_snippetService
.
getSnippetsSync
(
id
).
filter
(
selectFn
);
if
(
selected
)
{
for
(
const
snippet
of
snippets
)
{
if
(
selected
===
snippet
.
prefix
)
{
this
.
_activeSnippets
.
push
(
snippet
);
}
}
}
}
this
.
_hasSnippets
.
set
(
this
.
_
snippets
&&
this
.
_s
nippets
.
length
>
0
);
this
.
_hasSnippets
.
set
(
this
.
_
activeS
nippets
.
length
>
0
);
}
performSnippetCompletions
():
void
{
if
(
this
.
_
s
nippets
.
length
===
1
)
{
if
(
this
.
_
activeS
nippets
.
length
===
1
)
{
// one -> just insert
const
[
snippet
]
=
this
.
_
s
nippets
;
const
[
snippet
]
=
this
.
_
activeS
nippets
;
SnippetController2
.
get
(
this
.
_editor
).
insert
(
snippet
.
codeSnippet
,
snippet
.
prefix
.
length
,
0
);
}
else
if
(
this
.
_
s
nippets
.
length
>
1
)
{
}
else
if
(
this
.
_
activeS
nippets
.
length
>
1
)
{
// two or more -> show IntelliSense box
showSimpleSuggestions
(
this
.
_editor
,
this
.
_
s
nippets
.
map
(
snippet
=>
new
SnippetSuggestion
(
snippet
,
snippet
.
prefix
.
length
)));
showSimpleSuggestions
(
this
.
_editor
,
this
.
_
activeS
nippets
.
map
(
snippet
=>
new
SnippetSuggestion
(
snippet
,
snippet
.
prefix
.
length
)));
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录