Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4a7d555d
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,发现更多精彩内容 >>
提交
4a7d555d
编写于
2月 22, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify code dealing with brackets
上级
eeece32b
变更
23
显示空白变更内容
内联
并排
Showing
23 changed file
with
214 addition
and
283 deletion
+214
-283
extensions/typescript/src/typescriptMain.ts
extensions/typescript/src/typescriptMain.ts
+0
-5
src/vs/editor/common/model/textModelWithTokens.ts
src/vs/editor/common/model/textModelWithTokens.ts
+1
-1
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+0
-10
src/vs/editor/common/modes/monarch/monarchCommon.ts
src/vs/editor/common/modes/monarch/monarchCommon.ts
+3
-2
src/vs/editor/common/modes/monarch/monarchCompile.ts
src/vs/editor/common/modes/monarch/monarchCompile.ts
+4
-8
src/vs/editor/common/modes/monarch/monarchDefinition.ts
src/vs/editor/common/modes/monarch/monarchDefinition.ts
+3
-12
src/vs/editor/common/modes/supports/electricCharacter.ts
src/vs/editor/common/modes/supports/electricCharacter.ts
+17
-175
src/vs/editor/common/modes/supports/richEditBrackets.ts
src/vs/editor/common/modes/supports/richEditBrackets.ts
+163
-0
src/vs/editor/common/modes/supports/richEditSupport.ts
src/vs/editor/common/modes/supports/richEditSupport.ts
+7
-5
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
+1
-1
src/vs/editor/node/languageConfiguration.ts
src/vs/editor/node/languageConfiguration.ts
+0
-9
src/vs/editor/test/common/modes/autoIndentation.test.ts
src/vs/editor/test/common/modes/autoIndentation.test.ts
+1
-1
src/vs/editor/test/common/testModes.ts
src/vs/editor/test/common/testModes.ts
+5
-7
src/vs/languages/css/common/css.ts
src/vs/languages/css/common/css.ts
+0
-6
src/vs/languages/handlebars/common/handlebars.ts
src/vs/languages/handlebars/common/handlebars.ts
+0
-1
src/vs/languages/html/common/html.ts
src/vs/languages/html/common/html.ts
+0
-4
src/vs/languages/javascript/common/javascript.ts
src/vs/languages/javascript/common/javascript.ts
+0
-5
src/vs/languages/json/common/json.ts
src/vs/languages/json/common/json.ts
+0
-7
src/vs/languages/php/common/php.ts
src/vs/languages/php/common/php.ts
+6
-9
src/vs/languages/razor/common/csharpTokenization.ts
src/vs/languages/razor/common/csharpTokenization.ts
+3
-3
src/vs/languages/razor/common/razor.ts
src/vs/languages/razor/common/razor.ts
+0
-1
src/vs/languages/typescript/common/typescriptMode.ts
src/vs/languages/typescript/common/typescriptMode.ts
+0
-5
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+0
-6
未找到文件。
extensions/typescript/src/typescriptMain.ts
浏览文件 @
4a7d555d
...
...
@@ -113,11 +113,6 @@ function registerSupports(modeID: string, host: TypeScriptServiceClientHost, cli
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
delimiter.curly.
'
+
modeID
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.square.
'
+
modeID
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.paren.
'
+
modeID
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
],
docComment
:
{
scope
:
'
comment.documentation
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
}
},
...
...
src/vs/editor/common/model/textModelWithTokens.ts
浏览文件 @
4a7d555d
...
...
@@ -22,7 +22,7 @@ import {TokenIterator} from 'vs/editor/common/model/tokenIterator';
import
{
ILineContext
,
ILineTokens
,
IMode
,
IModeTransition
,
IState
}
from
'
vs/editor/common/modes
'
;
import
{
NullMode
,
NullState
,
nullTokenize
}
from
'
vs/editor/common/modes/nullMode
'
;
import
{
ignoreBracketsInToken
}
from
'
vs/editor/common/modes/supports
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/
electricCharacter
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/
richEditBrackets
'
;
export
class
TokensInflatorMap
implements
editorCommon
.
ITokensInflatorMap
{
...
...
src/vs/editor/common/modes.ts
浏览文件 @
4a7d555d
...
...
@@ -649,16 +649,6 @@ export interface ITaskSupport {
clean
?():
TPromise
<
void
>
;
}
/**
* Standard brackets used for auto indentation
*/
export
interface
IBracketPair
{
tokenType
:
string
;
open
:
string
;
close
:
string
;
isElectric
:
boolean
;
}
export
interface
IAutoClosingPairConditional
extends
IAutoClosingPair
{
notIn
?:
string
[];
}
...
...
src/vs/editor/common/modes/monarch/monarchCommon.ts
浏览文件 @
4a7d555d
...
...
@@ -4,7 +4,8 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
Bracket
,
IAutoClosingPairConditional
,
IBracketPair
,
ISuggestion
}
from
'
vs/editor/common/modes
'
;
import
{
Bracket
,
IAutoClosingPairConditional
,
ISuggestion
}
from
'
vs/editor/common/modes
'
;
import
{
CharacterPair
}
from
'
vs/editor/common/modes/supports/richEditBrackets
'
;
/*
* This module exports common types and functionality shared between
...
...
@@ -47,7 +48,7 @@ export interface ILexer extends ILexerMin {
wordDefinition
:
RegExp
;
autoClosingPairs
:
IAutoClosingPairConditional
[];
standardBrackets
:
IBracket
Pair
[];
standardBrackets
:
Character
Pair
[];
// enhancedBrackets: IRegexBracketPair[];
outdentTriggers
:
string
;
}
...
...
src/vs/editor/common/modes/monarch/monarchCompile.ts
浏览文件 @
4a7d555d
...
...
@@ -10,9 +10,10 @@
*/
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
{
Bracket
,
IAutoClosingPairConditional
,
IBracketPair
}
from
'
vs/editor/common/modes
'
;
import
{
Bracket
,
IAutoClosingPairConditional
}
from
'
vs/editor/common/modes
'
;
import
*
as
monarchCommon
from
'
vs/editor/common/modes/monarch/monarchCommon
'
;
import
{
ILanguage
,
ILanguageBracket
}
from
'
vs/editor/common/modes/monarch/monarchTypes
'
;
import
{
CharacterPair
}
from
'
vs/editor/common/modes/supports/richEditBrackets
'
;
/*
* Type helpers
...
...
@@ -687,14 +688,9 @@ export function compile(json: ILanguage): monarchCommon.ILexer {
// }
// lexer.enhancedBrackets = enhancedBrackets;
var
standardBrackets
:
IBracket
Pair
[]
=
[];
var
standardBrackets
:
Character
Pair
[]
=
[];
for
(
var
i
=
0
;
i
<
brackets
.
length
;
++
i
)
{
standardBrackets
.
push
({
tokenType
:
brackets
[
i
].
token
,
open
:
brackets
[
i
].
open
,
close
:
brackets
[
i
].
close
,
isElectric
:
true
});
standardBrackets
.
push
([
brackets
[
i
].
open
,
brackets
[
i
].
close
]);
}
lexer
.
standardBrackets
=
standardBrackets
;
...
...
src/vs/editor/common/modes/monarch/monarchDefinition.ts
浏览文件 @
4a7d555d
...
...
@@ -9,23 +9,15 @@
* using regular expressions.
*/
import
{
I
BracketPair
,
I
SuggestSupport
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestSupport
}
from
'
vs/editor/common/modes
'
;
import
{
ILexer
}
from
'
vs/editor/common/modes/monarch/monarchCommon
'
;
import
{
CharacterPair
,
IRichEditConfiguration
}
from
'
vs/editor/common/modes/supports/richEditSupport
'
;
import
{
IRichEditConfiguration
}
from
'
vs/editor/common/modes/supports/richEditSupport
'
;
import
{
PredefinedResultSuggestSupport
,
TextualAndPredefinedResultSuggestSupport
}
from
'
vs/editor/common/modes/supports/suggestSupport
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
export
function
createRichEditSupport
(
lexer
:
ILexer
):
IRichEditConfiguration
{
function
toBracket
(
input
:
IBracketPair
):
CharacterPair
{
return
[
input
.
open
,
input
.
close
];
}
function
toBrackets
(
input
:
IBracketPair
[]):
CharacterPair
[]
{
return
input
.
map
(
toBracket
);
}
return
{
wordPattern
:
lexer
.
wordDefinition
,
...
...
@@ -35,10 +27,9 @@ export function createRichEditSupport(lexer: ILexer): IRichEditConfiguration {
blockComment
:
[
lexer
.
blockCommentStart
,
lexer
.
blockCommentEnd
]
},
brackets
:
toBrackets
(
lexer
.
standardBrackets
)
,
brackets
:
lexer
.
standardBrackets
,
__electricCharacterSupport
:
{
brackets
:
lexer
.
standardBrackets
,
// regexBrackets: lexer.enhancedBrackets,
caseInsensitive
:
lexer
.
ignoreCase
,
embeddedElectricCharacters
:
lexer
.
outdentTriggers
.
split
(
''
)
...
...
src/vs/editor/common/modes/supports/electricCharacter.ts
浏览文件 @
4a7d555d
...
...
@@ -5,10 +5,9 @@
'
use strict
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IRichEditBracket
}
from
'
vs/editor/common/editorCommon
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
{
handleEvent
,
ignoreBracketsInToken
}
from
'
vs/editor/common/modes/supports
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/richEditBrackets
'
;
/**
* Definition of documentation comments (e.g. Javadoc/JSdoc)
...
...
@@ -21,7 +20,6 @@ export interface IDocComment {
}
export
interface
IBracketElectricCharacterContribution
{
brackets
:
modes
.
IBracketPair
[];
docComment
?:
IDocComment
;
caseInsensitive
?:
boolean
;
embeddedElectricCharacters
?:
string
[];
...
...
@@ -33,10 +31,10 @@ export class BracketElectricCharacterSupport implements modes.IRichEditElectricC
private
contribution
:
IBracketElectricCharacterContribution
;
private
brackets
:
Brackets
;
constructor
(
modeId
:
string
,
contribution
:
IBracketElectricCharacterContribution
)
{
constructor
(
modeId
:
string
,
brackets
:
modes
.
IRichEditBrackets
,
contribution
:
IBracketElectricCharacterContribution
)
{
this
.
_modeId
=
modeId
;
this
.
contribution
=
contribution
;
this
.
brackets
=
new
Brackets
(
modeId
,
contribution
.
brackets
,
contribution
.
docComment
,
contribution
.
caseInsensitive
);
this
.
contribution
=
contribution
||
{}
;
this
.
brackets
=
new
Brackets
(
modeId
,
brackets
,
this
.
contribution
.
docComment
,
this
.
contribution
.
caseInsensitive
);
}
public
getElectricCharacters
():
string
[]{
...
...
@@ -57,78 +55,32 @@ export class BracketElectricCharacterSupport implements modes.IRichEditElectricC
}
});
}
public
getRichEditBrackets
():
modes
.
IRichEditBrackets
{
return
this
.
brackets
.
getRichEditBrackets
();
}
}
interface
ISimpleInternalBracket
{
open
:
string
;
close
:
string
;
}
export
class
Brackets
{
private
_modeId
:
string
;
private
_brackets
:
IRichEditBracket
[];
private
_bracketsForwardRegex
:
RegExp
;
private
_bracketsReversedRegex
:
RegExp
;
private
_maxBracketLength
:
number
;
private
_textIsBracket
:
{[
text
:
string
]:
IRichEditBracket
;};
private
_textIsOpenBracket
:
{[
text
:
string
]:
boolean
;};
private
_richEditBrackets
:
modes
.
IRichEditBrackets
;
private
_docComment
:
IDocComment
;
constructor
(
modeId
:
string
,
brackets
:
modes
.
IBracketPair
[]
,
docComment
:
IDocComment
=
null
,
caseInsensitive
:
boolean
=
false
)
{
constructor
(
modeId
:
string
,
richEditBrackets
:
modes
.
IRichEditBrackets
,
docComment
:
IDocComment
=
null
,
caseInsensitive
:
boolean
=
false
)
{
this
.
_modeId
=
modeId
;
this
.
_brackets
=
brackets
.
map
((
b
)
=>
{
return
{
modeId
:
modeId
,
open
:
b
.
open
,
close
:
b
.
close
,
forwardRegex
:
getRegexForBracketPair
({
open
:
b
.
open
,
close
:
b
.
close
}),
reversedRegex
:
getReversedRegexForBracketPair
({
open
:
b
.
open
,
close
:
b
.
close
})
};
});
this
.
_bracketsForwardRegex
=
getRegexForBrackets
(
this
.
_brackets
);
this
.
_bracketsReversedRegex
=
getReversedRegexForBrackets
(
this
.
_brackets
);
this
.
_textIsBracket
=
{};
this
.
_textIsOpenBracket
=
{};
this
.
_maxBracketLength
=
0
;
this
.
_brackets
.
forEach
((
b
)
=>
{
this
.
_textIsBracket
[
b
.
open
]
=
b
;
this
.
_textIsBracket
[
b
.
close
]
=
b
;
this
.
_textIsOpenBracket
[
b
.
open
]
=
true
;
this
.
_textIsOpenBracket
[
b
.
close
]
=
false
;
this
.
_maxBracketLength
=
Math
.
max
(
this
.
_maxBracketLength
,
b
.
open
.
length
);
this
.
_maxBracketLength
=
Math
.
max
(
this
.
_maxBracketLength
,
b
.
close
.
length
);
});
this
.
_richEditBrackets
=
richEditBrackets
;
this
.
_docComment
=
docComment
?
docComment
:
null
;
}
public
getRichEditBrackets
():
modes
.
IRichEditBrackets
{
if
(
this
.
_brackets
.
length
===
0
)
{
return
null
;
}
return
{
maxBracketLength
:
this
.
_maxBracketLength
,
forwardRegex
:
this
.
_bracketsForwardRegex
,
reversedRegex
:
this
.
_bracketsReversedRegex
,
brackets
:
this
.
_brackets
,
textIsBracket
:
this
.
_textIsBracket
,
textIsOpenBracket
:
this
.
_textIsOpenBracket
};
}
public
getElectricCharacters
():
string
[]
{
var
result
:
string
[]
=
[];
for
(
let
i
=
0
,
len
=
this
.
_brackets
.
length
;
i
<
len
;
i
++
)
{
let
bracketPair
=
this
.
_brackets
[
i
];
if
(
this
.
_richEditBrackets
)
{
for
(
let
i
=
0
,
len
=
this
.
_richEditBrackets
.
brackets
.
length
;
i
<
len
;
i
++
)
{
let
bracketPair
=
this
.
_richEditBrackets
.
brackets
[
i
];
let
lastChar
=
bracketPair
.
close
.
charAt
(
bracketPair
.
close
.
length
-
1
);
result
.
push
(
lastChar
);
}
}
// Doc comments
if
(
this
.
_docComment
){
...
...
@@ -164,11 +116,11 @@ export class Brackets {
private
_onElectricCharacterStandardBrackets
(
context
:
modes
.
ILineContext
,
offset
:
number
):
modes
.
IElectricAction
{
if
(
this
.
_
brackets
.
length
===
0
)
{
if
(
!
this
.
_richEditBrackets
||
this
.
_richEditBrackets
.
brackets
.
length
===
0
)
{
return
null
;
}
let
reversedBracketRegex
=
this
.
_
bracketsR
eversedRegex
;
let
reversedBracketRegex
=
this
.
_
richEditBrackets
.
r
eversedRegex
;
let
lineText
=
context
.
getLineContent
();
let
tokenIndex
=
context
.
findIndexOfOffset
(
offset
);
...
...
@@ -184,7 +136,7 @@ export class Brackets {
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
1
,
lineText
,
tokenStart
,
tokenEnd
);
if
(
r
)
{
let
text
=
lineText
.
substring
(
r
.
startColumn
-
1
,
r
.
endColumn
-
1
);
let
isOpen
=
this
.
_textIsOpenBracket
[
text
];
let
isOpen
=
this
.
_
richEditBrackets
.
textIsOpenBracket
[
text
];
if
(
!
isOpen
)
{
return
{
matchOpenBracket
:
text
...
...
@@ -228,113 +180,3 @@ export class Brackets {
return
{
appendText
:
this
.
_docComment
.
close
};
}
}
function
once
<
T
,
R
>
(
keyFn
:(
input
:
T
)
=>
string
,
computeFn
:(
input
:
T
)
=>
R
):(
input
:
T
)
=>
R
{
let
cache
:
{[
key
:
string
]:
R
;}
=
{};
return
(
input
:
T
):
R
=>
{
let
key
=
keyFn
(
input
);
if
(
!
cache
.
hasOwnProperty
(
key
))
{
cache
[
key
]
=
computeFn
(
input
);
}
return
cache
[
key
];
};
}
var
getRegexForBracketPair
=
once
<
ISimpleInternalBracket
,
RegExp
>
(
(
input
)
=>
`
${
input
.
open
}
;
${
input
.
close
}
`
,
(
input
)
=>
{
return
createOrRegex
([
input
.
open
,
input
.
close
]);
}
);
var
getReversedRegexForBracketPair
=
once
<
ISimpleInternalBracket
,
RegExp
>
(
(
input
)
=>
`
${
input
.
open
}
;
${
input
.
close
}
`
,
(
input
)
=>
{
return
createOrRegex
([
toReversedString
(
input
.
open
),
toReversedString
(
input
.
close
)]);
}
);
var
getRegexForBrackets
=
once
<
ISimpleInternalBracket
[],
RegExp
>
(
(
input
)
=>
input
.
map
(
b
=>
`
${
b
.
open
}
;
${
b
.
close
}
`
).
join
(
'
;
'
),
(
input
)
=>
{
let
pieces
:
string
[]
=
[];
input
.
forEach
((
b
)
=>
{
pieces
.
push
(
b
.
open
);
pieces
.
push
(
b
.
close
);
});
return
createOrRegex
(
pieces
);
}
);
var
getReversedRegexForBrackets
=
once
<
ISimpleInternalBracket
[],
RegExp
>
(
(
input
)
=>
input
.
map
(
b
=>
`
${
b
.
open
}
;
${
b
.
close
}
`
).
join
(
'
;
'
),
(
input
)
=>
{
let
pieces
:
string
[]
=
[];
input
.
forEach
((
b
)
=>
{
pieces
.
push
(
toReversedString
(
b
.
open
));
pieces
.
push
(
toReversedString
(
b
.
close
));
});
return
createOrRegex
(
pieces
);
}
);
function
createOrRegex
(
pieces
:
string
[]):
RegExp
{
let
regexStr
=
`(
${
pieces
.
map
(
strings
.
escapeRegExpCharacters
).
join
(
'
)|(
'
)}
)`
;
return
strings
.
createRegExp
(
regexStr
,
true
,
false
,
false
,
false
);
}
function
toReversedString
(
str
:
string
):
string
{
let
reversedStr
=
''
;
for
(
let
i
=
str
.
length
-
1
;
i
>=
0
;
i
--
)
{
reversedStr
+=
str
.
charAt
(
i
);
}
return
reversedStr
;
}
export
class
BracketsUtils
{
private
static
_findPrevBracketInText
(
reversedBracketRegex
:
RegExp
,
lineNumber
:
number
,
reversedText
:
string
,
offset
:
number
):
Range
{
let
m
=
reversedText
.
match
(
reversedBracketRegex
);
if
(
!
m
)
{
return
null
;
}
let
matchOffset
=
reversedText
.
length
-
1
-
m
.
index
;
let
matchLength
=
m
[
0
].
length
;
let
absoluteMatchOffset
=
offset
+
matchOffset
;
return
new
Range
(
lineNumber
,
absoluteMatchOffset
+
1
,
lineNumber
,
absoluteMatchOffset
+
1
+
matchLength
);
}
public
static
findPrevBracketInToken
(
reversedBracketRegex
:
RegExp
,
lineNumber
:
number
,
lineText
:
string
,
currentTokenStart
:
number
,
currentTokenEnd
:
number
):
Range
{
// Because JS does not support backwards regex search, we search forwards in a reversed string with a reversed regex ;)
let
currentTokenReversedText
=
''
;
for
(
let
index
=
currentTokenEnd
-
1
;
index
>=
currentTokenStart
;
index
--
)
{
currentTokenReversedText
+=
lineText
.
charAt
(
index
);
}
return
this
.
_findPrevBracketInText
(
reversedBracketRegex
,
lineNumber
,
currentTokenReversedText
,
currentTokenStart
);
}
public
static
findNextBracketInText
(
bracketRegex
:
RegExp
,
lineNumber
:
number
,
text
:
string
,
offset
:
number
):
Range
{
let
m
=
text
.
match
(
bracketRegex
);
if
(
!
m
)
{
return
null
;
}
let
matchOffset
=
m
.
index
;
let
matchLength
=
m
[
0
].
length
;
let
absoluteMatchOffset
=
offset
+
matchOffset
;
return
new
Range
(
lineNumber
,
absoluteMatchOffset
+
1
,
lineNumber
,
absoluteMatchOffset
+
1
+
matchLength
);
}
public
static
findNextBracketInToken
(
bracketRegex
:
RegExp
,
lineNumber
:
number
,
lineText
:
string
,
currentTokenStart
:
number
,
currentTokenEnd
:
number
):
Range
{
let
currentTokenText
=
lineText
.
substring
(
currentTokenStart
,
currentTokenEnd
);
return
this
.
findNextBracketInText
(
bracketRegex
,
lineNumber
,
currentTokenText
,
currentTokenStart
);
}
}
src/vs/editor/common/modes/supports/richEditBrackets.ts
0 → 100644
浏览文件 @
4a7d555d
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IRichEditBracket
}
from
'
vs/editor/common/editorCommon
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
export
type
CharacterPair
=
[
string
,
string
];
interface
ISimpleInternalBracket
{
open
:
string
;
close
:
string
;
}
export
class
RichEditBrackets
implements
modes
.
IRichEditBrackets
{
public
brackets
:
IRichEditBracket
[];
public
forwardRegex
:
RegExp
;
public
reversedRegex
:
RegExp
;
public
maxBracketLength
:
number
;
public
textIsBracket
:
{[
text
:
string
]:
IRichEditBracket
;};
public
textIsOpenBracket
:
{[
text
:
string
]:
boolean
;};
constructor
(
modeId
:
string
,
brackets
:
CharacterPair
[])
{
this
.
brackets
=
brackets
.
map
((
b
)
=>
{
return
{
modeId
:
modeId
,
open
:
b
[
0
],
close
:
b
[
1
],
forwardRegex
:
getRegexForBracketPair
({
open
:
b
[
0
],
close
:
b
[
1
]
}),
reversedRegex
:
getReversedRegexForBracketPair
({
open
:
b
[
0
],
close
:
b
[
1
]
})
};
});
this
.
forwardRegex
=
getRegexForBrackets
(
this
.
brackets
);
this
.
reversedRegex
=
getReversedRegexForBrackets
(
this
.
brackets
);
this
.
textIsBracket
=
{};
this
.
textIsOpenBracket
=
{};
this
.
maxBracketLength
=
0
;
this
.
brackets
.
forEach
((
b
)
=>
{
this
.
textIsBracket
[
b
.
open
]
=
b
;
this
.
textIsBracket
[
b
.
close
]
=
b
;
this
.
textIsOpenBracket
[
b
.
open
]
=
true
;
this
.
textIsOpenBracket
[
b
.
close
]
=
false
;
this
.
maxBracketLength
=
Math
.
max
(
this
.
maxBracketLength
,
b
.
open
.
length
);
this
.
maxBracketLength
=
Math
.
max
(
this
.
maxBracketLength
,
b
.
close
.
length
);
});
}
}
function
once
<
T
,
R
>
(
keyFn
:(
input
:
T
)
=>
string
,
computeFn
:(
input
:
T
)
=>
R
):(
input
:
T
)
=>
R
{
let
cache
:
{[
key
:
string
]:
R
;}
=
{};
return
(
input
:
T
):
R
=>
{
let
key
=
keyFn
(
input
);
if
(
!
cache
.
hasOwnProperty
(
key
))
{
cache
[
key
]
=
computeFn
(
input
);
}
return
cache
[
key
];
};
}
var
getRegexForBracketPair
=
once
<
ISimpleInternalBracket
,
RegExp
>
(
(
input
)
=>
`
${
input
.
open
}
;
${
input
.
close
}
`
,
(
input
)
=>
{
return
createOrRegex
([
input
.
open
,
input
.
close
]);
}
);
var
getReversedRegexForBracketPair
=
once
<
ISimpleInternalBracket
,
RegExp
>
(
(
input
)
=>
`
${
input
.
open
}
;
${
input
.
close
}
`
,
(
input
)
=>
{
return
createOrRegex
([
toReversedString
(
input
.
open
),
toReversedString
(
input
.
close
)]);
}
);
var
getRegexForBrackets
=
once
<
ISimpleInternalBracket
[],
RegExp
>
(
(
input
)
=>
input
.
map
(
b
=>
`
${
b
.
open
}
;
${
b
.
close
}
`
).
join
(
'
;
'
),
(
input
)
=>
{
let
pieces
:
string
[]
=
[];
input
.
forEach
((
b
)
=>
{
pieces
.
push
(
b
.
open
);
pieces
.
push
(
b
.
close
);
});
return
createOrRegex
(
pieces
);
}
);
var
getReversedRegexForBrackets
=
once
<
ISimpleInternalBracket
[],
RegExp
>
(
(
input
)
=>
input
.
map
(
b
=>
`
${
b
.
open
}
;
${
b
.
close
}
`
).
join
(
'
;
'
),
(
input
)
=>
{
let
pieces
:
string
[]
=
[];
input
.
forEach
((
b
)
=>
{
pieces
.
push
(
toReversedString
(
b
.
open
));
pieces
.
push
(
toReversedString
(
b
.
close
));
});
return
createOrRegex
(
pieces
);
}
);
function
createOrRegex
(
pieces
:
string
[]):
RegExp
{
let
regexStr
=
`(
${
pieces
.
map
(
strings
.
escapeRegExpCharacters
).
join
(
'
)|(
'
)}
)`
;
return
strings
.
createRegExp
(
regexStr
,
true
,
false
,
false
,
false
);
}
function
toReversedString
(
str
:
string
):
string
{
let
reversedStr
=
''
;
for
(
let
i
=
str
.
length
-
1
;
i
>=
0
;
i
--
)
{
reversedStr
+=
str
.
charAt
(
i
);
}
return
reversedStr
;
}
export
class
BracketsUtils
{
private
static
_findPrevBracketInText
(
reversedBracketRegex
:
RegExp
,
lineNumber
:
number
,
reversedText
:
string
,
offset
:
number
):
Range
{
let
m
=
reversedText
.
match
(
reversedBracketRegex
);
if
(
!
m
)
{
return
null
;
}
let
matchOffset
=
reversedText
.
length
-
1
-
m
.
index
;
let
matchLength
=
m
[
0
].
length
;
let
absoluteMatchOffset
=
offset
+
matchOffset
;
return
new
Range
(
lineNumber
,
absoluteMatchOffset
+
1
,
lineNumber
,
absoluteMatchOffset
+
1
+
matchLength
);
}
public
static
findPrevBracketInToken
(
reversedBracketRegex
:
RegExp
,
lineNumber
:
number
,
lineText
:
string
,
currentTokenStart
:
number
,
currentTokenEnd
:
number
):
Range
{
// Because JS does not support backwards regex search, we search forwards in a reversed string with a reversed regex ;)
let
currentTokenReversedText
=
''
;
for
(
let
index
=
currentTokenEnd
-
1
;
index
>=
currentTokenStart
;
index
--
)
{
currentTokenReversedText
+=
lineText
.
charAt
(
index
);
}
return
this
.
_findPrevBracketInText
(
reversedBracketRegex
,
lineNumber
,
currentTokenReversedText
,
currentTokenStart
);
}
public
static
findNextBracketInText
(
bracketRegex
:
RegExp
,
lineNumber
:
number
,
text
:
string
,
offset
:
number
):
Range
{
let
m
=
text
.
match
(
bracketRegex
);
if
(
!
m
)
{
return
null
;
}
let
matchOffset
=
m
.
index
;
let
matchLength
=
m
[
0
].
length
;
let
absoluteMatchOffset
=
offset
+
matchOffset
;
return
new
Range
(
lineNumber
,
absoluteMatchOffset
+
1
,
lineNumber
,
absoluteMatchOffset
+
1
+
matchLength
);
}
public
static
findNextBracketInToken
(
bracketRegex
:
RegExp
,
lineNumber
:
number
,
lineText
:
string
,
currentTokenStart
:
number
,
currentTokenEnd
:
number
):
Range
{
let
currentTokenText
=
lineText
.
substring
(
currentTokenStart
,
currentTokenEnd
);
return
this
.
findNextBracketInText
(
bracketRegex
,
lineNumber
,
currentTokenText
,
currentTokenStart
);
}
}
src/vs/editor/common/modes/supports/richEditSupport.ts
浏览文件 @
4a7d555d
...
...
@@ -10,8 +10,7 @@ import {CharacterPairSupport} from 'vs/editor/common/modes/supports/characterPai
import
{
ICharacterPairContribution
}
from
'
vs/editor/common/modes/supports/characterPair
'
;
import
{
BracketElectricCharacterSupport
,
IBracketElectricCharacterContribution
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
import
{
IIndentationRules
,
IOnEnterRegExpRules
,
IOnEnterSupportOptions
,
OnEnterSupport
}
from
'
vs/editor/common/modes/supports/onEnter
'
;
export
type
CharacterPair
=
[
string
,
string
];
import
{
CharacterPair
,
RichEditBrackets
}
from
'
vs/editor/common/modes/supports/richEditBrackets
'
;
export
interface
CommentRule
{
lineComment
?:
string
;
...
...
@@ -48,6 +47,10 @@ export class RichEditSupport implements IRichEditSupport {
this
.
_conf
=
RichEditSupport
.
_mergeConf
(
prev
,
rawConf
);
if
(
this
.
_conf
.
brackets
)
{
this
.
brackets
=
new
RichEditBrackets
(
modeId
,
this
.
_conf
.
brackets
);
}
this
.
_handleOnEnter
(
modeId
,
this
.
_conf
);
this
.
_handleComments
(
modeId
,
this
.
_conf
);
...
...
@@ -56,9 +59,8 @@ export class RichEditSupport implements IRichEditSupport {
this
.
characterPair
=
new
CharacterPairSupport
(
modeId
,
this
.
_conf
.
__characterPairSupport
);
}
if
(
this
.
_conf
.
__electricCharacterSupport
)
{
this
.
electricCharacter
=
new
BracketElectricCharacterSupport
(
modeId
,
this
.
_conf
.
__electricCharacterSupport
);
this
.
brackets
=
this
.
electricCharacter
.
getRichEditBrackets
();
if
(
this
.
_conf
.
__electricCharacterSupport
||
this
.
_conf
.
brackets
)
{
this
.
electricCharacter
=
new
BracketElectricCharacterSupport
(
modeId
,
this
.
brackets
,
this
.
_conf
.
__electricCharacterSupport
);
}
this
.
wordDefinition
=
this
.
_conf
.
wordPattern
||
NullMode
.
DEFAULT_WORD_REGEXP
;
...
...
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
浏览文件 @
4a7d555d
...
...
@@ -9,7 +9,7 @@ import {Range} from 'vs/editor/common/core/range';
import
{
ILineTokens
,
IModel
,
IPosition
,
IRange
,
IRichEditBracket
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Bracket
,
IModeTransition
,
IRichEditBrackets
}
from
'
vs/editor/common/modes
'
;
import
{
ignoreBracketsInToken
}
from
'
vs/editor/common/modes/supports
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/
electricCharacter
'
;
import
{
BracketsUtils
}
from
'
vs/editor/common/modes/supports/
richEditBrackets
'
;
export
class
Node
{
...
...
src/vs/editor/node/languageConfiguration.ts
浏览文件 @
4a7d555d
...
...
@@ -82,15 +82,6 @@ export class LanguageConfigurationFileHandler {
};
}
// TMSyntax hard-codes these and tokenizes them as brackets
richEditConfig
.
__electricCharacterSupport
=
{
brackets
:
[
{
tokenType
:
'
delimiter.curly.
'
+
modeId
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.square.
'
+
modeId
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.paren.
'
+
modeId
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
]
};
this
.
_modeService
.
registerRichEditSupport
(
modeId
,
richEditConfig
);
}
}
src/vs/editor/test/common/modes/autoIndentation.test.ts
浏览文件 @
4a7d555d
...
...
@@ -10,7 +10,7 @@ import {createLineContextFromTokenText} from 'vs/editor/test/common/modesTestUti
suite
(
'
Editor Modes - Auto Indentation
'
,
()
=>
{
test
(
'
Doc comments
'
,
()
=>
{
var
brackets
=
new
Brackets
(
'
test
'
,
[]
,
var
brackets
=
new
Brackets
(
'
test
'
,
null
,
{
scope
:
'
doc
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
});
assert
.
equal
(
brackets
.
onElectricCharacter
(
createLineContextFromTokenText
([
...
...
src/vs/editor/test/common/testModes.ts
浏览文件 @
4a7d555d
...
...
@@ -231,13 +231,11 @@ export class BracketMode extends TestingMode {
getInitialState
:
()
=>
new
BracketState
(
this
)
},
false
,
false
);
this
.
richEditSupport
=
new
RichEditSupport
(
this
.
getId
(),
null
,
{
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
asd
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
}
,
{
tokenType
:
'
qwe
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
}
,
{
tokenType
:
'
zxc
'
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
[
'
{
'
,
'
}
'
]
,
[
'
[
'
,
'
]
'
]
,
[
'
(
'
,
'
)
'
],
]
}
});
}
}
...
...
src/vs/languages/css/common/css.ts
浏览文件 @
4a7d555d
...
...
@@ -323,12 +323,6 @@ export class CSSMode extends AbstractMode {
[
'
(
'
,
'
)
'
]
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
punctuation.bracket.css
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
}
]
},
__characterPairSupport
:
{
autoClosingPairs
:
[
{
open
:
'
{
'
,
close
:
'
}
'
},
...
...
src/vs/languages/handlebars/common/handlebars.ts
浏览文件 @
4a7d555d
...
...
@@ -130,7 +130,6 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
],
__electricCharacterSupport
:
{
brackets
:
[],
caseInsensitive
:
true
,
embeddedElectricCharacters
:
[
'
*
'
,
'
}
'
,
'
]
'
,
'
)
'
]
},
...
...
src/vs/languages/html/common/html.ts
浏览文件 @
4a7d555d
...
...
@@ -351,10 +351,6 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode impl
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
bla
'
,
open
:
'
<!--
'
,
close
:
'
-->
'
,
isElectric
:
true
},
{
tokenType
:
'
bla
'
,
open
:
'
<
'
,
close
:
'
>
'
,
isElectric
:
true
}
],
caseInsensitive
:
true
,
embeddedElectricCharacters
:
[
'
*
'
,
'
}
'
,
'
]
'
,
'
)
'
]
},
...
...
src/vs/languages/javascript/common/javascript.ts
浏览文件 @
4a7d555d
...
...
@@ -93,11 +93,6 @@ export class JSMode extends typescriptMode.TypeScriptMode<javascriptWorker.JavaS
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
delimiter.bracket.js
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.array.js
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.parenthesis.js
'
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
],
docComment
:
{
scope
:
'
comment.doc
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
}
},
...
...
src/vs/languages/json/common/json.ts
浏览文件 @
4a7d555d
...
...
@@ -61,13 +61,6 @@ export class JSONMode extends AbstractMode implements Modes.IExtraInfoSupport, M
[
'
[
'
,
'
]
'
]
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
delimiter.bracket.json
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.array.json
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
}
]
},
__characterPairSupport
:
{
autoClosingPairs
:
[
{
open
:
'
{
'
,
close
:
'
}
'
,
notIn
:
[
'
string
'
]
},
...
...
src/vs/languages/php/common/php.ts
浏览文件 @
4a7d555d
...
...
@@ -15,14 +15,15 @@ import {TokenizationSupport, ILeavingNestedModeData, ITokenizationCustomization}
import
{
TextualSuggestSupport
}
from
'
vs/editor/common/modes/supports/suggestSupport
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
var
bracketsSource
:
Modes
.
IBracketPair
[]
=
[
{
tokenType
:
'
delimiter.bracket.php
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.array.php
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.parenthesis.php
'
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
];
var
brackets
=
(
function
()
{
let
bracketsSource
=
[
{
tokenType
:
'
delimiter.bracket.php
'
,
open
:
'
{
'
,
close
:
'
}
'
},
{
tokenType
:
'
delimiter.array.php
'
,
open
:
'
[
'
,
close
:
'
]
'
},
{
tokenType
:
'
delimiter.parenthesis.php
'
,
open
:
'
(
'
,
close
:
'
)
'
}
];
let
MAP
:
{
[
text
:
string
]:{
tokenType
:
string
;
...
...
@@ -488,10 +489,6 @@ export class PHPMode extends AbstractMode implements ITokenizationCustomization
[
'
(
'
,
'
)
'
]
],
__electricCharacterSupport
:
{
brackets
:
bracketsSource
},
__characterPairSupport
:
{
autoClosingPairs
:
[
{
open
:
'
{
'
,
close
:
'
}
'
,
notIn
:
[
'
string.php
'
]
},
...
...
src/vs/languages/razor/common/csharpTokenization.ts
浏览文件 @
4a7d555d
...
...
@@ -21,9 +21,9 @@ var whitespace = '\t ';
var
brackets
=
(
function
()
{
let
bracketsSource
=
[
{
tokenType
:
'
punctuation.bracket.cs
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
punctuation.array.cs
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
punctuation.parenthesis.cs
'
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
{
tokenType
:
'
punctuation.bracket.cs
'
,
open
:
'
{
'
,
close
:
'
}
'
},
{
tokenType
:
'
punctuation.array.cs
'
,
open
:
'
[
'
,
close
:
'
]
'
},
{
tokenType
:
'
punctuation.parenthesis.cs
'
,
open
:
'
(
'
,
close
:
'
)
'
}
];
let
MAP
:
{
...
...
src/vs/languages/razor/common/razor.ts
浏览文件 @
4a7d555d
...
...
@@ -84,7 +84,6 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
],
__electricCharacterSupport
:
{
brackets
:
[],
caseInsensitive
:
true
,
embeddedElectricCharacters
:
[
'
*
'
,
'
}
'
,
'
]
'
,
'
)
'
]
},
...
...
src/vs/languages/typescript/common/typescriptMode.ts
浏览文件 @
4a7d555d
...
...
@@ -242,11 +242,6 @@ export class TypeScriptMode<W extends typescriptWorker.TypeScriptWorker2> extend
],
__electricCharacterSupport
:
{
brackets
:
[
{
tokenType
:
'
delimiter.bracket.ts
'
,
open
:
'
{
'
,
close
:
'
}
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.array.ts
'
,
open
:
'
[
'
,
close
:
'
]
'
,
isElectric
:
true
},
{
tokenType
:
'
delimiter.parenthesis.ts
'
,
open
:
'
(
'
,
close
:
'
)
'
,
isElectric
:
true
}
],
docComment
:
{
scope
:
'
comment.doc
'
,
open
:
'
/**
'
,
lineStart
:
'
*
'
,
close
:
'
*/
'
}
},
...
...
src/vs/vscode.d.ts
浏览文件 @
4a7d555d
...
...
@@ -2247,12 +2247,6 @@ declare namespace vscode {
* @deprecated Will be replaced by a better API soon.
*/
__electricCharacterSupport
?:
{
brackets
:
{
tokenType
:
string
;
open
:
string
;
close
:
string
;
isElectric
:
boolean
;
}[];
docComment
?:
{
scope
:
string
;
open
:
string
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录