Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e573984e
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,发现更多精彩内容 >>
提交
e573984e
编写于
12月 17, 2015
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #1386: Guess insertSpaces:false if more lines are indented with tabs
上级
ccc0b4ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
230 addition
and
64 deletion
+230
-64
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+20
-30
src/vs/editor/test/common/model/textModel.test.ts
src/vs/editor/test/common/model/textModel.test.ts
+210
-34
未找到文件。
src/vs/editor/common/model/textModel.ts
浏览文件 @
e573984e
...
...
@@ -472,7 +472,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
throw
new
Error
(
'
TextModel.guessIndentation: Model is disposed
'
);
}
var
i
:
number
,
let
i
:
number
,
len
:
number
,
factors
=
this
.
_extractIndentationFactors
(),
linesWithIndentationCount
=
factors
.
linesWithIndentationCount
,
...
...
@@ -481,29 +481,12 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
relativeSpaceCounts
=
factors
.
relativeSpaceCounts
;
// Count the absolute number of times tabs or spaces have been used as indentation
var
linesIndentedWithSpaces
=
0
;
let
linesIndentedWithSpaces
=
0
;
for
(
i
=
1
,
len
=
absoluteSpaceCounts
.
length
;
i
<
len
;
i
++
)
{
linesIndentedWithSpaces
+=
(
absoluteSpaceCounts
[
i
]
||
0
);
}
// Give preference to spaces over tabs (when evidence is the same)
// or when there are not enough clues (too little indentation in the file)
if
(
linesIndentedWithTabs
>=
linesIndentedWithSpaces
)
{
return
{
insertSpaces
:
true
,
tabSize
:
defaultTabSize
};
}
if
(
linesWithIndentationCount
<
6
&&
linesIndentedWithTabs
>
0
)
{
// Making a guess with 6 indented lines, of which tabs are used besides spaces is very difficult
return
{
insertSpaces
:
true
,
tabSize
:
defaultTabSize
};
}
var
candidate
:
number
,
let
candidate
:
number
,
candidateScore
:
number
,
penalization
:
number
,
m
:
number
,
...
...
@@ -528,18 +511,18 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
scores
[
candidate
]
=
candidateScore
/
(
1
+
penalization
);
}
//
console.log('----------');
//
console.log('linesWithIndentationCount: ', linesWithIndentationCount);
//
console.log('linesIndentedWithTabs: ', linesIndentedWithTabs);
//
console.log('absoluteSpaceCounts: ', absoluteSpaceCounts);
//
console.log('relativeSpaceCounts: ', relativeSpaceCounts);
//
console.log('=> linesIndentedWithSpaces: ', linesIndentedWithSpaces);
//
console.log('=> scores: ', scores);
//
console.log('----------');
//
console.log('linesWithIndentationCount: ', linesWithIndentationCount);
//
console.log('linesIndentedWithTabs: ', linesIndentedWithTabs);
//
console.log('absoluteSpaceCounts: ', absoluteSpaceCounts);
//
console.log('relativeSpaceCounts: ', relativeSpaceCounts);
//
console.log('=> linesIndentedWithSpaces: ', linesIndentedWithSpaces);
//
console.log('=> scores: ', scores);
var
bestCandidate
=
defaultTabSize
,
let
bestCandidate
=
defaultTabSize
,
bestCandidateScore
=
0
;
var
allowedGuesses
=
[
2
,
4
,
6
,
8
];
let
allowedGuesses
=
[
2
,
4
,
6
,
8
];
for
(
i
=
0
;
i
<
allowedGuesses
.
length
;
i
++
)
{
candidate
=
allowedGuesses
[
i
];
...
...
@@ -549,8 +532,15 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
bestCandidateScore
=
candidateScore
;
}
}
let
insertSpaces
=
true
;
if
(
linesIndentedWithTabs
>
linesIndentedWithSpaces
)
{
// More lines indented with tabs
insertSpaces
=
false
;
}
return
{
insertSpaces
:
true
,
insertSpaces
:
insertSpaces
,
tabSize
:
bestCandidate
};
}
...
...
src/vs/editor/test/common/model/textModel.test.ts
浏览文件 @
e573984e
...
...
@@ -15,15 +15,11 @@ function testGuessIndentation(expectedInsertSpaces:boolean, expectedTabSize:numb
m
.
dispose
();
assert
.
equal
(
r
.
insertSpaces
,
expectedInsertSpaces
,
msg
);
if
(
expectedInsertSpaces
)
{
assert
.
equal
(
r
.
tabSize
,
expectedTabSize
,
msg
);
}
else
{
assert
.
equal
(
r
.
tabSize
,
1337
,
msg
);
}
assert
.
equal
(
r
.
tabSize
,
expectedTabSize
,
msg
);
}
function
guessesTabs
(
text
:
string
[],
msg
?:
string
):
void
{
testGuessIndentation
(
false
,
0
,
text
,
msg
);
function
guessesTabs
(
expectedTabSize
:
number
,
text
:
string
[],
msg
?:
string
):
void
{
testGuessIndentation
(
false
,
expectedTabSize
,
text
,
msg
);
}
function
guessesSpaces
(
expectedTabSize
:
number
,
text
:
string
[],
msg
?:
string
):
void
{
...
...
@@ -63,25 +59,110 @@ suite('Editor Model - TextModel', () => {
test
(
'
guess indentation 1
'
,
()
=>
{
// Defaults to tabs
guessesSpaces
(
1337
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
]);
]
,
'
no clues
'
);
// Gives preference to tabs
guessesSpaces
(
1337
,
[
guessesTabs
(
1337
,
[
'
\t
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
]);
guessesSpaces
(
1337
,
[
],
'
no spaces, 1xTAB
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
],
'
1x2
'
);
guessesTabs
(
1337
,
[
'
\t
x
'
,
'
\t
x
'
,
'
\t
x
'
,
'
\t
x
'
,
'
\t
x
'
,
'
\t
x
'
,
'
\t
x
'
],
'
7xTAB
'
);
guessesSpaces
(
2
,
[
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
],
'
4x2, 4xTAB
'
);
guessesTabs
(
1337
,
[
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
]);
guessesSpaces
(
1337
,
[
],
'
4x1, 4xTAB
'
);
guessesTabs
(
2
,
[
'
\t
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
],
'
4x2, 5xTAB
'
);
guessesTabs
(
2
,
[
'
\t
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
],
'
1x2, 5xTAB
'
);
guessesTabs
(
4
,
[
'
\t
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
]);
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
],
'
1x4, 5xTAB
'
);
guessesTabs
(
2
,
[
'
\t
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
'
\t
x
'
,
'
x
'
,
],
'
1x2, 1x4, 5xTAB
'
);
guessesSpaces
(
1337
,
[
'
x
'
,
...
...
@@ -98,74 +179,156 @@ suite('Editor Model - TextModel', () => {
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
'
'
,
],
'
whitespace lines don
\'
t count
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
],
'
odd number is not allowed: 2x3, 1x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
odd number is not allowed: 6x3, 3x4
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
],
'
odd number is not allowed: 2x5, 1x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
odd number is not allowed: 6x5, 3x4
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
],
'
odd number is not allowed: 2x7, 1x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
odd number is not allowed: 6x7, 3x4
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
],
'
4x2
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
8x2
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x2
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
8x2
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
],
'
1x2, 1x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
4x2, 4x4
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x2, 1x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
6x2, 3x4
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x2, 2x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
4x2, 4x4
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
1x2, 2x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x2, 4x4
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x4
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
8x4
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
1x2, 2x4, 1x6
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
2x2, 4x4, 2x6
'
);
guessesSpaces
(
2
,
[
'
x
'
,
'
x
'
,
...
...
@@ -182,7 +345,13 @@ suite('Editor Model - TextModel', () => {
'
x
'
,
'
x
'
,
'
x
'
,
],
'
3x4, 1x5, 1x8
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
6x4, 2x5, 2x8
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
...
...
@@ -200,7 +369,14 @@ suite('Editor Model - TextModel', () => {
'
x
'
,
'
x
'
,
'
x
'
,
],
'
3x4, 1x5, 2x8
'
);
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
'
x
'
,
],
'
6x4, 2x5, 4x8
'
);
guessesSpaces
(
4
,
[
'
x
'
,
'
x
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录