Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
9a97cb10
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,发现更多精彩内容 >>
提交
9a97cb10
编写于
2月 20, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make SnippetRegistry a service, move things to workbench layer, preps #20764
上级
2fe6ff47
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
73 addition
and
74 deletion
+73
-74
src/vs/editor/contrib/suggest/common/suggest.ts
src/vs/editor/contrib/suggest/common/suggest.ts
+10
-19
src/vs/workbench/api/node/extHost.contribution.ts
src/vs/workbench/api/node/extHost.contribution.ts
+0
-2
src/vs/workbench/parts/snippets/electron-browser/TMSnippets.ts
...s/workbench/parts/snippets/electron-browser/TMSnippets.ts
+15
-13
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
...orkbench/parts/snippets/electron-browser/insertSnippet.ts
+8
-8
src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts
.../parts/snippets/electron-browser/snippets.contribution.ts
+5
-0
src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts
...kbench/parts/snippets/electron-browser/snippetsService.ts
+25
-24
src/vs/workbench/parts/snippets/electron-browser/snippetsTracker.ts
...kbench/parts/snippets/electron-browser/snippetsTracker.ts
+4
-2
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
...orkbench/parts/snippets/electron-browser/tabCompletion.ts
+4
-5
src/vs/workbench/parts/snippets/test/electron-browser/snippetsRegistry.test.ts
...s/snippets/test/electron-browser/snippetsRegistry.test.ts
+2
-1
未找到文件。
src/vs/editor/contrib/suggest/common/suggest.ts
浏览文件 @
9a97cb10
...
...
@@ -13,9 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
IModel
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
ISuggestResult
,
ISuggestSupport
,
ISuggestion
,
SuggestRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
ISnippetsRegistry
,
Extensions
}
from
'
vs/editor/common/modes/snippetsRegistry
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
DefaultConfig
}
from
'
vs/editor/common/config/defaultConfig
'
;
...
...
@@ -36,20 +34,13 @@ export interface ISuggestionItem {
export
type
SnippetConfig
=
'
top
'
|
'
bottom
'
|
'
inline
'
|
'
none
'
;
let
_snippetSuggestSupport
:
ISuggestSupport
;
// add suggestions from snippet registry.
export
const
snippetSuggestSupport
:
ISuggestSupport
=
{
triggerCharacters
:
[],
provideCompletionItems
(
model
:
IModel
,
position
:
Position
):
ISuggestResult
{
const
suggestions
=
Registry
.
as
<
ISnippetsRegistry
>
(
Extensions
.
Snippets
).
getSnippetCompletions
(
model
,
position
);
if
(
suggestions
)
{
return
{
suggestions
};
}
return
undefined
;
}
};
export
function
setSnippetSuggestSupport
(
support
:
ISuggestSupport
):
ISuggestSupport
{
const
old
=
_snippetSuggestSupport
;
_snippetSuggestSupport
=
support
;
return
old
;
}
export
function
provideSuggestionItems
(
model
:
IModel
,
position
:
Position
,
snippetConfig
:
SnippetConfig
=
'
bottom
'
,
onlyFrom
?:
ISuggestSupport
[]):
TPromise
<
ISuggestionItem
[]
>
{
...
...
@@ -62,8 +53,8 @@ export function provideSuggestionItems(model: IModel, position: Position, snippe
const
supports
=
SuggestRegistry
.
orderedGroups
(
model
);
// add snippets provider unless turned off
if
(
snippetConfig
!==
'
none
'
)
{
supports
.
unshift
([
snippetSuggestSupport
]);
if
(
snippetConfig
!==
'
none
'
&&
_snippetSuggestSupport
)
{
supports
.
unshift
([
_
snippetSuggestSupport
]);
}
// add suggestions from contributed providers - providers are ordered in groups of
...
...
@@ -103,7 +94,7 @@ export function provideSuggestionItems(model: IModel, position: Position, snippe
}
}
if
(
len
!==
allSuggestions
.
length
&&
support
!==
snippetSuggestSupport
)
{
if
(
len
!==
allSuggestions
.
length
&&
support
!==
_
snippetSuggestSupport
)
{
hasResult
=
true
;
}
...
...
@@ -217,7 +208,7 @@ CommonEditorRegistry.registerDefaultLanguageCommand('_executeCompletionItemProvi
return
provideSuggestionItems
(
model
,
position
).
then
(
items
=>
{
for
(
const
{
container
,
suggestion
}
of
items
)
{
for
(
const
{
container
,
suggestion
}
of
items
)
{
result
.
incomplete
=
result
.
incomplete
||
container
.
incomplete
;
result
.
suggestions
.
push
(
suggestion
);
}
...
...
src/vs/workbench/api/node/extHost.contribution.ts
浏览文件 @
9a97cb10
...
...
@@ -36,7 +36,6 @@ import { MainThreadFileSystemEventService } from './mainThreadFileSystemEventSer
import
{
MainThreadSCM
}
from
'
./mainThreadSCM
'
;
// --- other interested parties
import
{
MainProcessTextMateSnippet
}
from
'
vs/editor/node/textMate/TMSnippets
'
;
import
{
JSONValidationExtensionPoint
}
from
'
vs/platform/jsonschemas/common/jsonValidationExtensionPoint
'
;
import
{
LanguageConfigurationFileHandler
}
from
'
vs/editor/node/languageConfigurationExtensionPoint
'
;
import
{
SaveParticipant
}
from
'
./mainThreadSaveParticipant
'
;
...
...
@@ -90,7 +89,6 @@ export class ExtHostContribution implements IWorkbenchContribution {
col
.
finish
(
true
,
this
.
threadService
);
// Other interested parties
create
(
MainProcessTextMateSnippet
);
create
(
JSONValidationExtensionPoint
);
this
.
instantiationService
.
createInstance
(
LanguageConfigurationFileHandler
);
create
(
MainThreadFileSystemEventService
);
...
...
src/vs/
editor/node/textMate
/TMSnippets.ts
→
src/vs/
workbench/parts/snippets/electron-browser
/TMSnippets.ts
浏览文件 @
9a97cb10
...
...
@@ -5,18 +5,18 @@
'
use strict
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
IWorkbenchContribution
}
from
'
vs/workbench/common/contributions
'
;
import
{
parse
}
from
'
vs/base/common/json
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
ExtensionMessageCollector
,
ExtensionsRegistry
}
from
'
vs/platform/extensions/common/extensionsRegistry
'
;
import
{
ISnippets
Registry
,
Extensions
,
ISnippet
}
from
'
vs/editor/common/modes/snippetsRegistry
'
;
import
{
ISnippets
Service
,
ISnippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
platform
=
require
(
'
vs/platform/platform
'
);
import
{
languagesExtPoint
}
from
'
vs/editor/common/services/modeServiceImpl
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
export
interface
ISnippetsExtensionPoint
{
interface
ISnippetsExtensionPoint
{
language
:
string
;
path
:
string
;
}
...
...
@@ -41,12 +41,12 @@ let snippetsExtensionPoint = ExtensionsRegistry.registerExtensionPoint<ISnippets
}
});
export
class
MainProcessTextMateSnippet
{
private
_modeService
:
IModeService
;
constructor
(
@
IModeService
modeService
:
IModeService
)
{
this
.
_modeService
=
modeService
;
export
class
MainProcessTextMateSnippet
implements
IWorkbenchContribution
{
constructor
(
@
IModeService
private
_modeService
:
IModeService
,
@
ISnippetsService
private
_snippetService
:
ISnippetsService
)
{
snippetsExtensionPoint
.
setHandler
((
extensions
)
=>
{
for
(
let
i
=
0
;
i
<
extensions
.
length
;
i
++
)
{
let
tmSnippets
=
extensions
[
i
].
value
;
...
...
@@ -57,6 +57,10 @@ export class MainProcessTextMateSnippet {
});
}
getId
()
{
return
'
tmSnippetExtension
'
;
}
private
_withSnippetContribution
(
extensionName
:
string
,
extensionFolderPath
:
string
,
snippet
:
ISnippetsExtensionPoint
,
collector
:
ExtensionMessageCollector
):
void
{
if
(
!
snippet
.
language
||
(
typeof
snippet
.
language
!==
'
string
'
)
||
!
this
.
_modeService
.
isRegisteredMode
(
snippet
.
language
))
{
collector
.
error
(
nls
.
localize
(
'
invalid.language
'
,
"
Unknown language in `contributes.{0}.language`. Provided value: {1}
"
,
snippetsExtensionPoint
.
name
,
String
(
snippet
.
language
)));
...
...
@@ -79,19 +83,17 @@ export class MainProcessTextMateSnippet {
if
(
mode
.
getId
()
!==
modeId
)
{
return
;
}
readAndRegisterSnippets
(
languageIdentifier
,
normalizedAbsolutePath
,
extensionName
);
readAndRegisterSnippets
(
this
.
_snippetService
,
languageIdentifier
,
normalizedAbsolutePath
,
extensionName
);
disposable
.
dispose
();
});
}
}
}
let
snippetsRegistry
=
<
ISnippetsRegistry
>
platform
.
Registry
.
as
(
Extensions
.
Snippets
);
export
function
readAndRegisterSnippets
(
languageIdentifier
:
LanguageIdentifier
,
filePath
:
string
,
ownerName
:
string
):
TPromise
<
void
>
{
export
function
readAndRegisterSnippets
(
snippetService
:
ISnippetsService
,
languageIdentifier
:
LanguageIdentifier
,
filePath
:
string
,
ownerName
:
string
):
TPromise
<
void
>
{
return
readFile
(
filePath
).
then
(
fileContents
=>
{
let
snippets
=
parseSnippetFile
(
fileContents
.
toString
(),
ownerName
);
snippet
sRegistry
.
registerSnippets
(
languageIdentifier
,
snippets
,
filePath
);
snippet
Service
.
registerSnippets
(
languageIdentifier
,
snippets
,
filePath
);
});
}
...
...
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
浏览文件 @
9a97cb10
...
...
@@ -5,16 +5,15 @@
'
use strict
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ICommonCodeEditor
,
EditorContextKeys
}
from
'
vs/editor/common/editorCommon
'
;
import
{
editorAction
,
ServicesAccessor
,
EditorAction
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
SnippetController
}
from
'
vs/editor/contrib/snippet/common/snippetController
'
;
import
{
IQuickOpenService
,
IPickOpenEntry
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
ISnippetsRegistry
,
Extensions
,
ISnippet
}
from
'
vs/editor/common/modes/snippetsRegistry
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
LanguageId
}
from
'
vs/editor/common/modes
'
;
import
{
ICommandService
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ISnippetsService
,
ISnippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
interface
ISnippetPick
extends
IPickOpenEntry
{
snippet
:
ISnippet
;
...
...
@@ -26,7 +25,7 @@ class Args {
if
(
!
arg
||
typeof
arg
!==
'
object
'
)
{
return
Args
.
_empty
;
}
let
{
snippet
,
name
,
langId
}
=
arg
;
let
{
snippet
,
name
,
langId
}
=
arg
;
if
(
typeof
snippet
!==
'
string
'
)
{
snippet
=
undefined
;
}
...
...
@@ -65,14 +64,15 @@ class InsertSnippetAction extends EditorAction {
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICommonCodeEditor
,
arg
:
any
):
TPromise
<
void
>
{
const
modeService
=
accessor
.
get
(
IModeService
);
const
snippetService
=
accessor
.
get
(
ISnippetsService
);
if
(
!
editor
.
getModel
())
{
return
undefined
;
}
const
quickOpenService
=
accessor
.
get
(
IQuickOpenService
);
const
{
lineNumber
,
column
}
=
editor
.
getPosition
();
let
{
snippet
,
name
,
langId
}
=
Args
.
fromUser
(
arg
);
const
{
lineNumber
,
column
}
=
editor
.
getPosition
();
let
{
snippet
,
name
,
langId
}
=
Args
.
fromUser
(
arg
);
return
new
TPromise
<
ISnippet
>
((
resolve
,
reject
)
=>
{
...
...
@@ -96,7 +96,7 @@ class InsertSnippetAction extends EditorAction {
// validate the `languageId` to ensure this is a user
// facing language with a name and the chance to have
// snippets, else fall back to the outer language
const
{
language
}
=
modeService
.
getLanguageIdentifier
(
languageId
);
const
{
language
}
=
modeService
.
getLanguageIdentifier
(
languageId
);
if
(
!
modeService
.
getLanguageName
(
language
))
{
languageId
=
editor
.
getModel
().
getLanguageIdentifier
().
id
;
}
...
...
@@ -104,7 +104,7 @@ class InsertSnippetAction extends EditorAction {
if
(
name
)
{
// take selected snippet
Registry
.
as
<
ISnippetsRegistry
>
(
Extensions
.
Snippets
)
.
visitSnippets
(
languageId
,
snippet
=>
{
snippetService
.
visitSnippets
(
languageId
,
snippet
=>
{
if
(
snippet
.
name
!==
name
)
{
return
true
;
}
...
...
@@ -114,7 +114,7 @@ class InsertSnippetAction extends EditorAction {
}
else
{
// let user pick a snippet
const
picks
:
ISnippetPick
[]
=
[];
Registry
.
as
<
ISnippetsRegistry
>
(
Extensions
.
Snippets
)
.
visitSnippets
(
languageId
,
snippet
=>
{
snippetService
.
visitSnippets
(
languageId
,
snippet
=>
{
picks
.
push
({
label
:
snippet
.
prefix
,
detail
:
snippet
.
description
,
...
...
src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts
浏览文件 @
9a97cb10
...
...
@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
import
'
vs/workbench/parts/snippets/electron-browser/insertSnippet
'
;
import
'
vs/workbench/parts/snippets/electron-browser/tabCompletion
'
;
...
...
@@ -16,6 +17,7 @@ import platform = require('vs/platform/platform');
import
workbenchActionRegistry
=
require
(
'
vs/workbench/common/actionRegistry
'
);
import
workbenchContributions
=
require
(
'
vs/workbench/common/contributions
'
);
import
snippetsTracker
=
require
(
'
./snippetsTracker
'
);
import
tmSnippets
=
require
(
'
./TMSnippets
'
);
import
*
as
pfs
from
'
vs/base/node/pfs
'
;
import
errors
=
require
(
'
vs/base/common/errors
'
);
import
{
IQuickOpenService
,
IPickOpenEntry
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
...
...
@@ -121,6 +123,9 @@ workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenSn
(
<
workbenchContributions
.
IWorkbenchContributionsRegistry
>
platform
.
Registry
.
as
(
workbenchContributions
.
Extensions
.
Workbench
)).
registerWorkbenchContribution
(
snippetsTracker
.
SnippetsTracker
);
(
<
workbenchContributions
.
IWorkbenchContributionsRegistry
>
platform
.
Registry
.
as
(
workbenchContributions
.
Extensions
.
Workbench
)).
registerWorkbenchContribution
(
tmSnippets
.
MainProcessTextMateSnippet
);
let
schemaId
=
'
vscode://schemas/snippets
'
;
let
schema
:
IJSONSchema
=
{
...
...
src/vs/
editor/common/modes/snippetsRegistry
.ts
→
src/vs/
workbench/parts/snippets/electron-browser/snippetsService
.ts
浏览文件 @
9a97cb10
...
...
@@ -6,31 +6,21 @@
import
{
localize
}
from
'
vs/nls
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
I
Tokenized
Model
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IModel
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ISuggestion
,
LanguageIdentifier
,
LanguageId
}
from
'
vs/editor/common/modes
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
setSnippetSuggestSupport
}
from
'
vs/editor/contrib/suggest/common/suggest
'
;
export
const
Extensions
=
{
Snippets
:
'
base.contributions.snippets
'
};
export
const
ISnippetsService
=
createDecorator
<
ISnippetsService
>
(
'
snippetService
'
);
export
interface
ISnippetsRegistry
{
export
interface
ISnippetsService
{
_serviceBrand
:
any
;
/**
* Register a snippet to the registry.
*/
registerSnippets
(
languageIdentifier
:
LanguageIdentifier
,
snippets
:
ISnippet
[],
owner
?:
string
):
void
;
/**
* Visit all snippets
*/
visitSnippets
(
languageId
:
LanguageId
,
accept
:
(
snippet
:
ISnippet
)
=>
void
):
void
;
/**
* Get all snippet completions for the given position
*/
getSnippetCompletions
(
model
:
ITokenizedModel
,
position
:
IPosition
):
ISuggestion
[];
}
export
interface
ISnippet
{
...
...
@@ -45,10 +35,22 @@ interface ISnippetSuggestion extends ISuggestion {
disambiguateLabel
:
string
;
}
class
SnippetsRegistry
implements
ISnippetsRegistry
{
class
SnippetsService
implements
ISnippetsService
{
_serviceBrand
:
any
;
private
_snippets
:
{
[
owner
:
string
]:
ISnippet
[]
}[]
=
[];
constructor
()
{
setSnippetSuggestSupport
({
triggerCharacters
:
undefined
,
provideCompletionItems
:
(
model
,
position
)
=>
{
const
suggestions
=
this
.
getSnippetCompletions
(
<
any
>
model
,
position
);
return
{
suggestions
};
}
});
}
public
registerSnippets
(
languageIdentifier
:
LanguageIdentifier
,
snippets
:
ISnippet
[],
owner
=
''
):
void
{
let
snippetsByMode
=
this
.
_snippets
[
languageIdentifier
.
id
];
if
(
!
snippetsByMode
)
{
...
...
@@ -69,7 +71,7 @@ class SnippetsRegistry implements ISnippetsRegistry {
}
}
public
getSnippetCompletions
(
model
:
I
Tokenized
Model
,
position
:
IPosition
):
ISuggestion
[]
{
public
getSnippetCompletions
(
model
:
IModel
,
position
:
IPosition
):
ISuggestion
[]
{
const
languageId
=
model
.
getLanguageIdAtPosition
(
position
.
lineNumber
,
position
.
column
);
if
(
!
this
.
_snippets
[
languageId
])
{
return
undefined
;
...
...
@@ -116,7 +118,7 @@ class SnippetsRegistry implements ISnippetsRegistry {
// dismbiguate suggestions with same labels
let
lastSuggestion
:
ISnippetSuggestion
;
for
(
const
suggestion
of
result
.
sort
(
Snippets
Registry
.
_compareSuggestionsByLabel
))
{
for
(
const
suggestion
of
result
.
sort
(
Snippets
Service
.
_compareSuggestionsByLabel
))
{
if
(
lastSuggestion
&&
lastSuggestion
.
label
===
suggestion
.
label
)
{
// use the disambiguateLabel instead of the actual label
lastSuggestion
.
label
=
lastSuggestion
.
disambiguateLabel
;
...
...
@@ -133,6 +135,8 @@ class SnippetsRegistry implements ISnippetsRegistry {
}
}
registerSingleton
(
ISnippetsService
,
SnippetsService
);
export
interface
ISimpleModel
{
getLineContent
(
lineNumber
):
string
;
}
...
...
@@ -161,6 +165,3 @@ export function getNonWhitespacePrefix(model: ISimpleModel, position: IPosition)
return
''
;
}
const
snippetsRegistry
:
ISnippetsRegistry
=
new
SnippetsRegistry
();
Registry
.
add
(
Extensions
.
Snippets
,
snippetsRegistry
);
src/vs/workbench/parts/snippets/electron-browser/snippetsTracker.ts
浏览文件 @
9a97cb10
...
...
@@ -13,7 +13,8 @@ import winjs = require('vs/base/common/winjs.base');
import
{
mkdirp
,
fileExists
,
readdir
}
from
'
vs/base/node/pfs
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
lifecycle
=
require
(
'
vs/base/common/lifecycle
'
);
import
{
readAndRegisterSnippets
}
from
'
vs/editor/node/textMate/TMSnippets
'
;
import
{
readAndRegisterSnippets
}
from
'
./TMSnippets
'
;
import
{
ISnippetsService
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
import
{
ILifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
...
...
@@ -31,6 +32,7 @@ export class SnippetsTracker implements workbenchExt.IWorkbenchContribution {
constructor
(
@
ILifecycleService
private
lifecycleService
:
ILifecycleService
,
@
IModeService
private
modeService
:
IModeService
,
@
ISnippetsService
private
snippetService
:
ISnippetsService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
IExtensionService
extensionService
:
IExtensionService
)
{
...
...
@@ -75,7 +77,7 @@ export class SnippetsTracker implements workbenchExt.IWorkbenchContribution {
var
snippetPath
=
paths
.
join
(
this
.
snippetFolder
,
snippetFile
);
let
languageIdentifier
=
this
.
modeService
.
getLanguageIdentifier
(
modeId
);
if
(
languageIdentifier
)
{
return
readAndRegisterSnippets
(
languageIdentifier
,
snippetPath
,
localize
(
'
userSnippet
'
,
"
User Snippet
"
));
return
readAndRegisterSnippets
(
this
.
snippetService
,
languageIdentifier
,
snippetPath
,
localize
(
'
userSnippet
'
,
"
User Snippet
"
));
}
return
undefined
;
}));
...
...
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
浏览文件 @
9a97cb10
...
...
@@ -9,7 +9,7 @@ import { localize } from 'vs/nls';
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
RawContextKey
,
IContextKeyService
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
ISnippets
Registry
,
Extensions
,
getNonWhitespacePrefix
,
ISnippet
}
from
'
vs/editor/common/modes/snippetsRegistry
'
;
import
{
ISnippets
Service
,
getNonWhitespacePrefix
,
ISnippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
endsWith
}
from
'
vs/base/common/strings
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
...
...
@@ -20,8 +20,6 @@ import { IConfigurationRegistry, Extensions as ConfigExt } from "vs/platform/con
import
EditorContextKeys
=
editorCommon
.
EditorContextKeys
;
let
snippetsRegistry
=
<
ISnippetsRegistry
>
Registry
.
as
(
Extensions
.
Snippets
);
@
commonEditorContribution
export
class
TabCompletionController
implements
editorCommon
.
IEditorContribution
{
...
...
@@ -38,7 +36,8 @@ export class TabCompletionController implements editorCommon.IEditorContribution
constructor
(
editor
:
editorCommon
.
ICommonCodeEditor
,
@
IContextKeyService
contextKeyService
:
IContextKeyService
@
IContextKeyService
contextKeyService
:
IContextKeyService
,
@
ISnippetsService
snippetService
:
ISnippetsService
)
{
this
.
_snippetController
=
SnippetController
.
get
(
editor
);
const
hasSnippets
=
TabCompletionController
.
ContextKey
.
bindTo
(
contextKeyService
);
...
...
@@ -59,7 +58,7 @@ export class TabCompletionController implements editorCommon.IEditorContribution
}
if
(
selectFn
)
{
snippet
sRegistry
.
visitSnippets
(
editor
.
getModel
().
getLanguageIdentifier
().
id
,
s
=>
{
snippet
Service
.
visitSnippets
(
editor
.
getModel
().
getLanguageIdentifier
().
id
,
s
=>
{
if
(
selectFn
(
s
))
{
this
.
_currentSnippets
.
push
(
s
);
}
...
...
src/vs/
editor/test/common/modes
/snippetsRegistry.test.ts
→
src/vs/
workbench/parts/snippets/test/electron-browser
/snippetsRegistry.test.ts
浏览文件 @
9a97cb10
...
...
@@ -6,7 +6,8 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
getNonWhitespacePrefix
}
from
'
vs/editor/common/modes/snippetsRegistry
'
;
import
{
getNonWhitespacePrefix
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
suite
(
'
getNonWhitespacePrefix
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录