Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
9e589be9
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,发现更多精彩内容 >>
提交
9e589be9
编写于
2月 16, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move SnippetsRegistry out of modesRegistry
上级
ebc76bdf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
85 deletion
+86
-85
src/vs/editor/common/modes/modesRegistry.ts
src/vs/editor/common/modes/modesRegistry.ts
+0
-80
src/vs/editor/common/modes/supports.ts
src/vs/editor/common/modes/supports.ts
+81
-0
src/vs/editor/contrib/suggest/common/suggest.ts
src/vs/editor/contrib/suggest/common/suggest.ts
+2
-2
src/vs/editor/node/textMate/TMSnippets.ts
src/vs/editor/node/textMate/TMSnippets.ts
+3
-3
未找到文件。
src/vs/editor/common/modes/modesRegistry.ts
浏览文件 @
9e589be9
...
...
@@ -5,8 +5,6 @@
'
use strict
'
;
import
Modes
=
require
(
'
vs/editor/common/modes
'
);
import
Strings
=
require
(
'
vs/base/common/strings
'
);
import
EditorCommon
=
require
(
'
vs/editor/common/editorCommon
'
);
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
ILanguageExtensionPoint
}
from
'
vs/editor/common/services/modeService
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
...
...
@@ -122,81 +120,3 @@ export function registerLanguage(def:ILanguageExtensionPoint): void {
export
function
registerWorkerParticipant
(
modeId
:
string
,
moduleId
:
string
,
ctorName
?:
string
):
void
{
mR
.
registerWorkerParticipant
(
modeId
,
moduleId
,
ctorName
);
}
// TODO@Martin: find a better home for this code:
// TODO@Martin: modify suggestSupport to return a boolean if snippets should be presented or not
// and turn this into a real registry
var
_defaultSnippets
:
{
[
modeId
:
string
]:
Modes
.
ISuggestion
[]
}
=
Object
.
create
(
null
);
var
_snippets
:
{
[
modeId
:
string
]:
{
[
path
:
string
]:
Modes
.
ISuggestion
[]
}
}
=
Object
.
create
(
null
);
export
function
registerDefaultSnippets
(
modeId
:
string
,
snippets
:
Modes
.
ISuggestion
[]):
void
{
_defaultSnippets
[
modeId
]
=
(
_defaultSnippets
[
modeId
]
||
[]).
concat
(
snippets
);
}
export
function
registerSnippets
(
modeId
:
string
,
path
:
string
,
snippets
:
Modes
.
ISuggestion
[]):
void
{
var
snippetsByMode
=
_snippets
[
modeId
];
if
(
!
snippetsByMode
)
{
_snippets
[
modeId
]
=
snippetsByMode
=
{};
}
snippetsByMode
[
path
]
=
snippets
;
}
export
function
getSnippets
(
model
:
EditorCommon
.
IModel
,
position
:
EditorCommon
.
IPosition
):
Modes
.
ISuggestResult
{
var
word
=
model
.
getWordAtPosition
(
position
);
var
currentPrefix
=
word
?
word
.
word
.
substring
(
0
,
position
.
column
-
word
.
startColumn
)
:
''
;
var
result
:
Modes
.
ISuggestResult
=
{
currentWord
:
currentPrefix
,
suggestions
:
[]
};
// to avoid that snippets are too prominent in the intellisense proposals:
// - force that the current prefix matches with the snippet prefix
// if there's no prfix, only show snippets at the beginning of the line, or after a whitespace
var
filter
=
null
;
if
(
currentPrefix
.
length
===
0
)
{
if
(
position
.
column
>
1
)
{
var
previousCharacter
=
model
.
getValueInRange
({
startLineNumber
:
position
.
lineNumber
,
startColumn
:
position
.
column
-
1
,
endLineNumber
:
position
.
lineNumber
,
endColumn
:
position
.
column
});
if
(
previousCharacter
.
trim
().
length
!==
0
)
{
return
result
;
}
}
}
else
{
var
lowerCasePrefix
=
currentPrefix
.
toLowerCase
();
filter
=
(
p
:
Modes
.
ISuggestion
)
=>
{
return
Strings
.
startsWith
(
p
.
label
.
toLowerCase
(),
lowerCasePrefix
);
};
}
var
modeId
=
model
.
getMode
().
getId
();
var
snippets
:
Modes
.
ISuggestion
[]
=
[];
var
snipppetsByMode
=
_snippets
[
modeId
];
if
(
snipppetsByMode
)
{
for
(
var
s
in
snipppetsByMode
)
{
snippets
=
snippets
.
concat
(
snipppetsByMode
[
s
]);
}
}
var
defaultSnippets
=
_defaultSnippets
[
modeId
];
if
(
defaultSnippets
)
{
snippets
=
snippets
.
concat
(
defaultSnippets
);
}
result
.
suggestions
=
filter
?
snippets
.
filter
(
filter
)
:
snippets
;
// if (result.suggestions.length > 0) {
// if (word) {
// // Push also the current word as first suggestion, to avoid unexpected snippet acceptance on Enter.
// result.suggestions = result.suggestions.slice(0);
// result.suggestions.unshift({
// codeSnippet: word.word,
// label: word.word,
// type: 'text'
// });
// }
// result.incomplete = true;
// }
return
result
;
}
src/vs/editor/common/modes/supports.ts
浏览文件 @
9e589be9
...
...
@@ -7,6 +7,7 @@
import
Strings
=
require
(
'
vs/base/common/strings
'
);
import
Modes
=
require
(
'
vs/editor/common/modes
'
);
import
{
Arrays
}
from
'
vs/editor/common/core/arrays
'
;
import
*
as
EditorCommon
from
'
vs/editor/common/editorCommon
'
;
export
class
Token
implements
Modes
.
IToken
{
public
startIndex
:
number
;
...
...
@@ -142,3 +143,83 @@ export class FilteredLineContext implements Modes.ILineContext {
export
function
ignoreBracketsInToken
(
tokenType
:
string
):
boolean
{
return
/
\b(
comment|string|regex
)\b
/
.
test
(
tokenType
);
}
// TODO@Martin: find a better home for this code:
// TODO@Martin: modify suggestSupport to return a boolean if snippets should be presented or not
// and turn this into a real registry
export
class
SnippetsRegistry
{
private
static
_defaultSnippets
:
{
[
modeId
:
string
]:
Modes
.
ISuggestion
[]
}
=
Object
.
create
(
null
);
private
static
_snippets
:
{
[
modeId
:
string
]:
{
[
path
:
string
]:
Modes
.
ISuggestion
[]
}
}
=
Object
.
create
(
null
);
public
static
registerDefaultSnippets
(
modeId
:
string
,
snippets
:
Modes
.
ISuggestion
[]):
void
{
this
.
_defaultSnippets
[
modeId
]
=
(
this
.
_defaultSnippets
[
modeId
]
||
[]).
concat
(
snippets
);
}
public
static
registerSnippets
(
modeId
:
string
,
path
:
string
,
snippets
:
Modes
.
ISuggestion
[]):
void
{
let
snippetsByMode
=
this
.
_snippets
[
modeId
];
if
(
!
snippetsByMode
)
{
this
.
_snippets
[
modeId
]
=
snippetsByMode
=
{};
}
snippetsByMode
[
path
]
=
snippets
;
}
public
static
getSnippets
(
model
:
EditorCommon
.
IModel
,
position
:
EditorCommon
.
IPosition
):
Modes
.
ISuggestResult
{
let
word
=
model
.
getWordAtPosition
(
position
);
let
currentPrefix
=
word
?
word
.
word
.
substring
(
0
,
position
.
column
-
word
.
startColumn
)
:
''
;
let
result
:
Modes
.
ISuggestResult
=
{
currentWord
:
currentPrefix
,
suggestions
:
[]
};
// to avoid that snippets are too prominent in the intellisense proposals:
// - force that the current prefix matches with the snippet prefix
// if there's no prfix, only show snippets at the beginning of the line, or after a whitespace
let
filter
=
null
;
if
(
currentPrefix
.
length
===
0
)
{
if
(
position
.
column
>
1
)
{
let
previousCharacter
=
model
.
getValueInRange
({
startLineNumber
:
position
.
lineNumber
,
startColumn
:
position
.
column
-
1
,
endLineNumber
:
position
.
lineNumber
,
endColumn
:
position
.
column
});
if
(
previousCharacter
.
trim
().
length
!==
0
)
{
return
result
;
}
}
}
else
{
let
lowerCasePrefix
=
currentPrefix
.
toLowerCase
();
filter
=
(
p
:
Modes
.
ISuggestion
)
=>
{
return
Strings
.
startsWith
(
p
.
label
.
toLowerCase
(),
lowerCasePrefix
);
};
}
let
modeId
=
model
.
getMode
().
getId
();
let
snippets
:
Modes
.
ISuggestion
[]
=
[];
let
snipppetsByMode
=
this
.
_snippets
[
modeId
];
if
(
snipppetsByMode
)
{
for
(
let
s
in
snipppetsByMode
)
{
snippets
=
snippets
.
concat
(
snipppetsByMode
[
s
]);
}
}
let
defaultSnippets
=
this
.
_defaultSnippets
[
modeId
];
if
(
defaultSnippets
)
{
snippets
=
snippets
.
concat
(
defaultSnippets
);
}
result
.
suggestions
=
filter
?
snippets
.
filter
(
filter
)
:
snippets
;
// if (result.suggestions.length > 0) {
// if (word) {
// // Push also the current word as first suggestion, to avoid unexpected snippet acceptance on Enter.
// result.suggestions = result.suggestions.slice(0);
// result.suggestions.unshift({
// codeSnippet: word.word,
// label: word.word,
// type: 'text'
// });
// }
// result.incomplete = true;
// }
return
result
;
}
}
src/vs/editor/contrib/suggest/common/suggest.ts
浏览文件 @
9e589be9
...
...
@@ -11,7 +11,7 @@ import {onUnexpectedError, illegalArgument} from 'vs/base/common/errors';
import
{
ISuggestSupport
,
ISuggestResult
}
from
'
vs/editor/common/modes
'
;
import
LanguageFeatureRegistry
from
'
vs/editor/common/modes/languageFeatureRegistry
'
;
import
{
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
getSnippets
}
from
'
vs/editor/common/modes/modesRegistry
'
;
import
{
SnippetsRegistry
}
from
'
vs/editor/common/modes/supports
'
;
export
var
CONTEXT_SUGGEST_WIDGET_VISIBLE
=
'
suggestWidgetVisible
'
;
export
var
CONTEXT_SUGGESTION_SUPPORTS_ACCEPT_ON_KEY
=
'
suggestionSupportsAcceptOnKey
'
;
...
...
@@ -78,7 +78,7 @@ export function suggest(model: IModel, position: IPosition, triggerCharacter: st
return
sequence
(
factory
).
then
(()
=>
{
// add snippets to the first group
const
snippets
=
getSnippets
(
model
,
position
);
const
snippets
=
SnippetsRegistry
.
getSnippets
(
model
,
position
);
if
(
suggestions
.
length
===
0
)
{
suggestions
.
push
([
snippets
]);
}
else
{
...
...
src/vs/editor/node/textMate/TMSnippets.ts
浏览文件 @
9e589be9
...
...
@@ -9,11 +9,11 @@ import {TPromise} from 'vs/base/common/winjs.base';
import
Modes
=
require
(
'
vs/editor/common/modes
'
);
import
snippets
=
require
(
'
vs/editor/contrib/snippet/common/snippet
'
);
import
json
=
require
(
'
vs/base/common/json
'
);
import
modesExt
=
require
(
'
vs/editor/common/modes/modesRegistry
'
);
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
PluginsRegistry
,
IMessageCollector
}
from
'
vs/platform/plugins/common/pluginsRegistry
'
;
import
{
SnippetsRegistry
}
from
'
vs/editor/common/modes/supports
'
;
import
pfs
=
require
(
'
vs/base/node/pfs
'
);
...
...
@@ -27,7 +27,7 @@ export function snippetUpdated(modeId: string, filePath: string): TPromise<void>
var
errors
:
string
[]
=
[];
var
snippets
=
json
.
parse
(
fileContents
.
toString
(),
errors
);
var
adaptedSnippets
=
TMSnippetsAdaptor
.
adapt
(
snippets
);
modesExt
.
registerSnippets
(
modeId
,
filePath
,
adaptedSnippets
);
SnippetsRegistry
.
registerSnippets
(
modeId
,
filePath
,
adaptedSnippets
);
});
}
...
...
@@ -99,7 +99,7 @@ export class MainProcessTextMateSnippet {
var
errors
:
string
[]
=
[];
var
snippets
=
json
.
parse
(
fileContents
.
toString
(),
errors
);
var
adaptedSnippets
=
TMSnippetsAdaptor
.
adapt
(
snippets
);
modesExt
.
registerDefaultSnippets
(
modeId
,
adaptedSnippets
);
SnippetsRegistry
.
registerDefaultSnippets
(
modeId
,
adaptedSnippets
);
});
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录