Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
7cbc3587
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
7cbc3587
编写于
9月 21, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor renames
上级
0892555f
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
117 addition
and
75 deletion
+117
-75
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+17
-2
src/vs/editor/common/model/modelLine.ts
src/vs/editor/common/model/modelLine.ts
+6
-6
src/vs/editor/common/model/textModelWithTokens.ts
src/vs/editor/common/model/textModelWithTokens.ts
+36
-36
src/vs/editor/common/model/tokenIterator.ts
src/vs/editor/common/model/tokenIterator.ts
+3
-3
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+28
-1
src/vs/editor/common/modes/supports.ts
src/vs/editor/common/modes/supports.ts
+4
-4
src/vs/editor/common/modes/supports/electricCharacter.ts
src/vs/editor/common/modes/supports/electricCharacter.ts
+2
-2
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
+3
-3
src/vs/editor/test/common/modes/tokenization.test.ts
src/vs/editor/test/common/modes/tokenization.test.ts
+4
-4
src/vs/editor/test/common/modesTestUtils.ts
src/vs/editor/test/common/modesTestUtils.ts
+1
-1
src/vs/languages/html/common/htmlScanner.ts
src/vs/languages/html/common/htmlScanner.ts
+8
-8
src/vs/languages/html/common/htmlWorker.ts
src/vs/languages/html/common/htmlWorker.ts
+5
-5
未找到文件。
src/vs/editor/common/editorCommon.ts
浏览文件 @
7cbc3587
...
...
@@ -1452,10 +1452,25 @@ export interface ICursorStateComputer {
* @internal
*/
export
interface
ILineTokens
{
/**
* Get the number of tokens on this line.
*/
getTokenCount
():
number
;
getTokenStartIndex
(
tokenIndex
:
number
):
number
;
/**
* Get the start offset of the token at `tokenIndex`.
*/
getTokenStartOffset
(
tokenIndex
:
number
):
number
;
/**
* Get the type of the token at `tokenIndex`.
*/
getTokenType
(
tokenIndex
:
number
):
string
;
getTokenEndIndex
(
tokenIndex
:
number
,
textLength
:
number
):
number
;
/**
* Get the end offset of the token at `tokenIndex`.
*/
getTokenEndOffset
(
tokenIndex
:
number
,
textLength
:
number
):
number
;
/**
* Check if tokens have changed. This is called by the view to validate rendered lines
...
...
src/vs/editor/common/model/modelLine.ts
浏览文件 @
7cbc3587
...
...
@@ -746,7 +746,7 @@ export class LineTokens implements ILineTokens {
return
this
.
_tokens
.
length
;
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
TokensBinaryEncoding
.
getStartIndex
(
this
.
_tokens
[
tokenIndex
]);
}
...
...
@@ -754,7 +754,7 @@ export class LineTokens implements ILineTokens {
return
TokensBinaryEncoding
.
getType
(
this
.
map
,
this
.
_tokens
[
tokenIndex
]);
}
public
getTokenEnd
Index
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
public
getTokenEnd
Offset
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
if
(
tokenIndex
+
1
<
this
.
_tokens
.
length
)
{
return
TokensBinaryEncoding
.
getStartIndex
(
this
.
_tokens
[
tokenIndex
+
1
]);
}
...
...
@@ -803,7 +803,7 @@ class EmptyLineTokens implements ILineTokens {
return
0
;
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
0
;
}
...
...
@@ -811,7 +811,7 @@ class EmptyLineTokens implements ILineTokens {
return
strings
.
empty
;
}
public
getTokenEnd
Index
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
public
getTokenEnd
Offset
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
return
0
;
}
...
...
@@ -840,7 +840,7 @@ export class DefaultLineTokens implements ILineTokens {
return
1
;
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
0
;
}
...
...
@@ -848,7 +848,7 @@ export class DefaultLineTokens implements ILineTokens {
return
strings
.
empty
;
}
public
getTokenEnd
Index
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
public
getTokenEnd
Offset
(
tokenIndex
:
number
,
textLength
:
number
):
number
{
return
textLength
;
}
...
...
src/vs/editor/common/model/textModelWithTokens.ts
浏览文件 @
7cbc3587
...
...
@@ -58,8 +58,8 @@ class LineContext implements ILineContext {
return
this
.
_lineTokens
.
getTokenCount
();
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
return
this
.
_lineTokens
.
getTokenStart
Index
(
tokenIndex
);
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
this
.
_lineTokens
.
getTokenStart
Offset
(
tokenIndex
);
}
public
getTokenType
(
tokenIndex
:
number
):
string
{
...
...
@@ -528,7 +528,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
lineTokens
=
this
.
_lines
[
lineNumber
-
1
].
getTokens
(
this
.
_tokensInflatorMap
);
let
currentTokenIndex
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
let
currentTokenStart
=
lineTokens
.
getTokenStartIndex
(
currentTokenIndex
);
let
currentTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
currentTokenIndex
);
let
modeTransitions
=
this
.
_lines
[
lineNumber
-
1
].
getModeTransitions
(
this
.
getModeId
());
let
currentModeIndex
=
ModeTransition
.
findIndexInSegmentsArray
(
modeTransitions
,
position
.
column
-
1
);
...
...
@@ -536,13 +536,13 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
currentModeBrackets
=
LanguageConfigurationRegistry
.
getBracketsSupport
(
currentMode
.
modeId
);
// If position is in between two tokens, try first looking in the previous token
if
(
currentTokenIndex
>
0
&&
currentTokenStart
===
position
.
column
-
1
)
{
if
(
currentTokenIndex
>
0
&&
currentTokenStart
Offset
===
position
.
column
-
1
)
{
let
prevTokenIndex
=
currentTokenIndex
-
1
;
let
prevTokenType
=
lineTokens
.
getTokenType
(
prevTokenIndex
);
// check that previous token is not to be ignored
if
(
!
ignoreBracketsInToken
(
prevTokenType
))
{
let
prevTokenStart
=
lineTokens
.
getTokenStartIndex
(
prevTokenIndex
);
let
prevTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
prevTokenIndex
);
let
prevMode
=
currentMode
;
let
prevModeBrackets
=
currentModeBrackets
;
...
...
@@ -554,9 +554,9 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
if
(
prevModeBrackets
)
{
// limit search in case previous token is very large, there's no need to go beyond `maxBracketLength`
prevTokenStart
=
Math
.
max
(
prevTokenStar
t
,
position
.
column
-
1
-
prevModeBrackets
.
maxBracketLength
);
prevTokenStart
Offset
=
Math
.
max
(
prevTokenStartOffse
t
,
position
.
column
-
1
-
prevModeBrackets
.
maxBracketLength
);
let
foundBracket
=
BracketsUtils
.
findPrevBracketInToken
(
prevModeBrackets
.
reversedRegex
,
lineNumber
,
lineText
,
prevTokenStart
,
currentTokenStar
t
);
let
foundBracket
=
BracketsUtils
.
findPrevBracketInToken
(
prevModeBrackets
.
reversedRegex
,
lineNumber
,
lineText
,
prevTokenStart
Offset
,
currentTokenStartOffse
t
);
// check that we didn't hit a bracket too far away from position
if
(
foundBracket
&&
foundBracket
.
startColumn
<=
position
.
column
&&
position
.
column
<=
foundBracket
.
endColumn
)
{
...
...
@@ -579,15 +579,15 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
if
(
currentModeBrackets
)
{
// limit search to not go before `maxBracketLength`
currentTokenStart
=
Math
.
max
(
currentTokenStar
t
,
position
.
column
-
1
-
currentModeBrackets
.
maxBracketLength
);
currentTokenStart
Offset
=
Math
.
max
(
currentTokenStartOffse
t
,
position
.
column
-
1
-
currentModeBrackets
.
maxBracketLength
);
// limit search to not go after `maxBracketLength`
let
currentTokenEnd
=
lineTokens
.
getTokenEndIndex
(
currentTokenIndex
,
lineText
.
length
);
currentTokenEnd
=
Math
.
min
(
currentTokenEnd
,
position
.
column
-
1
+
currentModeBrackets
.
maxBracketLength
);
let
currentTokenEnd
Offset
=
lineTokens
.
getTokenEndOffset
(
currentTokenIndex
,
lineText
.
length
);
currentTokenEnd
Offset
=
Math
.
min
(
currentTokenEndOffset
,
position
.
column
-
1
+
currentModeBrackets
.
maxBracketLength
);
// it might still be the case that [currentTokenStart -> currentTokenEnd] contains multiple brackets
while
(
true
)
{
let
foundBracket
=
BracketsUtils
.
findNextBracketInText
(
currentModeBrackets
.
forwardRegex
,
lineNumber
,
lineText
.
substring
(
currentTokenStart
,
currentTokenEnd
),
currentTokenStar
t
);
let
foundBracket
=
BracketsUtils
.
findNextBracketInText
(
currentModeBrackets
.
forwardRegex
,
lineNumber
,
lineText
.
substring
(
currentTokenStart
Offset
,
currentTokenEndOffset
),
currentTokenStartOffse
t
);
if
(
!
foundBracket
)
{
// there are no brackets in this text
break
;
...
...
@@ -606,7 +606,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
}
}
currentTokenStart
=
foundBracket
.
endColumn
-
1
;
currentTokenStart
Offset
=
foundBracket
.
endColumn
-
1
;
}
}
}
...
...
@@ -646,10 +646,10 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
currentModeId
=
modeTransitions
[
currentModeIndex
].
modeId
;
let
tokensLength
=
lineTokens
.
getTokenCount
()
-
1
;
let
currentTokenEnd
=
lineText
.
length
;
let
currentTokenEnd
Offset
=
lineText
.
length
;
if
(
lineNumber
===
position
.
lineNumber
)
{
tokensLength
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenEnd
=
position
.
column
-
1
;
currentTokenEnd
Offset
=
position
.
column
-
1
;
currentModeIndex
=
ModeTransition
.
findIndexInSegmentsArray
(
modeTransitions
,
position
.
column
-
1
);
currentModeStart
=
modeTransitions
[
currentModeIndex
].
startIndex
;
...
...
@@ -658,9 +658,9 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
for
(
let
tokenIndex
=
tokensLength
;
tokenIndex
>=
0
;
tokenIndex
--
)
{
let
currentTokenType
=
lineTokens
.
getTokenType
(
tokenIndex
);
let
currentTokenStart
=
lineTokens
.
getTokenStartIndex
(
tokenIndex
);
let
currentTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
tokenIndex
);
if
(
currentTokenStart
<
currentModeStart
)
{
if
(
currentTokenStart
Offset
<
currentModeStart
)
{
currentModeIndex
--
;
currentModeStart
=
modeTransitions
[
currentModeIndex
].
startIndex
;
currentModeId
=
modeTransitions
[
currentModeIndex
].
modeId
;
...
...
@@ -669,7 +669,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
if
(
currentModeId
===
modeId
&&
!
ignoreBracketsInToken
(
currentTokenType
))
{
while
(
true
)
{
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
Offset
,
currentTokenEndOffset
);
if
(
!
r
)
{
break
;
}
...
...
@@ -687,11 +687,11 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
return
r
;
}
currentTokenEnd
=
r
.
startColumn
-
1
;
currentTokenEnd
Offset
=
r
.
startColumn
-
1
;
}
}
currentTokenEnd
=
currentTokenStar
t
;
currentTokenEnd
Offset
=
currentTokenStartOffse
t
;
}
}
...
...
@@ -714,10 +714,10 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
currentModeId
=
modeTransitions
[
currentModeIndex
].
modeId
;
let
startTokenIndex
=
0
;
let
currentTokenStart
=
lineTokens
.
getTokenStartIndex
(
startTokenIndex
);
let
currentTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
startTokenIndex
);
if
(
lineNumber
===
position
.
lineNumber
)
{
startTokenIndex
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenStart
=
Math
.
max
(
currentTokenStar
t
,
position
.
column
-
1
);
currentTokenStart
Offset
=
Math
.
max
(
currentTokenStartOffse
t
,
position
.
column
-
1
);
currentModeIndex
=
ModeTransition
.
findIndexInSegmentsArray
(
modeTransitions
,
position
.
column
-
1
);
nextModeStart
=
(
currentModeIndex
+
1
<
modeTransitions
.
length
?
modeTransitions
[
currentModeIndex
+
1
].
startIndex
:
lineText
.
length
+
1
);
...
...
@@ -726,9 +726,9 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
for
(
let
tokenIndex
=
startTokenIndex
,
tokensLength
=
lineTokens
.
getTokenCount
();
tokenIndex
<
tokensLength
;
tokenIndex
++
)
{
let
currentTokenType
=
lineTokens
.
getTokenType
(
tokenIndex
);
let
currentTokenEnd
=
lineTokens
.
getTokenEndIndex
(
tokenIndex
,
lineText
.
length
);
let
currentTokenEnd
Offset
=
lineTokens
.
getTokenEndOffset
(
tokenIndex
,
lineText
.
length
);
if
(
currentTokenStart
>=
nextModeStart
)
{
if
(
currentTokenStart
Offset
>=
nextModeStart
)
{
currentModeIndex
++
;
nextModeStart
=
(
currentModeIndex
+
1
<
modeTransitions
.
length
?
modeTransitions
[
currentModeIndex
+
1
].
startIndex
:
lineText
.
length
+
1
);
currentModeId
=
modeTransitions
[
currentModeIndex
].
modeId
;
...
...
@@ -736,7 +736,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
if
(
currentModeId
===
modeId
&&
!
ignoreBracketsInToken
(
currentTokenType
))
{
while
(
true
)
{
let
r
=
BracketsUtils
.
findNextBracketInToken
(
bracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
let
r
=
BracketsUtils
.
findNextBracketInToken
(
bracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
Offset
,
currentTokenEndOffset
);
if
(
!
r
)
{
break
;
}
...
...
@@ -754,11 +754,11 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
return
r
;
}
currentTokenStart
=
r
.
endColumn
-
1
;
currentTokenStart
Offset
=
r
.
endColumn
-
1
;
}
}
currentTokenStart
=
currentTokenEnd
;
currentTokenStart
Offset
=
currentTokenEndOffset
;
}
}
...
...
@@ -775,24 +775,24 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
lineText
=
this
.
_lines
[
lineNumber
-
1
].
text
;
let
tokensLength
=
lineTokens
.
getTokenCount
()
-
1
;
let
currentTokenEnd
=
lineText
.
length
;
let
currentTokenEnd
Offset
=
lineText
.
length
;
if
(
lineNumber
===
position
.
lineNumber
)
{
tokensLength
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenEnd
=
position
.
column
-
1
;
currentTokenEnd
Offset
=
position
.
column
-
1
;
}
for
(
let
tokenIndex
=
tokensLength
;
tokenIndex
>=
0
;
tokenIndex
--
)
{
let
currentTokenType
=
lineTokens
.
getTokenType
(
tokenIndex
);
let
currentTokenStart
=
lineTokens
.
getTokenStartIndex
(
tokenIndex
);
let
currentTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
tokenIndex
);
if
(
!
ignoreBracketsInToken
(
currentTokenType
))
{
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
let
r
=
BracketsUtils
.
findPrevBracketInToken
(
reversedBracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
Offset
,
currentTokenEndOffset
);
if
(
r
)
{
return
this
.
_toFoundBracket
(
r
);
}
}
currentTokenEnd
=
currentTokenStar
t
;
currentTokenEnd
Offset
=
currentTokenStartOffse
t
;
}
}
...
...
@@ -809,24 +809,24 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
let
lineText
=
this
.
_lines
[
lineNumber
-
1
].
text
;
let
startTokenIndex
=
0
;
let
currentTokenStart
=
lineTokens
.
getTokenStartIndex
(
startTokenIndex
);
let
currentTokenStart
Offset
=
lineTokens
.
getTokenStartOffset
(
startTokenIndex
);
if
(
lineNumber
===
position
.
lineNumber
)
{
startTokenIndex
=
lineTokens
.
findIndexOfOffset
(
position
.
column
-
1
);
currentTokenStart
=
Math
.
max
(
currentTokenStar
t
,
position
.
column
-
1
);
currentTokenStart
Offset
=
Math
.
max
(
currentTokenStartOffse
t
,
position
.
column
-
1
);
}
for
(
let
tokenIndex
=
startTokenIndex
,
tokensLength
=
lineTokens
.
getTokenCount
();
tokenIndex
<
tokensLength
;
tokenIndex
++
)
{
let
currentTokenType
=
lineTokens
.
getTokenType
(
tokenIndex
);
let
currentTokenEnd
=
lineTokens
.
getTokenEndIndex
(
tokenIndex
,
lineText
.
length
);
let
currentTokenEnd
Offset
=
lineTokens
.
getTokenEndOffset
(
tokenIndex
,
lineText
.
length
);
if
(
!
ignoreBracketsInToken
(
currentTokenType
))
{
let
r
=
BracketsUtils
.
findNextBracketInToken
(
bracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
,
currentTokenEnd
);
let
r
=
BracketsUtils
.
findNextBracketInToken
(
bracketRegex
,
lineNumber
,
lineText
,
currentTokenStart
Offset
,
currentTokenEndOffset
);
if
(
r
)
{
return
this
.
_toFoundBracket
(
r
);
}
}
currentTokenStart
=
currentTokenEnd
;
currentTokenStart
Offset
=
currentTokenEndOffset
;
}
}
...
...
src/vs/editor/common/model/tokenIterator.ts
浏览文件 @
7cbc3587
...
...
@@ -28,7 +28,7 @@ export class TokenIterator implements editorCommon.ITokenIterator {
var
columnIndex
=
position
.
column
-
1
,
tokenEndIndex
=
Number
.
MAX_VALUE
;
for
(
var
i
=
this
.
_currentLineTokens
.
getTokenCount
()
-
1
;
i
>=
0
;
i
--
)
{
let
tokenStartIndex
=
this
.
_currentLineTokens
.
getTokenStart
Index
(
i
);
let
tokenStartIndex
=
this
.
_currentLineTokens
.
getTokenStart
Offset
(
i
);
if
(
tokenStartIndex
<=
columnIndex
&&
columnIndex
<=
tokenEndIndex
)
{
...
...
@@ -97,9 +97,9 @@ export class TokenIterator implements editorCommon.ITokenIterator {
}
private
_current
():
editorCommon
.
ITokenInfo
{
let
startIndex
=
this
.
_currentLineTokens
.
getTokenStart
Index
(
this
.
_currentTokenIndex
);
let
startIndex
=
this
.
_currentLineTokens
.
getTokenStart
Offset
(
this
.
_currentTokenIndex
);
let
type
=
this
.
_currentLineTokens
.
getTokenType
(
this
.
_currentTokenIndex
);
let
endIndex
=
this
.
_currentLineTokens
.
getTokenEnd
Index
(
this
.
_currentTokenIndex
,
this
.
_model
.
getLineContent
(
this
.
_currentLineNumber
).
length
);
let
endIndex
=
this
.
_currentLineTokens
.
getTokenEnd
Offset
(
this
.
_currentTokenIndex
,
this
.
_model
.
getLineContent
(
this
.
_currentLineNumber
).
length
);
return
{
token
:
new
Token
(
startIndex
,
type
),
...
...
src/vs/editor/common/modes.ts
浏览文件 @
7cbc3587
...
...
@@ -170,13 +170,40 @@ export interface IModeDescriptor {
* @internal
*/
export
interface
ILineContext
{
/**
* Get the content of the line.
*/
getLineContent
():
string
;
/**
* The mode transitions on this line.
*/
modeTransitions
:
ModeTransition
[];
/**
* Get the number of tokens on this line.
*/
getTokenCount
():
number
;
getTokenStartIndex
(
tokenIndex
:
number
):
number
;
/**
* Get the start offset of the token at `tokenIndex`.
*/
getTokenStartOffset
(
tokenIndex
:
number
):
number
;
/**
* Get the type of the token at `tokenIndex`.
*/
getTokenType
(
tokenIndex
:
number
):
string
;
/**
* Find the token containing offset `offset`.
* For example, with the following tokens [0, 5), [5, 9), [9, infinity)
* Searching for 0, 1, 2, 3 or 4 will return 0.
* Searching for 5, 6, 7 or 8 will return 1.
* Searching for 9, 10, 11, ... will return 2.
* @param offset The search offset
* @return The index of the token containing the offset.
*/
findIndexOfOffset
(
offset
:
number
):
number
;
}
...
...
src/vs/editor/common/modes/supports.ts
浏览文件 @
7cbc3587
...
...
@@ -42,13 +42,13 @@ export function handleEvent<T>(context:modes.ILineContext, offset:number, runner
let
nextTokenAfterMode
=
-
1
;
if
(
modeIndex
+
1
<
modeTransitions
.
length
)
{
nextTokenAfterMode
=
context
.
findIndexOfOffset
(
modeTransitions
[
modeIndex
+
1
].
startIndex
);
nextCharacterAfterModeIndex
=
context
.
getTokenStart
Index
(
nextTokenAfterMode
);
nextCharacterAfterModeIndex
=
context
.
getTokenStart
Offset
(
nextTokenAfterMode
);
}
else
{
nextTokenAfterMode
=
context
.
getTokenCount
();
nextCharacterAfterModeIndex
=
context
.
getLineContent
().
length
;
}
let
firstTokenCharacterOffset
=
context
.
getTokenStart
Index
(
firstTokenInModeIndex
);
let
firstTokenCharacterOffset
=
context
.
getTokenStart
Offset
(
firstTokenInModeIndex
);
let
newCtx
=
new
FilteredLineContext
(
context
,
nestedModeId
,
firstTokenInModeIndex
,
nextTokenAfterMode
,
firstTokenCharacterOffset
,
nextCharacterAfterModeIndex
);
return
runner
(
nestedModeId
,
newCtx
,
offset
-
firstTokenCharacterOffset
);
}
...
...
@@ -88,8 +88,8 @@ export class FilteredLineContext implements modes.ILineContext {
return
this
.
_actual
.
findIndexOfOffset
(
offset
+
this
.
_firstTokenCharacterOffset
)
-
this
.
_firstTokenInModeIndex
;
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
return
this
.
_actual
.
getTokenStart
Index
(
tokenIndex
+
this
.
_firstTokenInModeIndex
)
-
this
.
_firstTokenCharacterOffset
;
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
this
.
_actual
.
getTokenStart
Offset
(
tokenIndex
+
this
.
_firstTokenInModeIndex
)
-
this
.
_firstTokenCharacterOffset
;
}
public
getTokenType
(
tokenIndex
:
number
):
string
{
...
...
src/vs/editor/common/modes/supports/electricCharacter.ts
浏览文件 @
7cbc3587
...
...
@@ -131,7 +131,7 @@ export class Brackets {
let
lineText
=
context
.
getLineContent
();
let
tokenIndex
=
context
.
findIndexOfOffset
(
offset
);
let
tokenStart
=
context
.
getTokenStart
Index
(
tokenIndex
);
let
tokenStart
=
context
.
getTokenStart
Offset
(
tokenIndex
);
let
tokenEnd
=
offset
+
1
;
var
firstNonWhitespaceIndex
=
strings
.
firstNonWhitespaceIndex
(
context
.
getLineContent
());
...
...
@@ -181,7 +181,7 @@ export class Brackets {
// check if the full open bracket matches
let
lastTokenIndex
=
context
.
findIndexOfOffset
(
offset
);
if
(
line
.
substring
(
context
.
getTokenStart
Index
(
lastTokenIndex
),
offset
+
1
/* include electric char*/
)
!==
pair
.
open
)
{
if
(
line
.
substring
(
context
.
getTokenStart
Offset
(
lastTokenIndex
),
offset
+
1
/* include electric char*/
)
!==
pair
.
open
)
{
continue
;
}
...
...
src/vs/editor/contrib/smartSelect/common/tokenTree.ts
浏览文件 @
7cbc3587
...
...
@@ -169,7 +169,7 @@ class TokenScanner {
}
let
tokenType
=
this
.
_currentLineTokens
.
getTokenType
(
this
.
_currentTokenIndex
);
let
tokenEndIndex
=
this
.
_currentLineTokens
.
getTokenEnd
Index
(
this
.
_currentTokenIndex
,
this
.
_currentLineText
.
length
);
let
tokenEndIndex
=
this
.
_currentLineTokens
.
getTokenEnd
Offset
(
this
.
_currentTokenIndex
,
this
.
_currentLineText
.
length
);
let
tmpTokenEndIndex
=
tokenEndIndex
;
let
nextBracket
:
Range
=
null
;
...
...
@@ -211,7 +211,7 @@ class TokenScanner {
this
.
_currentTokenStart
=
tmpTokenEndIndex
;
}
else
{
this
.
_currentTokenIndex
+=
1
;
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStart
Index
(
this
.
_currentTokenIndex
)
:
0
);
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStart
Offset
(
this
.
_currentTokenIndex
)
:
0
);
}
return
token
;
}
...
...
@@ -234,7 +234,7 @@ class TokenScanner {
this
.
_currentTokenStart
=
nextBracket
.
endColumn
-
1
;
}
else
{
this
.
_currentTokenIndex
+=
1
;
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStart
Index
(
this
.
_currentTokenIndex
)
:
0
);
this
.
_currentTokenStart
=
(
this
.
_currentTokenIndex
<
this
.
_currentLineTokens
.
getTokenCount
()
?
this
.
_currentLineTokens
.
getTokenStart
Offset
(
this
.
_currentTokenIndex
)
:
0
);
}
return
token
;
}
...
...
src/vs/editor/test/common/modes/tokenization.test.ts
浏览文件 @
7cbc3587
...
...
@@ -301,11 +301,11 @@ suite('Editor Modes - Tokenization', () => {
handleEvent
(
createMockLineContext
(
'
abc (def
'
,
lineTokens
),
0
,
(
modeId
:
string
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
assert
.
deepEqual
(
modeId
,
'
A
'
);
assert
.
equal
(
context
.
getTokenCount
(),
3
);
assert
.
equal
(
context
.
getTokenStart
Index
(
0
),
0
);
assert
.
equal
(
context
.
getTokenStart
Offset
(
0
),
0
);
assert
.
equal
(
context
.
getTokenType
(
0
),
'
A.abc
'
);
assert
.
equal
(
context
.
getTokenStart
Index
(
1
),
3
);
assert
.
equal
(
context
.
getTokenStart
Offset
(
1
),
3
);
assert
.
equal
(
context
.
getTokenType
(
1
),
''
);
assert
.
equal
(
context
.
getTokenStart
Index
(
2
),
4
);
assert
.
equal
(
context
.
getTokenStart
Offset
(
2
),
4
);
assert
.
equal
(
context
.
getTokenType
(
2
),
'
A.(
'
);
assert
.
deepEqual
(
offset
,
0
);
assert
.
equal
(
context
.
getLineContent
(),
'
abc (
'
);
...
...
@@ -314,7 +314,7 @@ suite('Editor Modes - Tokenization', () => {
handleEvent
(
createMockLineContext
(
'
abc (def
'
,
lineTokens
),
6
,
(
modeId
:
string
,
context
:
modes
.
ILineContext
,
offset
:
number
)
=>
{
assert
.
deepEqual
(
modeId
,
'
B
'
);
assert
.
equal
(
context
.
getTokenCount
(),
1
);
assert
.
equal
(
context
.
getTokenStart
Index
(
0
),
0
);
assert
.
equal
(
context
.
getTokenStart
Offset
(
0
),
0
);
assert
.
equal
(
context
.
getTokenType
(
0
),
'
B.def
'
);
assert
.
deepEqual
(
offset
,
1
);
assert
.
equal
(
context
.
getLineContent
(),
'
def
'
);
...
...
src/vs/editor/test/common/modesTestUtils.ts
浏览文件 @
7cbc3587
...
...
@@ -52,7 +52,7 @@ class TestLineContext implements modes.ILineContext {
return
this
.
_tokens
.
length
;
}
public
getTokenStart
Index
(
tokenIndex
:
number
):
number
{
public
getTokenStart
Offset
(
tokenIndex
:
number
):
number
{
return
this
.
_tokens
[
tokenIndex
].
startIndex
;
}
...
...
src/vs/languages/html/common/htmlScanner.ts
浏览文件 @
7cbc3587
...
...
@@ -54,16 +54,16 @@ export function getScanner(model: EditorCommon.ITokenizedModel, position:EditorC
var
tokensOnLine
=
tokens
.
getTokenCount
();
var
tokenType
=
tokens
.
getTokenType
(
tokenIndex
);
var
tokenStart
=
tokens
.
getTokenStart
Index
(
tokenIndex
);
var
tokenEnd
=
tokens
.
getTokenEnd
Index
(
tokenIndex
,
lineContent
.
length
);
var
tokenStart
=
tokens
.
getTokenStart
Offset
(
tokenIndex
);
var
tokenEnd
=
tokens
.
getTokenEnd
Offset
(
tokenIndex
,
lineContent
.
length
);
if
((
tokenType
===
''
||
isDelimiter
(
tokenType
))
&&
tokenStart
===
lineOffset
)
{
tokenIndex
--
;
if
(
tokenIndex
>=
0
)
{
// we are at the end of a different token
tokenType
=
tokens
.
getTokenType
(
tokenIndex
);
tokenStart
=
tokens
.
getTokenStart
Index
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Index
(
tokenIndex
,
lineContent
.
length
);
tokenStart
=
tokens
.
getTokenStart
Offset
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Offset
(
tokenIndex
,
lineContent
.
length
);
}
else
{
tokenType
=
''
;
tokenStart
=
tokenEnd
=
0
;
...
...
@@ -88,8 +88,8 @@ export function getScanner(model: EditorCommon.ITokenizedModel, position:EditorC
do
{
while
(
tokenIndex
>=
0
)
{
tokenType
=
tokens
.
getTokenType
(
tokenIndex
);
tokenStart
=
tokens
.
getTokenStart
Index
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Index
(
tokenIndex
,
lineContent
.
length
);
tokenStart
=
tokens
.
getTokenStart
Offset
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Offset
(
tokenIndex
,
lineContent
.
length
);
if
(
isInterestingToken
(
tokenType
))
{
return
true
;
...
...
@@ -118,8 +118,8 @@ export function getScanner(model: EditorCommon.ITokenizedModel, position:EditorC
do
{
while
(
tokenIndex
<
tokensOnLine
)
{
tokenType
=
tokens
.
getTokenType
(
tokenIndex
);
tokenStart
=
tokens
.
getTokenStart
Index
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Index
(
tokenIndex
,
lineContent
.
length
);
tokenStart
=
tokens
.
getTokenStart
Offset
(
tokenIndex
);
tokenEnd
=
tokens
.
getTokenEnd
Offset
(
tokenIndex
,
lineContent
.
length
);
if
(
isInterestingToken
(
tokenType
))
{
return
true
;
...
...
src/vs/languages/html/common/htmlWorker.ts
浏览文件 @
7cbc3587
...
...
@@ -561,8 +561,8 @@ export class HTMLWorker {
break
;
case
ATTRIB_NAME
:
nextTokenEndIndex
=
tokens
.
getTokenEnd
Index
(
i
,
lineContentLength
);
tokenContent
=
lineContent
.
substring
(
tokens
.
getTokenStart
Index
(
i
),
nextTokenEndIndex
).
toLowerCase
();
nextTokenEndIndex
=
tokens
.
getTokenEnd
Offset
(
i
,
lineContentLength
);
tokenContent
=
lineContent
.
substring
(
tokens
.
getTokenStart
Offset
(
i
),
nextTokenEndIndex
).
toLowerCase
();
if
(
tokenContent
===
'
src
'
||
tokenContent
===
'
href
'
)
{
state
=
LinkDetectionState
.
AFTER_HREF_OR_SRC
;
...
...
@@ -573,10 +573,10 @@ export class HTMLWorker {
case
ATTRIB_VALUE
:
if
(
state
===
LinkDetectionState
.
AFTER_HREF_OR_SRC
)
{
nextTokenEndIndex
=
tokens
.
getTokenEnd
Index
(
i
,
lineContentLength
);
tokenContent
=
lineContent
.
substring
(
tokens
.
getTokenStart
Index
(
i
),
nextTokenEndIndex
);
nextTokenEndIndex
=
tokens
.
getTokenEnd
Offset
(
i
,
lineContentLength
);
tokenContent
=
lineContent
.
substring
(
tokens
.
getTokenStart
Offset
(
i
),
nextTokenEndIndex
);
link
=
this
.
createLink
(
modelAbsoluteUrl
,
rootAbsoluteUrl
,
tokenContent
,
lineNumber
,
tokens
.
getTokenStart
Index
(
i
)
+
2
,
nextTokenEndIndex
);
link
=
this
.
createLink
(
modelAbsoluteUrl
,
rootAbsoluteUrl
,
tokenContent
,
lineNumber
,
tokens
.
getTokenStart
Offset
(
i
)
+
2
,
nextTokenEndIndex
);
if
(
link
)
{
newLinks
.
push
(
link
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录