Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4644b60d
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,发现更多精彩内容 >>
提交
4644b60d
编写于
1月 24, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove internal API for accessing the value of a model directly
上级
fb1d2193
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
56 addition
and
63 deletion
+56
-63
src/vs/workbench/common/editor/textEditorModel.ts
src/vs/workbench/common/editor/textEditorModel.ts
+17
-22
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
+3
-13
src/vs/workbench/services/backup/test/node/backupFileService.test.ts
...bench/services/backup/test/node/backupFileService.test.ts
+15
-15
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
...workbench/services/textfile/common/textFileEditorModel.ts
+8
-7
src/vs/workbench/test/common/editor/editorModel.test.ts
src/vs/workbench/test/common/editor/editorModel.test.ts
+10
-3
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+1
-1
未找到文件。
src/vs/workbench/common/editor/textEditorModel.ts
浏览文件 @
4644b60d
...
...
@@ -67,13 +67,13 @@ 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
|
ITextBufferFactory
,
resource
?:
URI
,
modeId
?:
string
):
TPromise
<
EditorModel
>
{
protected
createTextEditorModel
(
value
:
ITextBufferFactory
,
resource
?:
URI
,
modeId
?:
string
):
TPromise
<
EditorModel
>
{
const
firstLineText
=
this
.
getFirstLineText
(
value
);
const
mode
=
this
.
getOrCreateMode
(
this
.
modeService
,
modeId
,
firstLineText
);
return
TPromise
.
as
(
this
.
doCreateTextEditorModel
(
value
,
mode
,
resource
));
}
private
doCreateTextEditorModel
(
value
:
string
|
ITextBufferFactory
,
mode
:
TPromise
<
IMode
>
,
resource
:
URI
):
EditorModel
{
private
doCreateTextEditorModel
(
value
:
ITextBufferFactory
,
mode
:
TPromise
<
IMode
>
,
resource
:
URI
):
EditorModel
{
let
model
=
resource
&&
this
.
modelService
.
getModel
(
resource
);
if
(
!
model
)
{
model
=
this
.
modelService
.
createModel
(
value
,
mode
,
resource
);
...
...
@@ -91,24 +91,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
return
this
;
}
protected
getFirstLineText
(
value
:
string
|
ITextBufferFactory
|
ITextSnapshot
):
string
{
// string
if
(
typeof
value
===
'
string
'
)
{
const
firstLineText
=
value
.
substr
(
0
,
100
);
let
crIndex
=
firstLineText
.
indexOf
(
'
\r
'
);
if
(
crIndex
<
0
)
{
crIndex
=
firstLineText
.
length
;
}
let
lfIndex
=
firstLineText
.
indexOf
(
'
\n
'
);
if
(
lfIndex
<
0
)
{
lfIndex
=
firstLineText
.
length
;
}
return
firstLineText
.
substr
(
0
,
Math
.
min
(
crIndex
,
lfIndex
));
}
protected
getFirstLineText
(
value
:
ITextBufferFactory
|
ITextSnapshot
):
string
{
// text buffer factory
const
textBufferFactory
=
value
as
ITextBufferFactory
;
...
...
@@ -118,7 +101,19 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
// text snapshot
const
textSnapshot
=
value
as
ITextSnapshot
;
return
this
.
getFirstLineText
(
textSnapshot
.
read
()
||
''
);
const
firstLineText
=
textSnapshot
.
read
().
substr
(
0
,
100
);
let
crIndex
=
firstLineText
.
indexOf
(
'
\r
'
);
if
(
crIndex
<
0
)
{
crIndex
=
firstLineText
.
length
;
}
let
lfIndex
=
firstLineText
.
indexOf
(
'
\n
'
);
if
(
lfIndex
<
0
)
{
lfIndex
=
firstLineText
.
length
;
}
return
firstLineText
.
substr
(
0
,
Math
.
min
(
crIndex
,
lfIndex
));
}
/**
...
...
@@ -133,7 +128,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
|
ITextBufferFactory
):
void
{
protected
updateTextEditorModel
(
newValue
:
ITextBufferFactory
):
void
{
if
(
!
this
.
textEditorModel
)
{
return
;
}
...
...
src/vs/workbench/services/backup/common/backup.ts
浏览文件 @
4644b60d
...
...
@@ -52,10 +52,10 @@ export interface IBackupFileService {
* Backs up a resource.
*
* @param resource The resource to back up.
* @param content The content of the resource as
value or
snapshot.
* @param content The content of the resource as snapshot.
* @param versionId The version id of the resource to backup.
*/
backupResource
(
resource
:
Uri
,
content
:
string
|
ITextSnapshot
,
versionId
?:
number
):
TPromise
<
void
>
;
backupResource
(
resource
:
Uri
,
content
:
ITextSnapshot
,
versionId
?:
number
):
TPromise
<
void
>
;
/**
* Gets a list of file backups for the current workspace.
...
...
src/vs/workbench/services/backup/node/backupFileService.ts
浏览文件 @
4644b60d
...
...
@@ -11,7 +11,7 @@ import * as pfs from 'vs/base/node/pfs';
import
Uri
from
'
vs/base/common/uri
'
;
import
{
ResourceQueue
}
from
'
vs/base/common/async
'
;
import
{
IBackupFileService
,
BACKUP_FILE_UPDATE_OPTIONS
,
BACKUP_FILE_RESOLVE_OPTIONS
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
IFileService
,
ITextSnapshot
,
IFileStat
}
from
'
vs/platform/files/common/files
'
;
import
{
IFileService
,
ITextSnapshot
}
from
'
vs/platform/files/common/files
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
readToMatchingString
}
from
'
vs/base/node/stream
'
;
import
{
ITextBufferFactory
}
from
'
vs/editor/common/model
'
;
...
...
@@ -171,7 +171,7 @@ export class BackupFileService implements IBackupFileService {
});
}
public
backupResource
(
resource
:
Uri
,
content
:
string
|
ITextSnapshot
,
versionId
?:
number
):
TPromise
<
void
>
{
public
backupResource
(
resource
:
Uri
,
content
:
ITextSnapshot
,
versionId
?:
number
):
TPromise
<
void
>
{
if
(
this
.
isShuttingDown
)
{
return
TPromise
.
as
(
void
0
);
}
...
...
@@ -190,17 +190,7 @@ export class BackupFileService implements IBackupFileService {
const
preamble
=
`
${
resource
.
toString
()}${
BackupFileService
.
META_MARKER
}
`
;
// Update content with value
let
updateContentPromise
:
TPromise
<
IFileStat
>
;
if
(
typeof
content
===
'
string
'
)
{
updateContentPromise
=
this
.
fileService
.
updateContent
(
backupResource
,
`
${
preamble
}${
content
}
`
,
BACKUP_FILE_UPDATE_OPTIONS
);
}
// Update content with snapshot
else
{
updateContentPromise
=
this
.
fileService
.
updateContent
(
backupResource
,
new
BackupSnapshot
(
content
,
preamble
),
BACKUP_FILE_UPDATE_OPTIONS
);
}
return
updateContentPromise
.
then
(()
=>
model
.
add
(
backupResource
,
versionId
));
return
this
.
fileService
.
updateContent
(
backupResource
,
new
BackupSnapshot
(
content
,
preamble
),
BACKUP_FILE_UPDATE_OPTIONS
).
then
(()
=>
model
.
add
(
backupResource
,
versionId
));
});
});
}
...
...
src/vs/workbench/services/backup/test/node/backupFileService.test.ts
浏览文件 @
4644b60d
...
...
@@ -16,7 +16,7 @@ import pfs = require('vs/base/node/pfs');
import
Uri
from
'
vs/base/common/uri
'
;
import
{
BackupFileService
,
BackupFilesModel
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
FileService
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModel
,
createTextBufferFactory
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TestContextService
,
TestTextResourceConfigurationService
,
getRandomTestPath
,
TestLifecycleService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
Workspace
,
toWorkspaceFolders
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
TestConfigurationService
}
from
'
vs/platform/configuration/test/common/testConfigurationService
'
;
...
...
@@ -107,7 +107,7 @@ suite('BackupFileService', () => {
suite
(
'
backupResource
'
,
()
=>
{
test
(
'
text file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
fooFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
1
);
assert
.
equal
(
fs
.
existsSync
(
fooBackupPath
),
true
);
assert
.
equal
(
fs
.
readFileSync
(
fooBackupPath
),
`
${
fooFile
.
toString
()}
\ntest`
);
...
...
@@ -116,7 +116,7 @@ suite('BackupFileService', () => {
});
test
(
'
untitled file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
untitledFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
untitled
'
)).
length
,
1
);
assert
.
equal
(
fs
.
existsSync
(
untitledBackupPath
),
true
);
assert
.
equal
(
fs
.
readFileSync
(
untitledBackupPath
),
`
${
untitledFile
.
toString
()}
\ntest`
);
...
...
@@ -177,7 +177,7 @@ suite('BackupFileService', () => {
suite
(
'
discardResourceBackup
'
,
()
=>
{
test
(
'
text file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
fooFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
1
);
service
.
discardResourceBackup
(
fooFile
).
then
(()
=>
{
assert
.
equal
(
fs
.
existsSync
(
fooBackupPath
),
false
);
...
...
@@ -188,7 +188,7 @@ suite('BackupFileService', () => {
});
test
(
'
untitled file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
untitledFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
untitled
'
)).
length
,
1
);
service
.
discardResourceBackup
(
untitledFile
).
then
(()
=>
{
assert
.
equal
(
fs
.
existsSync
(
untitledBackupPath
),
false
);
...
...
@@ -201,9 +201,9 @@ suite('BackupFileService', () => {
suite
(
'
discardAllWorkspaceBackups
'
,
()
=>
{
test
(
'
text file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
fooFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
1
);
service
.
backupResource
(
barFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
barFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
2
);
service
.
discardAllWorkspaceBackups
().
then
(()
=>
{
assert
.
equal
(
fs
.
existsSync
(
fooBackupPath
),
false
);
...
...
@@ -216,7 +216,7 @@ suite('BackupFileService', () => {
});
test
(
'
untitled file
'
,
function
(
done
:
()
=>
void
)
{
service
.
backupResource
(
untitledFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
untitled
'
)).
length
,
1
);
service
.
discardAllWorkspaceBackups
().
then
(()
=>
{
assert
.
equal
(
fs
.
existsSync
(
untitledBackupPath
),
false
);
...
...
@@ -228,7 +228,7 @@ suite('BackupFileService', () => {
test
(
'
should disable further backups
'
,
function
(
done
:
()
=>
void
)
{
service
.
discardAllWorkspaceBackups
().
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
'
test
'
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
assert
.
equal
(
fs
.
existsSync
(
workspaceBackupPath
),
false
);
done
();
});
...
...
@@ -238,10 +238,10 @@ suite('BackupFileService', () => {
suite
(
'
getWorkspaceFileBackups
'
,
()
=>
{
test
(
'
("file") - text file
'
,
done
=>
{
service
.
backupResource
(
fooFile
,
`test`
).
then
(()
=>
{
service
.
backupResource
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
getWorkspaceFileBackups
().
then
(
textFiles
=>
{
assert
.
deepEqual
(
textFiles
.
map
(
f
=>
f
.
fsPath
),
[
fooFile
.
fsPath
]);
service
.
backupResource
(
barFile
,
`test`
).
then
(()
=>
{
service
.
backupResource
(
barFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
getWorkspaceFileBackups
().
then
(
textFiles
=>
{
assert
.
deepEqual
(
textFiles
.
map
(
f
=>
f
.
fsPath
),
[
fooFile
.
fsPath
,
barFile
.
fsPath
]);
done
();
...
...
@@ -252,7 +252,7 @@ suite('BackupFileService', () => {
});
test
(
'
("file") - untitled file
'
,
done
=>
{
service
.
backupResource
(
untitledFile
,
`test`
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
getWorkspaceFileBackups
().
then
(
textFiles
=>
{
assert
.
deepEqual
(
textFiles
.
map
(
f
=>
f
.
fsPath
),
[
untitledFile
.
fsPath
]);
done
();
...
...
@@ -261,7 +261,7 @@ suite('BackupFileService', () => {
});
test
(
'
("untitled") - untitled file
'
,
done
=>
{
service
.
backupResource
(
untitledFile
,
`test`
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
getWorkspaceFileBackups
().
then
(
textFiles
=>
{
assert
.
deepEqual
(
textFiles
.
map
(
f
=>
f
.
fsPath
),
[
'
Untitled-1
'
]);
done
();
...
...
@@ -273,7 +273,7 @@ suite('BackupFileService', () => {
test
(
'
resolveBackupContent
'
,
()
=>
{
test
(
'
should restore the original contents (untitled file)
'
,
()
=>
{
const
contents
=
'
test
\n
and more stuff
'
;
service
.
backupResource
(
untitledFile
,
c
ontents
).
then
(()
=>
{
service
.
backupResource
(
untitledFile
,
c
reateTextBufferFactory
(
contents
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
resolveBackupContent
(
service
.
toBackupResource
(
untitledFile
)).
then
(
factory
=>
{
assert
.
equal
(
contents
,
snapshotToString
(
factory
.
create
(
platform
.
isWindows
?
DefaultEndOfLine
.
CRLF
:
DefaultEndOfLine
.
LF
).
createSnapshot
(
true
)));
});
...
...
@@ -288,7 +288,7 @@ suite('BackupFileService', () => {
'
adipiscing ßß elit
'
,
].
join
(
''
);
service
.
backupResource
(
fooFile
,
c
ontents
).
then
(()
=>
{
service
.
backupResource
(
fooFile
,
c
reateTextBufferFactory
(
contents
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
)
).
then
(()
=>
{
service
.
resolveBackupContent
(
service
.
toBackupResource
(
untitledFile
)).
then
(
factory
=>
{
assert
.
equal
(
contents
,
snapshotToString
(
factory
.
create
(
platform
.
isWindows
?
DefaultEndOfLine
.
CRLF
:
DefaultEndOfLine
.
LF
).
createSnapshot
(
true
)));
});
...
...
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
浏览文件 @
4644b60d
...
...
@@ -23,7 +23,7 @@ import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorMo
import
{
EncodingMode
}
from
'
vs/workbench/common/editor
'
;
import
{
BaseTextEditorModel
}
from
'
vs/workbench/common/editor/textEditorModel
'
;
import
{
IBackupFileService
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
IFileService
,
IFileStat
,
FileOperationError
,
FileOperationResult
,
IContent
,
CONTENT_CHANGE_EVENT_BUFFER_DELAY
,
FileChangesEvent
,
FileChangeType
}
from
'
vs/platform/files/common/files
'
;
import
{
IFileService
,
IFileStat
,
FileOperationError
,
FileOperationResult
,
CONTENT_CHANGE_EVENT_BUFFER_DELAY
,
FileChangesEvent
,
FileChangeType
}
from
'
vs/platform/files/common/files
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IMessageService
,
Severity
}
from
'
vs/platform/message/common/message
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
...
...
@@ -32,6 +32,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
ITextBufferFactory
}
from
'
vs/editor/common/model
'
;
import
{
IHashService
}
from
'
vs/workbench/services/hash/common/hashService
'
;
import
{
createTextBufferFactory
}
from
'
vs/editor/common/model/textModel
'
;
/**
* 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.
...
...
@@ -290,12 +291,12 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
// If we have a backup, continue loading with it
if
(
!!
backup
)
{
const
content
:
IContent
=
{
const
content
:
I
RawText
Content
=
{
resource
:
this
.
resource
,
name
:
paths
.
basename
(
this
.
resource
.
fsPath
),
mtime
:
Date
.
now
(),
etag
:
void
0
,
value
:
''
,
/* will be filled later from backup */
value
:
createTextBufferFactory
(
''
)
,
/* will be filled later from backup */
encoding
:
this
.
fileService
.
getEncoding
(
this
.
resource
,
this
.
preferredEncoding
)
};
...
...
@@ -355,7 +356,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return
TPromise
.
wrapError
<
TextFileEditorModel
>
(
error
);
}
private
loadWithContent
(
content
:
IRawTextContent
|
IContent
,
backup
?:
URI
):
TPromise
<
TextFileEditorModel
>
{
private
loadWithContent
(
content
:
IRawTextContent
,
backup
?:
URI
):
TPromise
<
TextFileEditorModel
>
{
return
this
.
doLoadWithContent
(
content
,
backup
).
then
(
model
=>
{
// Telemetry: We log the fileGet telemetry event after the model has been loaded to ensure a good mimetype
...
...
@@ -379,7 +380,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
});
}
private
doLoadWithContent
(
content
:
IRawTextContent
|
IContent
,
backup
?:
URI
):
TPromise
<
TextFileEditorModel
>
{
private
doLoadWithContent
(
content
:
IRawTextContent
,
backup
?:
URI
):
TPromise
<
TextFileEditorModel
>
{
diag
(
'
load() - resolved content
'
,
this
.
resource
,
new
Date
());
// Update our resolved disk stat model
...
...
@@ -420,7 +421,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return
this
.
doCreateTextModel
(
content
.
resource
,
content
.
value
,
backup
);
}
private
doUpdateTextModel
(
value
:
string
|
ITextBufferFactory
):
TPromise
<
TextFileEditorModel
>
{
private
doUpdateTextModel
(
value
:
ITextBufferFactory
):
TPromise
<
TextFileEditorModel
>
{
diag
(
'
load() - updated text editor model
'
,
this
.
resource
,
new
Date
());
// Ensure we are not tracking a stale state
...
...
@@ -440,7 +441,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return
TPromise
.
as
<
TextFileEditorModel
>
(
this
);
}
private
doCreateTextModel
(
resource
:
URI
,
value
:
string
|
ITextBufferFactory
,
backup
:
URI
):
TPromise
<
TextFileEditorModel
>
{
private
doCreateTextModel
(
resource
:
URI
,
value
:
ITextBufferFactory
,
backup
:
URI
):
TPromise
<
TextFileEditorModel
>
{
diag
(
'
load() - created text editor model
'
,
this
.
resource
,
new
Date
());
this
.
createTextEditorModelPromise
=
this
.
doLoadBackup
(
backup
).
then
(
backupContent
=>
{
...
...
src/vs/workbench/test/common/editor/editorModel.test.ts
浏览文件 @
4644b60d
...
...
@@ -15,9 +15,16 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
TestConfigurationService
}
from
'
vs/platform/configuration/test/common/testConfigurationService
'
;
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
import
{
ITextBufferFactory
}
from
'
vs/editor/common/model
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
createTextBufferFactory
}
from
'
vs/editor/common/model/textModel
'
;
class
MyEditorModel
extends
EditorModel
{
}
class
MyTextEditorModel
extends
BaseTextEditorModel
{
}
class
MyTextEditorModel
extends
BaseTextEditorModel
{
public
createTextEditorModel
(
value
:
ITextBufferFactory
,
resource
?:
URI
,
modeId
?:
string
)
{
return
super
.
createTextEditorModel
(
value
,
resource
,
modeId
);
}
}
suite
(
'
Workbench - EditorModel
'
,
()
=>
{
...
...
@@ -51,9 +58,9 @@ suite('Workbench - EditorModel', () => {
let
modelService
=
stubModelService
(
instantiationService
);
let
m
=
new
MyTextEditorModel
(
modelService
,
modeService
);
m
.
load
().
then
((
model
:
any
)
=>
{
m
.
load
().
then
((
model
:
MyTextEditorModel
)
=>
{
assert
(
model
===
m
);
return
model
.
createTextEditorModel
(
'
foo
'
,
null
,
'
text/plain
'
).
then
(()
=>
{
return
model
.
createTextEditorModel
(
createTextBufferFactory
(
'
foo
'
)
,
null
,
'
text/plain
'
).
then
(()
=>
{
assert
.
strictEqual
(
m
.
isResolved
(),
true
);
});
}).
done
(()
=>
{
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
4644b60d
...
...
@@ -857,7 +857,7 @@ export class TestBackupFileService implements IBackupFileService {
return
null
;
}
public
backupResource
(
resource
:
URI
,
content
:
string
|
ITextSnapshot
):
TPromise
<
void
>
{
public
backupResource
(
resource
:
URI
,
content
:
ITextSnapshot
):
TPromise
<
void
>
{
return
TPromise
.
as
(
void
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录