Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
668dc067
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,发现更多精彩内容 >>
提交
668dc067
编写于
3月 02, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract more code to textSource.ts
上级
220a10c2
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
131 addition
and
119 deletion
+131
-119
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+1
-31
src/vs/editor/common/model/editableTextModel.ts
src/vs/editor/common/model/editableTextModel.ts
+2
-1
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+12
-43
src/vs/editor/common/model/textModelWithDecorations.ts
src/vs/editor/common/model/textModelWithDecorations.ts
+2
-1
src/vs/editor/common/model/textModelWithMarkers.ts
src/vs/editor/common/model/textModelWithMarkers.ts
+2
-1
src/vs/editor/common/model/textModelWithTokens.ts
src/vs/editor/common/model/textModelWithTokens.ts
+2
-1
src/vs/editor/common/model/textSource.ts
src/vs/editor/common/model/textSource.ts
+69
-2
src/vs/editor/common/services/modelService.ts
src/vs/editor/common/services/modelService.ts
+3
-3
src/vs/editor/common/services/modelServiceImpl.ts
src/vs/editor/common/services/modelServiceImpl.ts
+4
-4
src/vs/editor/node/model/modelBuilder.ts
src/vs/editor/node/model/modelBuilder.ts
+3
-3
src/vs/editor/test/node/model/modelBuilder.test.ts
src/vs/editor/test/node/model/modelBuilder.test.ts
+3
-3
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-1
src/vs/workbench/api/node/extHostDocuments.ts
src/vs/workbench/api/node/extHostDocuments.ts
+2
-1
src/vs/workbench/api/node/mainThreadDocuments.ts
src/vs/workbench/api/node/mainThreadDocuments.ts
+3
-2
src/vs/workbench/common/editor/textEditorModel.ts
src/vs/workbench/common/editor/textEditorModel.ts
+5
-5
src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts
...ts/welcome/walkThrough/node/walkThroughContentProvider.ts
+2
-2
src/vs/workbench/services/backup/common/backup.ts
src/vs/workbench/services/backup/common/backup.ts
+2
-2
src/vs/workbench/services/backup/node/backupFileService.ts
src/vs/workbench/services/backup/node/backupFileService.ts
+2
-2
src/vs/workbench/services/backup/test/backupFileService.test.ts
.../workbench/services/backup/test/backupFileService.test.ts
+2
-2
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
...workbench/services/textfile/common/textFileEditorModel.ts
+3
-3
src/vs/workbench/services/textfile/common/textfiles.ts
src/vs/workbench/services/textfile/common/textfiles.ts
+2
-2
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+3
-4
未找到文件。
src/vs/editor/common/editorCommon.ts
浏览文件 @
668dc067
...
...
@@ -21,6 +21,7 @@ import { IndentRange } from 'vs/editor/common/model/indentRanges';
import
{
ICommandHandlerDescription
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ContextKeyExpr
,
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
FontInfo
}
from
'
vs/editor/common/config/fontInfo
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
/**
* @internal
...
...
@@ -2457,37 +2458,6 @@ export interface IModelContentChangedEvent {
readonly
isRedoing
:
boolean
;
}
/**
* The raw text backing a model.
* @internal
*/
export
interface
ITextSource
{
/**
* The entire text length.
*/
readonly
length
:
number
;
/**
* The text split into lines.
*/
readonly
lines
:
string
[];
/**
* The BOM (leading character sequence of the file).
*/
readonly
BOM
:
string
;
/**
* The end of line sequence.
*/
readonly
EOL
:
string
;
/**
* The text contains Unicode characters classified as "R" or "AL".
*/
readonly
containsRTL
:
boolean
;
/**
* The text contains only characters inside the ASCII range 32-126 or \t \r \n
*/
readonly
isBasicASCII
:
boolean
;
}
/**
* The raw text backing a model.
* @internal
...
...
src/vs/editor/common/model/editableTextModel.ts
浏览文件 @
668dc067
...
...
@@ -14,6 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
interface
IValidatedEditOperation
{
sortIndex
:
number
;
...
...
@@ -69,7 +70,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
super
.
dispose
();
}
protected
_resetValue
(
newValue
:
editorCommon
.
ITextSource
):
void
{
protected
_resetValue
(
newValue
:
ITextSource
):
void
{
super
.
_resetValue
(
newValue
);
// Destroy my edit history and settings
...
...
src/vs/editor/common/model/textModel.ts
浏览文件 @
668dc067
...
...
@@ -15,7 +15,7 @@ import { DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/com
import
{
PrefixSumComputer
}
from
'
vs/editor/common/viewModel/prefixSumComputer
'
;
import
{
IndentRange
,
computeRanges
}
from
'
vs/editor/common/model/indentRanges
'
;
import
{
TextModelSearch
,
SearchParams
}
from
'
vs/editor/common/model/textModelSearch
'
;
import
{
ITextSource
2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
ITextSource
,
RawTextSource
,
IRawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
const
LIMIT_FIND_COUNT
=
999
;
export
const
LONG_LINE_BOUNDARY
=
1000
;
...
...
@@ -286,7 +286,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
}
}
protected
_resetValue
(
newValue
:
editorCommon
.
ITextSource
):
void
{
protected
_resetValue
(
newValue
:
ITextSource
):
void
{
this
.
_constructLines
(
newValue
);
this
.
_increaseVersionId
();
}
...
...
@@ -304,7 +304,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
};
}
public
equals
(
other
:
editorCommon
.
ITextSource
):
boolean
{
public
equals
(
other
:
ITextSource
):
boolean
{
this
.
_assertNotDisposed
();
if
(
this
.
_BOM
!==
other
.
BOM
)
{
return
false
;
...
...
@@ -340,7 +340,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
this
.
setValueFromRawText
(
rawText
);
}
public
setValueFromRawText
(
newValue
:
editorCommon
.
ITextSource
):
void
{
public
setValueFromRawText
(
newValue
:
ITextSource
):
void
{
this
.
_assertNotDisposed
();
if
(
newValue
===
null
)
{
// There's nothing to do
...
...
@@ -750,43 +750,12 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
}
}
public
static
toTextSource
(
rawText
:
string
):
ITextSource2
{
// Count the number of lines that end with \r\n
let
carriageReturnCnt
=
0
;
let
lastCarriageReturnIndex
=
-
1
;
while
((
lastCarriageReturnIndex
=
rawText
.
indexOf
(
'
\r
'
,
lastCarriageReturnIndex
+
1
))
!==
-
1
)
{
carriageReturnCnt
++
;
}
const
containsRTL
=
strings
.
containsRTL
(
rawText
);
const
isBasicASCII
=
(
containsRTL
?
false
:
strings
.
isBasicASCII
(
rawText
));
// Split the text into lines
const
lines
=
rawText
.
split
(
/
\r\n
|
\r
|
\n
/
);
// Remove the BOM (if present)
let
BOM
=
''
;
if
(
strings
.
startsWithUTF8BOM
(
lines
[
0
]))
{
BOM
=
strings
.
UTF8_BOM_CHARACTER
;
lines
[
0
]
=
lines
[
0
].
substr
(
1
);
}
return
{
BOM
:
BOM
,
lines
:
lines
,
length
:
rawText
.
length
,
containsRTL
:
containsRTL
,
isBasicASCII
:
isBasicASCII
,
totalCRCount
:
carriageReturnCnt
};
}
/**
* if text source is empty or with precisely one line, returns null. No end of line is detected.
* if text source contains more lines ending with '\r\n', returns '\r\n'.
* Otherwise returns '\n'. More lines end with '\n'.
*/
public
static
getEndOfLine
(
textSource
:
I
TextSource2
):
string
{
public
static
getEndOfLine
(
textSource
:
I
RawTextSource
):
string
{
const
lineFeedCnt
=
textSource
.
lines
.
length
-
1
;
if
(
lineFeedCnt
===
0
)
{
// This is an empty file or a file with precisely one line
...
...
@@ -801,11 +770,11 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
}
public
static
toRawText
(
rawText
:
string
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
const
textSource
=
TextModel
.
toTextSource
(
rawText
);
const
textSource
=
RawTextSource
.
fromString
(
rawText
);
return
TextModel
.
toRawTextFromTextSource
(
textSource
,
opts
);
}
public
static
toRawTextFromTextSource
(
textSource
:
I
TextSource2
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
public
static
toRawTextFromTextSource
(
textSource
:
I
RawTextSource
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
let
EOL
=
TextModel
.
getEndOfLine
(
textSource
);
if
(
!
EOL
)
{
// This is an empty file or a file with precisely one line
...
...
@@ -841,7 +810,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
};
}
private
_constructLines
(
rawText
:
editorCommon
.
ITextSource
):
void
{
private
_constructLines
(
rawText
:
ITextSource
):
void
{
const
tabSize
=
this
.
_options
.
tabSize
;
let
rawLines
=
rawText
.
lines
;
let
modelLines
:
ModelLine
[]
=
[];
...
...
@@ -898,7 +867,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
export
class
RawText
{
public
static
toRawText
(
textSourceOrString
:
I
TextSource2
|
string
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
public
static
toRawText
(
textSourceOrString
:
I
RawTextSource
|
string
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
if
(
typeof
textSourceOrString
===
'
string
'
)
{
return
RawText
.
fromString
(
textSourceOrString
,
opts
);
}
else
{
...
...
@@ -906,7 +875,7 @@ export class RawText {
}
}
public
static
toRawTextWithModelOptions
(
textSourceOrString
:
I
TextSource2
|
string
,
model
:
editorCommon
.
IModel
):
editorCommon
.
IRawText
{
public
static
toRawTextWithModelOptions
(
textSourceOrString
:
I
RawTextSource
|
string
,
model
:
editorCommon
.
IModel
):
editorCommon
.
IRawText
{
if
(
typeof
textSourceOrString
===
'
string
'
)
{
return
RawText
.
fromStringWithModelOptions
(
textSourceOrString
,
model
);
}
else
{
...
...
@@ -918,7 +887,7 @@ export class RawText {
return
TextModel
.
toRawText
(
rawText
,
opts
);
}
public
static
fromTextSource
(
textSource
:
I
TextSource2
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
public
static
fromTextSource
(
textSource
:
I
RawTextSource
,
opts
:
editorCommon
.
ITextModelCreationOptions
):
editorCommon
.
IRawText
{
return
TextModel
.
toRawTextFromTextSource
(
textSource
,
opts
);
}
...
...
@@ -933,7 +902,7 @@ export class RawText {
});
}
public
static
fromTextSourceWithModelOptions
(
textSource
:
I
TextSource2
,
model
:
editorCommon
.
IModel
):
editorCommon
.
IRawText
{
public
static
fromTextSourceWithModelOptions
(
textSource
:
I
RawTextSource
,
model
:
editorCommon
.
IModel
):
editorCommon
.
IRawText
{
let
opts
=
model
.
getOptions
();
return
TextModel
.
toRawTextFromTextSource
(
textSource
,
{
tabSize
:
opts
.
tabSize
,
...
...
src/vs/editor/common/model/textModelWithDecorations.ts
浏览文件 @
668dc067
...
...
@@ -14,6 +14,7 @@ import { MarkersTracker, LineMarker } from 'vs/editor/common/model/modelLine';
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
INewMarker
,
TextModelWithMarkers
}
from
'
vs/editor/common/model/textModelWithMarkers
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
class
DecorationsTracker
{
...
...
@@ -165,7 +166,7 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
super
.
dispose
();
}
protected
_resetValue
(
newValue
:
editorCommon
.
ITextSource
):
void
{
protected
_resetValue
(
newValue
:
ITextSource
):
void
{
super
.
_resetValue
(
newValue
);
// Destroy all my decorations
...
...
src/vs/editor/common/model/textModelWithMarkers.ts
浏览文件 @
668dc067
...
...
@@ -6,10 +6,11 @@
import
{
IdGenerator
}
from
'
vs/base/common/idGenerator
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
I
TextSource
,
I
RawText
,
ITextModelWithMarkers
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IRawText
,
ITextModelWithMarkers
}
from
'
vs/editor/common/editorCommon
'
;
import
{
LineMarker
}
from
'
vs/editor/common/model/modelLine
'
;
import
{
TextModelWithTokens
}
from
'
vs/editor/common/model/textModelWithTokens
'
;
import
{
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
interface
IMarkerIdToMarkerMap
{
[
key
:
string
]:
LineMarker
;
...
...
src/vs/editor/common/model/textModelWithTokens.ts
浏览文件 @
668dc067
...
...
@@ -21,6 +21,7 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
import
{
LineTokens
,
LineToken
}
from
'
vs/editor/common/core/lineTokens
'
;
import
{
getWordAtText
}
from
'
vs/editor/common/model/wordHelper
'
;
import
{
TokenizationResult2
}
from
'
vs/editor/common/core/token
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
class
ModelTokensChangedEventBuilder
{
...
...
@@ -107,7 +108,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
return
false
;
}
protected
_resetValue
(
newValue
:
editorCommon
.
ITextSource
):
void
{
protected
_resetValue
(
newValue
:
ITextSource
):
void
{
super
.
_resetValue
(
newValue
);
// Cancel tokenization, clear all tokens and begin tokenizing
this
.
_resetTokenizationState
();
...
...
src/vs/editor/common/model/textSource.ts
浏览文件 @
668dc067
...
...
@@ -4,10 +4,12 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
/**
*
The text source
*
A processed string ready to be turned into an editor model.
*/
export
interface
I
TextSource2
{
export
interface
I
RawTextSource
{
/**
* The entire text length.
*/
...
...
@@ -33,3 +35,68 @@ export interface ITextSource2 {
*/
readonly
isBasicASCII
:
boolean
;
}
export
class
RawTextSource
{
public
static
fromString
(
rawText
:
string
):
IRawTextSource
{
// Count the number of lines that end with \r\n
let
carriageReturnCnt
=
0
;
let
lastCarriageReturnIndex
=
-
1
;
while
((
lastCarriageReturnIndex
=
rawText
.
indexOf
(
'
\r
'
,
lastCarriageReturnIndex
+
1
))
!==
-
1
)
{
carriageReturnCnt
++
;
}
const
containsRTL
=
strings
.
containsRTL
(
rawText
);
const
isBasicASCII
=
(
containsRTL
?
false
:
strings
.
isBasicASCII
(
rawText
));
// Split the text into lines
const
lines
=
rawText
.
split
(
/
\r\n
|
\r
|
\n
/
);
// Remove the BOM (if present)
let
BOM
=
''
;
if
(
strings
.
startsWithUTF8BOM
(
lines
[
0
]))
{
BOM
=
strings
.
UTF8_BOM_CHARACTER
;
lines
[
0
]
=
lines
[
0
].
substr
(
1
);
}
return
{
BOM
:
BOM
,
lines
:
lines
,
length
:
rawText
.
length
,
containsRTL
:
containsRTL
,
isBasicASCII
:
isBasicASCII
,
totalCRCount
:
carriageReturnCnt
};
}
}
/**
* A processed string with its EOL resolved ready to be turned into an editor model.
*/
export
interface
ITextSource
{
/**
* The entire text length.
*/
readonly
length
:
number
;
/**
* The text split into lines.
*/
readonly
lines
:
string
[];
/**
* The BOM (leading character sequence of the file).
*/
readonly
BOM
:
string
;
/**
* The end of line sequence.
*/
readonly
EOL
:
string
;
/**
* The text contains Unicode characters classified as "R" or "AL".
*/
readonly
containsRTL
:
boolean
;
/**
* The text contains only characters inside the ASCII range 32-126 or \t \r \n
*/
readonly
isBasicASCII
:
boolean
;
}
src/vs/editor/common/services/modelService.ts
浏览文件 @
668dc067
...
...
@@ -10,16 +10,16 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IModel
,
ITextModelCreationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IMode
}
from
'
vs/editor/common/modes
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
var
IModelService
=
createDecorator
<
IModelService
>
(
'
modelService
'
);
export
interface
IModelService
{
_serviceBrand
:
any
;
createModel
(
value
:
string
|
I
TextSource2
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
IModel
;
createModel
(
value
:
string
|
I
RawTextSource
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
IModel
;
updateModel
(
model
:
IModel
,
value
:
string
|
I
TextSource2
):
void
;
updateModel
(
model
:
IModel
,
value
:
string
|
I
RawTextSource
):
void
;
setMode
(
model
:
IModel
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
):
void
;
...
...
src/vs/editor/common/services/modelServiceImpl.ts
浏览文件 @
668dc067
...
...
@@ -24,7 +24,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import
{
DEFAULT_INDENTATION
,
DEFAULT_TRIM_AUTO_WHITESPACE
}
from
'
vs/editor/common/config/defaultConfig
'
;
import
{
PLAINTEXT_LANGUAGE_IDENTIFIER
}
from
'
vs/editor/common/modes/modesRegistry
'
;
import
{
RawText
}
from
'
vs/editor/common/model/textModel
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
function
MODEL_ID
(
resource
:
URI
):
string
{
return
resource
.
toString
();
...
...
@@ -339,7 +339,7 @@ export class ModelServiceImpl implements IModelService {
// --- begin IModelService
private
_createModelData
(
value
:
string
|
I
TextSource2
,
languageIdentifier
:
LanguageIdentifier
,
resource
:
URI
):
ModelData
{
private
_createModelData
(
value
:
string
|
I
RawTextSource
,
languageIdentifier
:
LanguageIdentifier
,
resource
:
URI
):
ModelData
{
// create & save the model
const
options
=
this
.
getCreationOptions
(
languageIdentifier
.
language
);
...
...
@@ -358,7 +358,7 @@ export class ModelServiceImpl implements IModelService {
return
modelData
;
}
public
updateModel
(
model
:
editorCommon
.
IModel
,
value
:
string
|
I
TextSource2
):
void
{
public
updateModel
(
model
:
editorCommon
.
IModel
,
value
:
string
|
I
RawTextSource
):
void
{
let
options
=
this
.
getCreationOptions
(
model
.
getLanguageIdentifier
().
language
);
let
rawText
:
editorCommon
.
IRawText
=
RawText
.
toRawText
(
value
,
options
);
...
...
@@ -371,7 +371,7 @@ export class ModelServiceImpl implements IModelService {
model
.
setValueFromRawText
(
rawText
);
}
public
createModel
(
value
:
string
|
I
TextSource2
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
editorCommon
.
IModel
{
public
createModel
(
value
:
string
|
I
RawTextSource
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
editorCommon
.
IModel
{
let
modelData
:
ModelData
;
if
(
!
modeOrPromise
||
TPromise
.
is
(
modeOrPromise
))
{
...
...
src/vs/editor/node/model/modelBuilder.ts
浏览文件 @
668dc067
...
...
@@ -9,11 +9,11 @@ import * as crypto from 'crypto';
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
interface
ModelBuilderResult
{
readonly
hash
:
string
;
readonly
value
:
I
TextSource2
;
readonly
value
:
I
RawTextSource
;
}
class
ModelLineBasedBuilder
{
...
...
@@ -60,7 +60,7 @@ class ModelLineBasedBuilder {
}
}
export
function
computeHash
(
rawText
:
I
TextSource2
):
string
{
export
function
computeHash
(
rawText
:
I
RawTextSource
):
string
{
let
hash
=
crypto
.
createHash
(
'
sha1
'
);
for
(
let
i
=
0
,
len
=
rawText
.
lines
.
length
;
i
<
len
;
i
++
)
{
hash
.
update
(
rawText
.
lines
[
i
]
+
'
\n
'
);
...
...
src/vs/editor/test/node/model/modelBuilder.test.ts
浏览文件 @
668dc067
...
...
@@ -9,10 +9,10 @@ import { ModelBuilder, computeHash } from 'vs/editor/node/model/modelBuilder';
import
{
ITextModelCreationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
ITextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
RawTextSource
,
IRawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
function
testModelBuilder
(
chunks
:
string
[],
opts
:
ITextModelCreationOptions
=
TextModel
.
DEFAULT_CREATION_OPTIONS
):
string
{
let
expectedTextSource
=
TextModel
.
toTextSource
(
chunks
.
join
(
''
));
let
expectedTextSource
=
RawTextSource
.
fromString
(
chunks
.
join
(
''
));
let
expectedHash
=
computeHash
(
expectedTextSource
);
let
builder
=
new
ModelBuilder
();
...
...
@@ -30,7 +30,7 @@ export function testModelBuilder(chunks: string[], opts: ITextModelCreationOptio
return
expectedHash
;
}
function
toTextSource
(
lines
:
string
[]):
I
TextSource2
{
function
toTextSource
(
lines
:
string
[]):
I
RawTextSource
{
return
{
BOM
:
''
,
lines
:
lines
,
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
668dc067
...
...
@@ -27,6 +27,7 @@ import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
import
{
ConfigurationTarget
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
import
{
IWorkspaceConfigurationValues
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
...
...
@@ -122,7 +123,7 @@ export abstract class MainThreadDocumentsShape {
$tryCreateDocument
(
options
?:
{
language
:
string
;
}):
TPromise
<
any
>
{
throw
ni
();
}
$tryOpenDocument
(
uri
:
URI
):
TPromise
<
any
>
{
throw
ni
();
}
$registerTextContentProvider
(
handle
:
number
,
scheme
:
string
):
void
{
throw
ni
();
}
$onVirtualDocumentChange
(
uri
:
URI
,
value
:
editorCommon
.
ITextSource
):
void
{
throw
ni
();
}
$onVirtualDocumentChange
(
uri
:
URI
,
value
:
ITextSource
):
void
{
throw
ni
();
}
$unregisterTextContentProvider
(
handle
:
number
):
void
{
throw
ni
();
}
$trySaveDocument
(
uri
:
URI
):
TPromise
<
boolean
>
{
throw
ni
();
}
}
...
...
src/vs/workbench/api/node/extHostDocuments.ts
浏览文件 @
668dc067
...
...
@@ -20,6 +20,7 @@ import * as vscode from 'vscode';
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
getWordAtText
,
ensureValidWordDefinition
}
from
'
vs/editor/common/model/wordHelper
'
;
import
{
MainContext
,
MainThreadDocumentsShape
,
ExtHostDocumentsShape
,
IModelAddedData
}
from
'
./extHost.protocol
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
const
_modeId2WordDefinition
=
new
Map
<
string
,
RegExp
>
();
...
...
@@ -263,7 +264,7 @@ export class ExtHostDocumentData extends MirrorModel2 {
super
.
dispose
();
}
equalLines
({
lines
}:
editorCommon
.
ITextSource
):
boolean
{
equalLines
({
lines
}:
ITextSource
):
boolean
{
const
len
=
lines
.
length
;
if
(
len
!==
this
.
_lines
.
length
)
{
return
false
;
...
...
src/vs/workbench/api/node/mainThreadDocuments.ts
浏览文件 @
668dc067
...
...
@@ -19,6 +19,7 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
import
{
ExtHostContext
,
MainThreadDocumentsShape
,
ExtHostDocumentsShape
}
from
'
./extHost.protocol
'
;
import
{
ITextModelResolverService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
class
MainThreadDocuments
extends
MainThreadDocumentsShape
{
private
_modelService
:
IModelService
;
...
...
@@ -241,12 +242,12 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
}
}
$onVirtualDocumentChange
(
uri
:
URI
,
value
:
editorCommon
.
ITextSource
):
void
{
$onVirtualDocumentChange
(
uri
:
URI
,
value
:
ITextSource
):
void
{
const
model
=
this
.
_modelService
.
getModel
(
uri
);
if
(
!
model
)
{
return
;
}
const
raw
:
editorCommon
.
ITextSource
=
{
const
raw
:
ITextSource
=
{
lines
:
value
.
lines
,
length
:
value
.
length
,
BOM
:
value
.
BOM
,
...
...
src/vs/workbench/common/editor/textEditorModel.ts
浏览文件 @
668dc067
...
...
@@ -13,7 +13,7 @@ import { ITextEditorModel } from 'vs/editor/common/services/resolverService';
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
/**
* The base text editor model leverages the code editor model. This class is only intended to be subclassed and not instantiated.
...
...
@@ -67,7 +67,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
/**
* Creates the text editor model with the provided value, modeId (can be comma separated for multiple values) and optional resource URL.
*/
protected
createTextEditorModel
(
value
:
string
|
I
TextSource2
,
resource
?:
URI
,
modeId
?:
string
):
TPromise
<
EditorModel
>
{
protected
createTextEditorModel
(
value
:
string
|
I
RawTextSource
,
resource
?:
URI
,
modeId
?:
string
):
TPromise
<
EditorModel
>
{
const
firstLineText
=
this
.
getFirstLineText
(
value
);
const
mode
=
this
.
getOrCreateMode
(
this
.
modeService
,
modeId
,
firstLineText
);
...
...
@@ -77,7 +77,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
});
}
private
doCreateTextEditorModel
(
value
:
string
|
I
TextSource2
,
mode
:
TPromise
<
IMode
>
,
resource
:
URI
):
EditorModel
{
private
doCreateTextEditorModel
(
value
:
string
|
I
RawTextSource
,
mode
:
TPromise
<
IMode
>
,
resource
:
URI
):
EditorModel
{
let
model
=
resource
&&
this
.
modelService
.
getModel
(
resource
);
if
(
!
model
)
{
model
=
this
.
modelService
.
createModel
(
value
,
mode
,
resource
);
...
...
@@ -95,7 +95,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
return
this
;
}
protected
getFirstLineText
(
value
:
string
|
I
TextSource2
):
string
{
protected
getFirstLineText
(
value
:
string
|
I
RawTextSource
):
string
{
if
(
typeof
value
===
'
string
'
)
{
const
firstLineText
=
value
.
substr
(
0
,
100
);
...
...
@@ -127,7 +127,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
/**
* Updates the text editor model with the provided value. If the value is the same as the model has, this is a no-op.
*/
protected
updateTextEditorModel
(
newValue
:
string
|
I
TextSource2
):
void
{
protected
updateTextEditorModel
(
newValue
:
string
|
I
RawTextSource
):
void
{
if
(
!
this
.
textEditorModel
)
{
return
;
}
...
...
src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts
浏览文件 @
668dc067
...
...
@@ -15,7 +15,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import
{
IWorkbenchContribution
}
from
'
vs/workbench/common/contributions
'
;
import
{
marked
}
from
'
vs/base/common/marked/marked
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
class
WalkThroughContentProvider
implements
ITextModelContentProvider
,
IWorkbenchContribution
{
...
...
@@ -30,7 +30,7 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW
public
provideTextContent
(
resource
:
URI
):
TPromise
<
IModel
>
{
const
query
=
resource
.
query
?
JSON
.
parse
(
resource
.
query
)
:
{};
const
content
:
TPromise
<
string
|
I
TextSource2
>
=
(
query
.
moduleId
?
new
TPromise
<
string
>
((
resolve
,
reject
)
=>
{
const
content
:
TPromise
<
string
|
I
RawTextSource
>
=
(
query
.
moduleId
?
new
TPromise
<
string
>
((
resolve
,
reject
)
=>
{
require
([
query
.
moduleId
],
content
=>
{
try
{
resolve
(
content
.
default
());
...
...
src/vs/workbench/services/backup/common/backup.ts
浏览文件 @
668dc067
...
...
@@ -9,7 +9,7 @@ import Uri from 'vs/base/common/uri';
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IResolveContentOptions
,
IUpdateContentOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
const
IBackupFileService
=
createDecorator
<
IBackupFileService
>
(
'
backupFileService
'
);
...
...
@@ -58,7 +58,7 @@ export interface IBackupFileService {
* @param rawText The IRawTextProvider from a backup resource.
* @return The backup file's backed up content.
*/
parseBackupContent
(
textSource
:
I
TextSource2
):
string
;
parseBackupContent
(
textSource
:
I
RawTextSource
):
string
;
/**
* Discards the backup associated with a resource if it exists..
...
...
src/vs/workbench/services/backup/node/backupFileService.ts
浏览文件 @
668dc067
...
...
@@ -19,7 +19,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
readToMatchingString
}
from
'
vs/base/node/stream
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
interface
IBackupFilesModel
{
resolve
(
backupRoot
:
string
):
TPromise
<
IBackupFilesModel
>
;
...
...
@@ -239,7 +239,7 @@ export class BackupFileService implements IBackupFileService {
});
}
public
parseBackupContent
(
textSource
:
I
TextSource2
):
string
{
public
parseBackupContent
(
textSource
:
I
RawTextSource
):
string
{
return
textSource
.
lines
.
slice
(
1
).
join
(
TextModel
.
getEndOfLine
(
textSource
)
||
''
);
// The first line of a backup text file is the file name
}
...
...
src/vs/workbench/services/backup/test/backupFileService.test.ts
浏览文件 @
668dc067
...
...
@@ -19,9 +19,9 @@ import { FileService } from 'vs/workbench/services/files/node/fileService';
import
{
EnvironmentService
}
from
'
vs/platform/environment/node/environmentService
'
;
import
{
IBackupService
}
from
'
vs/platform/backup/common/backup
'
;
import
{
parseArgs
}
from
'
vs/platform/environment/node/argv
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TestWindowService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
class
TestEnvironmentService
extends
EnvironmentService
{
...
...
@@ -252,7 +252,7 @@ suite('BackupFileService', () => {
test
(
'
parseBackupContent
'
,
()
=>
{
test
(
'
should separate metadata from content
'
,
()
=>
{
const
textSource
=
TextModel
.
toTextSource
(
'
metadata
\n
content
'
);
const
textSource
=
RawTextSource
.
fromString
(
'
metadata
\n
content
'
);
assert
.
equal
(
service
.
parseBackupContent
(
textSource
),
'
content
'
);
});
});
...
...
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
浏览文件 @
668dc067
...
...
@@ -31,7 +31,7 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
anonymize
}
from
'
vs/platform/telemetry/common/telemetryUtils
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
/**
* The text file editor model listens to changes to its underlying code editor model and saves these changes through the file service back to the disk.
...
...
@@ -356,7 +356,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return
this
.
doCreateTextModel
(
content
.
resource
,
content
.
value
,
backup
);
}
private
doUpdateTextModel
(
value
:
string
|
I
TextSource2
):
TPromise
<
EditorModel
>
{
private
doUpdateTextModel
(
value
:
string
|
I
RawTextSource
):
TPromise
<
EditorModel
>
{
diag
(
'
load() - updated text editor model
'
,
this
.
resource
,
new
Date
());
this
.
setDirty
(
false
);
// Ensure we are not tracking a stale state
...
...
@@ -371,7 +371,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return
TPromise
.
as
<
EditorModel
>
(
this
);
}
private
doCreateTextModel
(
resource
:
URI
,
value
:
string
|
I
TextSource2
,
backup
:
URI
):
TPromise
<
EditorModel
>
{
private
doCreateTextModel
(
resource
:
URI
,
value
:
string
|
I
RawTextSource
,
backup
:
URI
):
TPromise
<
EditorModel
>
{
diag
(
'
load() - created text editor model
'
,
this
.
resource
,
new
Date
());
this
.
createTextEditorModelPromise
=
this
.
doLoadBackup
(
backup
).
then
(
backupContent
=>
{
...
...
src/vs/workbench/services/textfile/common/textfiles.ts
浏览文件 @
668dc067
...
...
@@ -12,7 +12,7 @@ import { IEncodingSupport, ConfirmResult } from 'vs/workbench/common/editor';
import
{
IBaseStat
,
IResolveContentOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ITextEditorModel
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
I
TextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
I
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
/**
* The save error handler can be installed on the text text file editor model to install code that executes when save errors occur.
...
...
@@ -112,7 +112,7 @@ export interface IRawTextContent extends IBaseStat {
/**
* The line grouped content of a text file.
*/
value
:
I
TextSource2
;
value
:
I
RawTextSource
;
/**
* The line grouped logical hash of a text file.
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
668dc067
...
...
@@ -39,7 +39,6 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import
{
ModeServiceImpl
}
from
'
vs/editor/common/services/modeServiceImpl
'
;
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
import
{
IRawTextContent
,
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
parseArgs
}
from
'
vs/platform/environment/node/argv
'
;
import
{
EnvironmentService
}
from
'
vs/platform/environment/node/environmentService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
...
...
@@ -49,7 +48,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import
{
TestConfigurationService
}
from
'
vs/platform/configuration/test/common/testConfigurationService
'
;
import
{
IWindowsService
,
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
TestWorkspace
}
from
'
vs/platform/workspace/test/common/testWorkspace
'
;
import
{
ITextSource2
}
from
'
vs/editor/common/model/textSource
'
;
import
{
RawTextSource
,
IRawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
export
function
createFileInput
(
instantiationService
:
IInstantiationService
,
resource
:
URI
):
FileEditorInput
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
void
0
);
...
...
@@ -150,7 +149,7 @@ export class TestTextFileService extends TextFileService {
}
return
this
.
fileService
.
resolveContent
(
resource
,
options
).
then
((
content
)
=>
{
const
textSource
=
TextModel
.
toTextSource
(
content
.
value
);
const
textSource
=
RawTextSource
.
fromString
(
content
.
value
);
return
<
IRawTextContent
>
{
resource
:
content
.
resource
,
name
:
content
.
name
,
...
...
@@ -733,7 +732,7 @@ export class TestBackupFileService implements IBackupFileService {
return
TPromise
.
as
([]);
}
public
parseBackupContent
(
rawText
:
I
TextSource2
):
string
{
public
parseBackupContent
(
rawText
:
I
RawTextSource
):
string
{
return
rawText
.
lines
.
join
(
'
\n
'
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录