Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
62c6e28b
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,发现更多精彩内容 >>
提交
62c6e28b
编写于
1月 05, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move computeIndentLevel to TextModel; renames
上级
bd701a22
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
46 addition
and
48 deletion
+46
-48
src/vs/editor/common/model/indentationGuesser.ts
src/vs/editor/common/model/indentationGuesser.ts
+6
-6
src/vs/editor/common/model/modelLine.ts
src/vs/editor/common/model/modelLine.ts
+0
-30
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+34
-5
src/vs/editor/contrib/folding/indentRangeProvider.ts
src/vs/editor/contrib/folding/indentRangeProvider.ts
+3
-3
src/vs/editor/contrib/quickFix/lightBulbWidget.ts
src/vs/editor/contrib/quickFix/lightBulbWidget.ts
+2
-2
src/vs/editor/test/common/model/model.line.test.ts
src/vs/editor/test/common/model/model.line.test.ts
+1
-2
未找到文件。
src/vs/editor/common/model/indentationGuesser.ts
浏览文件 @
62c6e28b
...
...
@@ -7,12 +7,12 @@
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
ITextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
export
interface
IIndentationGuesser
Target
{
export
interface
IIndentationGuesser
Source
{
getLineCount
():
number
;
getLineContent
(
lineNumber
:
number
):
string
;
}
export
class
IndentationGuesserTextBuffer
Target
implements
IIndentationGuesserTarget
{
export
class
IndentationGuesserTextBuffer
Source
implements
IIndentationGuesserSource
{
constructor
(
private
readonly
_buffer
:
ITextBuffer
...
...
@@ -27,7 +27,7 @@ export class IndentationGuesserTextBufferTarget implements IIndentationGuesserTa
}
}
export
class
IndentationGuesserStringArray
Target
implements
IIndentationGuesserTarget
{
export
class
IndentationGuesserStringArray
Source
implements
IIndentationGuesserSource
{
constructor
(
private
readonly
_lines
:
string
[]
...
...
@@ -116,9 +116,9 @@ export interface IGuessedIndentation {
insertSpaces
:
boolean
;
}
export
function
guessIndentation
(
target
:
IIndentationGuesserTarget
,
defaultTabSize
:
number
,
defaultInsertSpaces
:
boolean
):
IGuessedIndentation
{
export
function
guessIndentation
(
source
:
IIndentationGuesserSource
,
defaultTabSize
:
number
,
defaultInsertSpaces
:
boolean
):
IGuessedIndentation
{
// Look at most at the first 10k lines
const
linesCount
=
Math
.
min
(
target
.
getLineCount
(),
10000
);
const
linesCount
=
Math
.
min
(
source
.
getLineCount
(),
10000
);
let
linesIndentedWithTabsCount
=
0
;
// number of lines that contain at least one tab in indentation
let
linesIndentedWithSpacesCount
=
0
;
// number of lines that contain only spaces in indentation
...
...
@@ -132,7 +132,7 @@ export function guessIndentation(target: IIndentationGuesserTarget, defaultTabSi
let
spacesDiffCount
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
];
// `tabSize` scores
for
(
let
lineNumber
=
1
;
lineNumber
<=
linesCount
;
lineNumber
++
)
{
let
currentLineText
=
target
.
getLineContent
(
lineNumber
);
let
currentLineText
=
source
.
getLineContent
(
lineNumber
);
let
currentLineHasContent
=
false
;
// does `currentLineText` contain non-whitespace chars
let
currentLineIndentation
=
0
;
// index at which `currentLineText` contains the first non-whitespace char
...
...
src/vs/editor/common/model/modelLine.ts
浏览文件 @
62c6e28b
...
...
@@ -5,7 +5,6 @@
'
use strict
'
;
import
{
IState
,
FontStyle
,
StandardTokenType
,
MetadataConsts
,
ColorId
,
LanguageId
,
ITokenizationSupport
,
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
LineTokens
}
from
'
vs/editor/common/core/lineTokens
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -16,35 +15,6 @@ import { ITextBuffer } from 'vs/editor/common/model/textBuffer';
import
{
TokenizationResult2
}
from
'
vs/editor/common/core/token
'
;
import
{
nullTokenize2
}
from
'
vs/editor/common/modes/nullMode
'
;
/**
* Returns:
* - -1 => the line consists of whitespace
* - otherwise => the indent level is returned value
*/
export
function
computeIndentLevel
(
line
:
string
,
tabSize
:
number
):
number
{
let
indent
=
0
;
let
i
=
0
;
let
len
=
line
.
length
;
while
(
i
<
len
)
{
let
chCode
=
line
.
charCodeAt
(
i
);
if
(
chCode
===
CharCode
.
Space
)
{
indent
++
;
}
else
if
(
chCode
===
CharCode
.
Tab
)
{
indent
=
indent
-
indent
%
tabSize
+
tabSize
;
}
else
{
break
;
}
i
++
;
}
if
(
i
===
len
)
{
return
-
1
;
// line only consists of whitespace
}
return
indent
;
}
function
getDefaultMetadata
(
topLevelLanguageId
:
LanguageId
):
number
{
return
(
(
topLevelLanguageId
<<
MetadataConsts
.
LANGUAGEID_OFFSET
)
...
...
src/vs/editor/common/model/textModel.ts
浏览文件 @
62c6e28b
...
...
@@ -28,8 +28,8 @@ import { Position, IPosition } from 'vs/editor/common/core/position';
import
{
LanguageConfigurationRegistry
}
from
'
vs/editor/common/modes/languageConfigurationRegistry
'
;
import
{
LineTokens
}
from
'
vs/editor/common/core/lineTokens
'
;
import
{
getWordAtText
}
from
'
vs/editor/common/model/wordHelper
'
;
import
{
ModelLinesTokens
,
computeIndentLevel
,
ModelTokensChangedEventBuilder
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
guessIndentation
,
IndentationGuesserTextBuffer
Target
,
IndentationGuesserStringArrayTarget
}
from
'
vs/editor/common/model/indentationGuesser
'
;
import
{
ModelLinesTokens
,
ModelTokensChangedEventBuilder
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
guessIndentation
,
IndentationGuesserTextBuffer
Source
,
IndentationGuesserStringArraySource
}
from
'
vs/editor/common/model/indentationGuesser
'
;
import
{
EDITOR_MODEL_DEFAULTS
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
TextModelSearch
,
SearchParams
}
from
'
vs/editor/common/model/textModelSearch
'
;
import
{
TextBuffer
,
ITextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
...
...
@@ -82,7 +82,7 @@ export class TextModel extends Disposable implements model.ITextModel {
let
resolvedOpts
:
model
.
TextModelResolvedOptions
;
if
(
options
.
detectIndentation
)
{
const
guessedIndentation
=
guessIndentation
(
new
IndentationGuesserStringArray
Target
(
textSource
.
lines
),
options
.
tabSize
,
options
.
insertSpaces
);
const
guessedIndentation
=
guessIndentation
(
new
IndentationGuesserStringArray
Source
(
textSource
.
lines
),
options
.
tabSize
,
options
.
insertSpaces
);
resolvedOpts
=
new
model
.
TextModelResolvedOptions
({
tabSize
:
guessedIndentation
.
tabSize
,
insertSpaces
:
guessedIndentation
.
insertSpaces
,
...
...
@@ -515,7 +515,7 @@ export class TextModel extends Disposable implements model.ITextModel {
public
detectIndentation
(
defaultInsertSpaces
:
boolean
,
defaultTabSize
:
number
):
void
{
this
.
_assertNotDisposed
();
let
guessedIndentation
=
guessIndentation
(
new
IndentationGuesserTextBuffer
Target
(
this
.
_buffer
),
defaultTabSize
,
defaultInsertSpaces
);
let
guessedIndentation
=
guessIndentation
(
new
IndentationGuesserTextBuffer
Source
(
this
.
_buffer
),
defaultTabSize
,
defaultInsertSpaces
);
this
.
updateOptions
({
insertSpaces
:
guessedIndentation
.
insertSpaces
,
tabSize
:
guessedIndentation
.
tabSize
...
...
@@ -1944,8 +1944,37 @@ export class TextModel extends Disposable implements model.ITextModel {
};
}
/**
* Returns:
* - -1 => the line consists of whitespace
* - otherwise => the indent level is returned value
*/
public
static
computeIndentLevel
(
line
:
string
,
tabSize
:
number
):
number
{
let
indent
=
0
;
let
i
=
0
;
let
len
=
line
.
length
;
while
(
i
<
len
)
{
let
chCode
=
line
.
charCodeAt
(
i
);
if
(
chCode
===
CharCode
.
Space
)
{
indent
++
;
}
else
if
(
chCode
===
CharCode
.
Tab
)
{
indent
=
indent
-
indent
%
tabSize
+
tabSize
;
}
else
{
break
;
}
i
++
;
}
if
(
i
===
len
)
{
return
-
1
;
// line only consists of whitespace
}
return
indent
;
}
private
_computeIndentLevel
(
lineIndex
:
number
):
number
{
return
computeIndentLevel
(
this
.
_buffer
.
getLineContent
(
lineIndex
+
1
),
this
.
_options
.
tabSize
);
return
TextModel
.
computeIndentLevel
(
this
.
_buffer
.
getLineContent
(
lineIndex
+
1
),
this
.
_options
.
tabSize
);
}
public
getLinesIndentGuides
(
startLineNumber
:
number
,
endLineNumber
:
number
):
number
[]
{
...
...
src/vs/editor/contrib/folding/indentRangeProvider.ts
浏览文件 @
62c6e28b
...
...
@@ -7,8 +7,8 @@
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
FoldingMarkers
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
computeIndentLevel
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
FoldingRanges
,
MAX_LINE_NUMBER
}
from
'
vs/editor/contrib/folding/foldingRanges
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
const
MAX_FOLDING_REGIONS_FOR_INDENT_LIMIT
=
5000
;
...
...
@@ -71,7 +71,7 @@ export class RangesCollector {
for
(
let
i
=
this
.
_length
-
1
,
k
=
0
;
i
>=
0
;
i
--
)
{
let
startIndex
=
this
.
_startIndexes
[
i
];
let
lineContent
=
model
.
getLineContent
(
startIndex
);
let
indent
=
computeIndentLevel
(
lineContent
,
tabSize
);
let
indent
=
TextModel
.
computeIndentLevel
(
lineContent
,
tabSize
);
if
(
indent
<
maxIndent
)
{
startIndexes
[
k
]
=
startIndex
;
endIndexes
[
k
]
=
this
.
_endIndexes
[
i
];
...
...
@@ -101,7 +101,7 @@ export function computeRanges(model: ITextModel, offSide: boolean, markers?: Fol
for
(
let
line
=
model
.
getLineCount
();
line
>
0
;
line
--
)
{
let
lineContent
=
model
.
getLineContent
(
line
);
let
indent
=
computeIndentLevel
(
lineContent
,
tabSize
);
let
indent
=
TextModel
.
computeIndentLevel
(
lineContent
,
tabSize
);
let
previous
=
previousRegions
[
previousRegions
.
length
-
1
];
if
(
indent
===
-
1
)
{
if
(
offSide
&&
!
previous
.
marker
)
{
...
...
src/vs/editor/contrib/quickFix/lightBulbWidget.ts
浏览文件 @
62c6e28b
...
...
@@ -12,7 +12,7 @@ import { GlobalMouseMoveMonitor, IStandardMouseMoveEventData, standardMouseMoveM
import
*
as
dom
from
'
vs/base/browser/dom
'
;
import
{
ICodeEditor
,
IContentWidget
,
IContentWidgetPosition
,
ContentWidgetPositionPreference
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
QuickFixComputeEvent
}
from
'
./quickFixModel
'
;
import
{
computeIndentLevel
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
export
class
LightBulbWidget
implements
IDisposable
,
IContentWidget
{
...
...
@@ -139,7 +139,7 @@ export class LightBulbWidget implements IDisposable, IContentWidget {
const
model
=
this
.
_editor
.
getModel
();
const
tabSize
=
model
.
getOptions
().
tabSize
;
const
lineContent
=
model
.
getLineContent
(
lineNumber
);
const
indent
=
computeIndentLevel
(
lineContent
,
tabSize
);
const
indent
=
TextModel
.
computeIndentLevel
(
lineContent
,
tabSize
);
const
lineHasSpace
=
config
.
fontInfo
.
spaceWidth
*
indent
>
22
;
let
effectiveLineNumber
=
lineNumber
;
...
...
src/vs/editor/test/common/model/model.line.test.ts
浏览文件 @
62c6e28b
...
...
@@ -6,7 +6,6 @@
import
*
as
assert
from
'
assert
'
;
import
{
LineTokens
}
from
'
vs/editor/common/core/lineTokens
'
;
import
{
computeIndentLevel
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
LanguageIdentifier
,
MetadataConsts
}
from
'
vs/editor/common/modes
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ViewLineToken
,
ViewLineTokenFactory
}
from
'
vs/editor/test/common/core/viewLineToken
'
;
...
...
@@ -46,7 +45,7 @@ function assertLineTokens(__actual: LineTokens, _expected: TestToken[]): void {
suite
(
'
ModelLine - getIndentLevel
'
,
()
=>
{
function
assertIndentLevel
(
text
:
string
,
expected
:
number
,
tabSize
:
number
=
4
):
void
{
let
actual
=
computeIndentLevel
(
text
,
tabSize
);
let
actual
=
TextModel
.
computeIndentLevel
(
text
,
tabSize
);
assert
.
equal
(
actual
,
expected
,
text
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录