Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ebc30748
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,发现更多精彩内容 >>
提交
ebc30748
编写于
7月 21, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emulate LanguageConfiguration.__electricCharacterSupport.docComment with autoClosingPairs
上级
24b9f788
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
40 deletion
+49
-40
extensions/typescript/src/typescriptMain.ts
extensions/typescript/src/typescriptMain.ts
+3
-4
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+1
-0
src/vs/editor/common/modes/languageConfigurationRegistry.ts
src/vs/editor/common/modes/languageConfigurationRegistry.ts
+1
-4
src/vs/editor/common/modes/supports/electricCharacter.ts
src/vs/editor/common/modes/supports/electricCharacter.ts
+43
-30
src/vs/editor/test/common/modes/autoIndentation.test.ts
src/vs/editor/test/common/modes/autoIndentation.test.ts
+1
-2
未找到文件。
extensions/typescript/src/typescriptMain.ts
浏览文件 @
ebc30748
...
...
@@ -206,18 +206,17 @@ class LanguageProvider {
}
],
__electricCharacterSupport
:
{
docComment
:
{
scope
:
'
comment.documentation
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
}
},
__characterPairSupport
:
{
autoClosingPairs
:
[
{
open
:
'
{
'
,
close
:
'
}
'
},
{
open
:
'
[
'
,
close
:
'
]
'
},
{
open
:
'
(
'
,
close
:
'
)
'
},
{
open
:
'
"
'
,
close
:
'
"
'
,
notIn
:
[
'
string
'
]
},
{
open
:
'
\'
'
,
close
:
'
\'
'
,
notIn
:
[
'
string
'
,
'
comment
'
]
},
{
open
:
'
`
'
,
close
:
'
`
'
,
notIn
:
[
'
string
'
,
'
comment
'
]
}
{
open
:
'
`
'
,
close
:
'
`
'
,
notIn
:
[
'
string
'
,
'
comment
'
]
},
{
open
:
'
/**
'
,
close
:
'
*/
'
,
notIn
:
[
'
string
'
]
}
]
}
});
...
...
src/vs/editor/common/modes.ts
浏览文件 @
ebc30748
...
...
@@ -879,6 +879,7 @@ export type CharacterPair = [string, string];
export
interface
IAutoClosingPairConditional
extends
IAutoClosingPair
{
notIn
?:
string
[];
}
/**
...
...
src/vs/editor/common/modes/languageConfigurationRegistry.ts
浏览文件 @
ebc30748
...
...
@@ -111,10 +111,7 @@ export class RichEditSupport {
this
.
_handleComments
(
modeId
,
this
.
_conf
);
this
.
characterPair
=
new
CharacterPairSupport
(
LanguageConfigurationRegistry
,
modeId
,
this
.
_conf
);
if
(
this
.
_conf
.
__electricCharacterSupport
||
this
.
_conf
.
brackets
)
{
this
.
electricCharacter
=
new
BracketElectricCharacterSupport
(
LanguageConfigurationRegistry
,
modeId
,
this
.
brackets
,
this
.
_conf
.
__electricCharacterSupport
);
}
this
.
electricCharacter
=
new
BracketElectricCharacterSupport
(
LanguageConfigurationRegistry
,
modeId
,
this
.
brackets
,
this
.
characterPair
.
getAutoClosingPairs
(),
this
.
_conf
.
__electricCharacterSupport
);
this
.
wordDefinition
=
this
.
_conf
.
wordPattern
||
DEFAULT_WORD_REGEXP
;
}
...
...
src/vs/editor/common/modes/supports/electricCharacter.ts
浏览文件 @
ebc30748
...
...
@@ -32,11 +32,11 @@ export class BracketElectricCharacterSupport implements modes.IRichEditElectricC
private
contribution
:
IBracketElectricCharacterContribution
;
private
brackets
:
Brackets
;
constructor
(
registry
:
LanguageConfigurationRegistryImpl
,
modeId
:
string
,
brackets
:
modes
.
IRichEditBrackets
,
contribution
:
IBracketElectricCharacterContribution
)
{
constructor
(
registry
:
LanguageConfigurationRegistryImpl
,
modeId
:
string
,
brackets
:
modes
.
IRichEditBrackets
,
autoClosePairs
:
modes
.
IAutoClosingPairConditional
[],
contribution
:
IBracketElectricCharacterContribution
)
{
this
.
_registry
=
registry
;
this
.
_modeId
=
modeId
;
this
.
contribution
=
contribution
||
{};
this
.
brackets
=
new
Brackets
(
modeId
,
brackets
,
this
.
contribution
.
docComment
);
this
.
brackets
=
new
Brackets
(
modeId
,
brackets
,
autoClosePairs
,
contribution
.
docComment
);
}
public
getElectricCharacters
():
string
[]{
...
...
@@ -66,12 +66,16 @@ export class Brackets {
private
_modeId
:
string
;
private
_richEditBrackets
:
modes
.
IRichEditBrackets
;
private
_
docComment
:
IDocComment
;
private
_
complexAutoClosePairs
:
modes
.
IAutoClosingPairConditional
[]
;
constructor
(
modeId
:
string
,
richEditBrackets
:
modes
.
IRichEditBrackets
,
docComment
:
IDocComment
=
null
)
{
constructor
(
modeId
:
string
,
richEditBrackets
:
modes
.
IRichEditBrackets
,
autoClosePairs
:
modes
.
IAutoClosingPairConditional
[],
docComment
?:
IDocComment
)
{
this
.
_modeId
=
modeId
;
this
.
_richEditBrackets
=
richEditBrackets
;
this
.
_docComment
=
docComment
?
docComment
:
null
;
this
.
_complexAutoClosePairs
=
autoClosePairs
.
filter
(
pair
=>
pair
.
open
.
length
>
1
&&
!!
pair
.
close
);
if
(
docComment
)
{
// IDocComment is legacy, only partially supported
this
.
_complexAutoClosePairs
.
push
({
open
:
docComment
.
open
,
close
:
docComment
.
close
});
}
}
public
getElectricCharacters
():
string
[]
{
...
...
@@ -85,9 +89,9 @@ export class Brackets {
}
}
//
Doc comments
if
(
this
.
_docComment
)
{
result
.
push
(
this
.
_docComment
.
open
.
charAt
(
this
.
_docComment
.
open
.
length
-
1
));
//
auto close
for
(
let
pair
of
this
.
_complexAutoClosePairs
)
{
result
.
push
(
pair
.
open
.
charAt
(
pair
.
open
.
length
-
1
));
}
// Filter duplicate entries
...
...
@@ -103,8 +107,8 @@ export class Brackets {
return
null
;
}
return
(
this
.
_onElectric
CharacterDocComment
(
context
,
offset
)
||
this
.
_onElectric
CharacterStandardBrackets
(
context
,
offset
));
return
(
this
.
_onElectric
AutoClose
(
context
,
offset
)
||
this
.
_onElectric
AutoIndent
(
context
,
offset
));
}
private
containsTokenTypes
(
fullTokenSpec
:
string
,
tokensToLookFor
:
string
):
boolean
{
...
...
@@ -117,7 +121,7 @@ export class Brackets {
return
true
;
}
private
_onElectric
CharacterStandardBrackets
(
context
:
modes
.
ILineContext
,
offset
:
number
):
modes
.
IElectricAction
{
private
_onElectric
AutoIndent
(
context
:
modes
.
ILineContext
,
offset
:
number
):
modes
.
IElectricAction
{
if
(
!
this
.
_richEditBrackets
||
this
.
_richEditBrackets
.
brackets
.
length
===
0
)
{
return
null
;
...
...
@@ -151,35 +155,44 @@ export class Brackets {
return
null
;
}
private
_onElectric
CharacterDocComment
(
context
:
modes
.
ILineContext
,
offset
:
number
):
modes
.
IElectricAction
{
// We only auto-close, so do nothing if there is no closing part.
if
(
!
this
.
_
docComment
||
!
this
.
_docComment
.
close
)
{
private
_onElectric
AutoClose
(
context
:
modes
.
ILineContext
,
offset
:
number
):
modes
.
IElectricAction
{
if
(
!
this
.
_
complexAutoClosePairs
.
length
)
{
return
null
;
}
var
line
=
context
.
getLineContent
();
var
char
:
string
=
line
[
offset
];
// See if the right electric character was pressed
if
(
char
!==
this
.
_docComment
.
open
.
charAt
(
this
.
_docComment
.
open
.
length
-
1
))
{
return
null
;
}
for
(
let
i
=
0
;
i
<
this
.
_complexAutoClosePairs
.
length
;
i
++
)
{
let
pair
=
this
.
_complexAutoClosePairs
[
i
];
// If this line already contains the closing tag, do nothing.
if
(
line
.
indexOf
(
this
.
_docComment
.
close
,
offset
)
>=
0
)
{
return
null
;
}
// See if the right electric character was pressed
if
(
char
!==
pair
.
open
.
charAt
(
pair
.
open
.
length
-
1
)
)
{
continue
;
}
// If we're not in a documentation comment, do nothing.
var
lastTokenIndex
=
context
.
findIndexOfOffset
(
offset
);
if
(
!
this
.
containsTokenTypes
(
context
.
getTokenType
(
lastTokenIndex
),
this
.
_docComment
.
scope
))
{
return
null
;
}
// If this line already contains the closing tag, do nothing.
if
(
line
.
indexOf
(
pair
.
close
,
offset
)
>=
0
)
{
continue
;
}
if
(
line
.
substring
(
context
.
getTokenStartIndex
(
lastTokenIndex
),
offset
+
1
/* include electric char*/
)
!==
this
.
_docComment
.
open
)
{
return
null
;
// check if the full open bracket matches
let
lastTokenIndex
=
context
.
findIndexOfOffset
(
offset
);
if
(
line
.
substring
(
context
.
getTokenStartIndex
(
lastTokenIndex
),
offset
+
1
/* include electric char*/
)
!==
pair
.
open
)
{
continue
;
}
// If we're in a scope listen in 'notIn', do nothing
if
(
pair
.
notIn
)
{
let
tokenType
=
context
.
getTokenType
(
lastTokenIndex
);
if
(
pair
.
notIn
.
some
(
scope
=>
this
.
containsTokenTypes
(
tokenType
,
scope
)))
{
continue
;
}
}
return
{
appendText
:
pair
.
close
};
}
return
{
appendText
:
this
.
_docComment
.
close
};
}
}
src/vs/editor/test/common/modes/autoIndentation.test.ts
浏览文件 @
ebc30748
...
...
@@ -10,8 +10,7 @@ import {createLineContextFromTokenText} from 'vs/editor/test/common/modesTestUti
suite
(
'
Editor Modes - Auto Indentation
'
,
()
=>
{
test
(
'
Doc comments
'
,
()
=>
{
var
brackets
=
new
Brackets
(
'
test
'
,
null
,
{
scope
:
'
doc
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
});
var
brackets
=
new
Brackets
(
'
test
'
,
null
,
[{
open
:
'
/**
'
,
close
:
'
*/
'
}]);
assert
.
equal
(
brackets
.
onElectricCharacter
(
createLineContextFromTokenText
([
{
text
:
'
/**
'
,
type
:
'
doc
'
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录