Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9b0e1d35
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,发现更多精彩内容 >>
提交
9b0e1d35
编写于
9月 05, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify all tests that deal with textFileServices
上级
82d9fb51
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
235 addition
and
416 deletion
+235
-416
src/vs/test/utils/servicesTestUtils.ts
src/vs/test/utils/servicesTestUtils.ts
+65
-40
src/vs/workbench/common/editor/binaryEditorModel.ts
src/vs/workbench/common/editor/binaryEditorModel.ts
+1
-1
src/vs/workbench/parts/files/common/textFileServices.ts
src/vs/workbench/parts/files/common/textFileServices.ts
+23
-4
src/vs/workbench/parts/files/electron-browser/textFileServices.ts
...orkbench/parts/files/electron-browser/textFileServices.ts
+3
-23
src/vs/workbench/parts/files/test/browser/events.test.ts
src/vs/workbench/parts/files/test/browser/events.test.ts
+6
-6
src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts
...orkbench/parts/files/test/browser/fileEditorInput.test.ts
+37
-112
src/vs/workbench/parts/files/test/browser/fileEditorModel.test.ts
...orkbench/parts/files/test/browser/fileEditorModel.test.ts
+37
-61
src/vs/workbench/parts/files/test/browser/textFileEditor.test.ts
...workbench/parts/files/test/browser/textFileEditor.test.ts
+7
-18
src/vs/workbench/parts/files/test/browser/textFileEditorModelCache.test.ts
...parts/files/test/browser/textFileEditorModelCache.test.ts
+4
-4
src/vs/workbench/parts/files/test/browser/viewModel.test.ts
src/vs/workbench/parts/files/test/browser/viewModel.test.ts
+49
-49
src/vs/workbench/test/browser/services.test.ts
src/vs/workbench/test/browser/services.test.ts
+3
-98
未找到文件。
src/vs/test/utils/servicesTestUtils.ts
浏览文件 @
9b0e1d35
...
...
@@ -7,26 +7,24 @@
import
{
Promise
,
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
EventEmitter
=
require
(
'
vs/base/common/eventEmitter
'
)
;
import
Paths
=
require
(
'
vs/base/common/paths
'
)
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
Storage
=
require
(
'
vs/workbench/common/storage
'
)
;
import
{
ITelemetryService
,
NullTelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
Storage
,
InMemoryLocalStorage
}
from
'
vs/workbench/common/storage
'
;
import
{
EditorInputEvent
,
IEditorGroup
}
from
'
vs/workbench/common/editor
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
IConfigurationService
,
getConfigurationValue
,
IConfigurationValue
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
WorkbenchEditorService
=
require
(
'
vs/workbench/services/editor/common/editorService
'
);
import
QuickOpenService
=
require
(
'
vs/workbench/services/quickopen/common/quickOpenService
'
);
import
PartService
=
require
(
'
vs/workbench/services/part/common/partService
'
);
import
WorkspaceContextService
=
require
(
'
vs/platform/workspace/common/workspace
'
);
import
{
IQuickOpenService
}
from
'
vs/workbench/services/quickopen/common/quickOpenService
'
;
import
{
IPartService
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
IEditorInput
,
IEditorModel
,
Position
,
Direction
,
IEditor
,
IResourceInput
,
ITextEditorModel
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
IUntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IUntitledEditorService
,
UntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IMessageService
,
IConfirmation
}
from
'
vs/platform/message/common/message
'
;
import
{
IWorkspace
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ILifecycleService
,
ShutdownEvent
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IWorkspace
,
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ILifecycleService
,
ShutdownEvent
,
NullLifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
EditorStacksModel
}
from
'
vs/workbench/common/editor/editorStacksModel
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
...
...
@@ -40,6 +38,10 @@ import {IRawTextContent} from 'vs/workbench/parts/files/common/files';
import
{
RawText
}
from
'
vs/editor/common/model/textModel
'
;
import
{
parseArgs
}
from
'
vs/code/node/argv
'
;
import
{
EnvironmentService
}
from
'
vs/platform/environment/node/environmentService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITextFileService
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
IHistoryService
}
from
'
vs/workbench/services/history/common/history
'
;
export
const
TestWorkspace
:
IWorkspace
=
{
resource
:
URI
.
file
(
'
C:
\\
testWorkspace
'
),
...
...
@@ -49,7 +51,7 @@ export const TestWorkspace: IWorkspace = {
export
const
TestEnvironmentService
=
new
EnvironmentService
(
parseArgs
(
process
.
argv
),
process
.
execPath
);
export
class
TestContextService
implements
WorkspaceContextService
.
IWorkspaceContextService
{
export
class
TestContextService
implements
IWorkspaceContextService
{
public
_serviceBrand
:
any
;
private
workspace
:
any
;
...
...
@@ -74,55 +76,78 @@ export class TestContextService implements WorkspaceContextService.IWorkspaceCon
public
isInsideWorkspace
(
resource
:
URI
):
boolean
{
if
(
resource
&&
this
.
workspace
)
{
return
P
aths
.
isEqualOrParent
(
resource
.
fsPath
,
this
.
workspace
.
resource
.
fsPath
);
return
p
aths
.
isEqualOrParent
(
resource
.
fsPath
,
this
.
workspace
.
resource
.
fsPath
);
}
return
false
;
}
public
toWorkspaceRelativePath
(
resource
:
URI
):
string
{
return
Paths
.
makePosixAbsolute
(
P
aths
.
normalize
(
resource
.
fsPath
.
substr
(
'
c:
'
.
length
)));
return
paths
.
makePosixAbsolute
(
p
aths
.
normalize
(
resource
.
fsPath
.
substr
(
'
c:
'
.
length
)));
}
public
toResource
(
workspaceRelativePath
:
string
):
URI
{
return
URI
.
file
(
P
aths
.
join
(
'
C:
\\
'
,
workspaceRelativePath
));
return
URI
.
file
(
p
aths
.
join
(
'
C:
\\
'
,
workspaceRelativePath
));
}
}
export
abstract
class
TestTextFileService
extends
TextFileService
{
constructor
(
@
WorkspaceContextService
.
IWorkspaceContextService
contextService
:
WorkspaceContextService
.
IWorkspaceContextService
,
@
ILifecycleService
lifecycleService
:
ILifecycleService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IConfigurationService
configurationService
:
IConfigurationService
,
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
WorkbenchEditorService
.
IWorkbenchEditorService
editorService
:
WorkbenchEditorService
.
IWorkbenchEditorService
,
@
IWorkbenchEditorService
editorService
:
IWorkbenchEditorService
,
@
IEditorGroupService
editorGroupService
:
IEditorGroupService
,
@
IEventService
eventService
:
IEventService
,
@
IFileService
fileService
:
IFileService
,
@
IModelService
modelService
:
IModelService
)
{
super
(
contextService
,
instantiationService
,
configurationService
,
telemetry
Service
,
editorService
,
eventService
,
fileService
,
modelService
);
super
(
lifecycleService
,
contextService
,
instantiationService
,
configurationService
,
telemetryService
,
editorGroup
Service
,
editorService
,
eventService
,
fileService
,
modelService
);
}
public
resolveTextContent
(
resource
:
URI
,
options
?:
IResolveContentOptions
):
TPromise
<
IRawTextContent
>
{
return
this
.
fileService
.
resolveContent
(
resource
,
options
).
then
((
content
)
=>
{
const
raw
=
RawText
.
fromString
(
content
.
value
,
{
defaultEOL
:
1
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
false
});
return
<
IRawTextContent
>
{
return
<
IRawTextContent
>
{
resource
:
content
.
resource
,
name
:
content
.
name
,
mtime
:
content
.
mtime
,
etag
:
content
.
etag
,
mime
:
content
.
mime
,
encoding
:
content
.
encoding
,
value
:
raw
,
valueLogicalHash
:
null
name
:
content
.
name
,
mtime
:
content
.
mtime
,
etag
:
content
.
etag
,
mime
:
content
.
mime
,
encoding
:
content
.
encoding
,
value
:
raw
,
valueLogicalHash
:
null
};
});
}
}
export
function
textFileServiceInstantiationService
():
TestInstantiationService
{
let
instantiationService
=
new
TestInstantiationService
();
instantiationService
.
stub
(
IEventService
,
new
TestEventService
());
instantiationService
.
stub
(
IWorkspaceContextService
,
new
TestContextService
(
TestWorkspace
));
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
IUntitledEditorService
,
instantiationService
.
createInstance
(
UntitledEditorService
));
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
new
TestEditorService
(
function
()
{
}));
instantiationService
.
stub
(
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IEditorGroupService
,
new
TestEditorGroupService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IHistoryService
,
'
getHistory
'
,
[]);
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IFileService
,
TestFileService
);
instantiationService
.
stub
(
ITelemetryService
,
NullTelemetryService
);
instantiationService
.
stub
(
IMessageService
,
new
TestMessageService
());
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
return
instantiationService
;
}
export
class
TestMessageService
implements
IMessageService
{
public
_serviceBrand
:
any
;
...
...
@@ -151,7 +176,7 @@ export class TestMessageService implements IMessageService {
}
}
export
class
TestPartService
implements
PartService
.
IPartService
{
export
class
TestPartService
implements
IPartService
{
public
_serviceBrand
:
any
;
public
layout
():
void
{
}
...
...
@@ -200,20 +225,20 @@ export class TestPartService implements PartService.IPartService {
public
getWorkbenchElementId
():
string
{
return
''
;
}
}
export
class
TestEventService
extends
EventEmitter
.
EventEmitter
implements
IEventService
{
export
class
TestEventService
extends
EventEmitter
implements
IEventService
{
public
_serviceBrand
:
any
;
}
export
class
TestStorageService
extends
EventEmitter
.
EventEmitter
implements
IStorageService
{
export
class
TestStorageService
extends
EventEmitter
implements
IStorageService
{
public
_serviceBrand
:
any
;
private
storage
:
Storage
.
Storage
;
private
storage
:
Storage
;
constructor
()
{
super
();
let
context
=
new
TestContextService
();
this
.
storage
=
new
Storage
.
Storage
(
new
Storage
.
InMemoryLocalStorage
(),
null
,
context
);
this
.
storage
=
new
Storage
(
new
InMemoryLocalStorage
(),
null
,
context
);
}
store
(
key
:
string
,
value
:
any
,
scope
:
StorageScope
=
StorageScope
.
GLOBAL
):
void
{
...
...
@@ -256,7 +281,7 @@ export class TestUntitledEditorService implements IUntitledEditorService {
return
[];
}
public
revertAll
(
resources
?:
URI
[]):
URI
[]
{
public
revertAll
(
resources
?:
URI
[]):
URI
[]
{
return
[];
}
...
...
@@ -292,7 +317,7 @@ export class TestEditorGroupService implements IEditorGroupService {
let
services
=
new
ServiceCollection
();
services
.
set
(
IStorageService
,
new
TestStorageService
());
services
.
set
(
WorkspaceContextService
.
IWorkspaceContextService
,
new
TestContextService
());
services
.
set
(
IWorkspaceContextService
,
new
TestContextService
());
const
lifecycle
=
new
TestLifecycleService
();
services
.
set
(
ILifecycleService
,
lifecycle
);
...
...
@@ -363,7 +388,7 @@ export class TestEditorGroupService implements IEditorGroupService {
}
}
export
class
TestEditorService
implements
WorkbenchEditorService
.
IWorkbenchEditorService
{
export
class
TestEditorService
implements
IWorkbenchEditorService
{
public
_serviceBrand
:
any
;
public
activeEditorInput
;
...
...
@@ -443,7 +468,7 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito
}
}
export
class
TestQuickOpenService
implements
QuickOpenService
.
IQuickOpenService
{
export
class
TestQuickOpenService
implements
IQuickOpenService
{
public
_serviceBrand
:
any
;
private
callback
:
(
prefix
:
string
)
=>
void
;
...
...
@@ -498,7 +523,7 @@ export const TestFileService = {
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
P
aths
.
basename
(
resource
.
fsPath
)
name
:
p
aths
.
basename
(
resource
.
fsPath
)
});
},
...
...
@@ -506,7 +531,7 @@ export const TestFileService = {
return
TPromise
.
as
({
resource
:
resource
,
value
:
{
on
:
(
event
:
string
,
callback
:
Function
):
void
=>
{
on
:
(
event
:
string
,
callback
:
Function
):
void
=>
{
if
(
event
===
'
data
'
)
{
callback
(
'
Hello Html
'
);
}
...
...
@@ -519,7 +544,7 @@ export const TestFileService = {
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
P
aths
.
basename
(
resource
.
fsPath
)
name
:
p
aths
.
basename
(
resource
.
fsPath
)
});
},
...
...
@@ -531,13 +556,13 @@ export const TestFileService = {
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
P
aths
.
basename
(
res
.
fsPath
)
name
:
p
aths
.
basename
(
res
.
fsPath
)
};
});
}
};
export
class
TestConfigurationService
extends
EventEmitter
.
EventEmitter
implements
IConfigurationService
{
export
class
TestConfigurationService
extends
EventEmitter
implements
IConfigurationService
{
public
_serviceBrand
:
any
;
private
configuration
=
Object
.
create
(
null
);
...
...
src/vs/workbench/common/editor/binaryEditorModel.ts
浏览文件 @
9b0e1d35
...
...
@@ -21,7 +21,7 @@ export class BinaryEditorModel extends EditorModel {
constructor
(
resource
:
URI
,
name
:
string
,
@
IFileService
pr
otected
fileService
:
IFileService
@
IFileService
pr
ivate
fileService
:
IFileService
)
{
super
();
...
...
src/vs/workbench/parts/files/common/textFileServices.ts
浏览文件 @
9b0e1d35
...
...
@@ -12,6 +12,7 @@ import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEdito
import
{
CACHE
,
TextFileEditorModel
}
from
'
vs/workbench/parts/files/common/editors/textFileEditorModel
'
;
import
{
IResult
,
ITextFileOperationResult
,
ITextFileService
,
IRawTextContent
,
IAutoSaveConfiguration
,
AutoSaveMode
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
ILifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IFileService
,
IResolveContentOptions
,
IFilesConfiguration
,
IFileOperationResult
,
FileOperationResult
,
AutoSaveConfiguration
}
from
'
vs/platform/files/common/files
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
...
...
@@ -21,6 +22,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
/**
* The workbench file service implementation implements the raw file service spec and adds additional methods on top.
...
...
@@ -40,10 +42,12 @@ export abstract class TextFileService implements ITextFileService {
protected
configuredAutoSaveOnWindowChange
:
boolean
;
constructor
(
@
ILifecycleService
protected
lifecycleService
:
ILifecycleService
,
@
IWorkspaceContextService
protected
contextService
:
IWorkspaceContextService
,
@
IInstantiationService
private
instantiationService
:
IInstantiationService
,
@
IConfigurationService
private
configurationService
:
IConfigurationService
,
@
ITelemetryService
private
telemetryService
:
ITelemetryService
,
@
IEditorGroupService
private
editorGroupService
:
IEditorGroupService
,
@
IWorkbenchEditorService
protected
editorService
:
IWorkbenchEditorService
,
@
IEventService
private
eventService
:
IEventService
,
@
IFileService
protected
fileService
:
IFileService
,
...
...
@@ -51,15 +55,13 @@ export abstract class TextFileService implements ITextFileService {
)
{
this
.
listenerToUnbind
=
[];
this
.
_onAutoSaveConfigurationChange
=
new
Emitter
<
IAutoSaveConfiguration
>
();
}
protected
init
():
void
{
this
.
registerListeners
();
const
configuration
=
this
.
configurationService
.
getConfiguration
<
IFilesConfiguration
>
();
this
.
onConfigurationChange
(
configuration
);
this
.
telemetryService
.
publicLog
(
'
autoSave
'
,
this
.
getAutoSaveConfiguration
());
this
.
registerListeners
();
}
public
abstract
resolveTextContent
(
resource
:
URI
,
options
?:
IResolveContentOptions
):
TPromise
<
IRawTextContent
>
;
...
...
@@ -72,6 +74,23 @@ export abstract class TextFileService implements ITextFileService {
// Configuration changes
this
.
listenerToUnbind
.
push
(
this
.
configurationService
.
onDidUpdateConfiguration
(
e
=>
this
.
onConfigurationChange
(
e
.
config
)));
// Application & Editor focus change
window
.
addEventListener
(
'
blur
'
,
()
=>
this
.
onWindowFocusLost
());
window
.
addEventListener
(
'
blur
'
,
()
=>
this
.
onEditorFocusChanged
(),
true
);
this
.
listenerToUnbind
.
push
(
this
.
editorGroupService
.
onEditorsChanged
(()
=>
this
.
onEditorFocusChanged
()));
}
private
onWindowFocusLost
():
void
{
if
(
this
.
configuredAutoSaveOnWindowChange
&&
this
.
isDirty
())
{
this
.
saveAll
().
done
(
null
,
errors
.
onUnexpectedError
);
}
}
private
onEditorFocusChanged
():
void
{
if
(
this
.
configuredAutoSaveOnFocusChange
&&
this
.
isDirty
())
{
this
.
saveAll
().
done
(
null
,
errors
.
onUnexpectedError
);
}
}
private
onConfigurationChange
(
configuration
:
IFilesConfiguration
):
void
{
...
...
src/vs/workbench/parts/files/electron-browser/textFileServices.ts
浏览文件 @
9b0e1d35
...
...
@@ -11,7 +11,6 @@ import paths = require('vs/base/common/paths');
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
{
isWindows
,
isLinux
}
from
'
vs/base/common/platform
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
errors
=
require
(
'
vs/base/common/errors
'
);
import
{
UntitledEditorModel
}
from
'
vs/workbench/common/editor/untitledEditorModel
'
;
import
{
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
...
...
@@ -44,20 +43,18 @@ export class TextFileService extends AbstractTextFileService {
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IFileService
fileService
:
IFileService
,
@
IUntitledEditorService
private
untitledEditorService
:
IUntitledEditorService
,
@
ILifecycleService
private
lifecycleService
:
ILifecycleService
,
@
ILifecycleService
lifecycleService
:
ILifecycleService
,
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IConfigurationService
configurationService
:
IConfigurationService
,
@
IEventService
eventService
:
IEventService
,
@
IModeService
private
modeService
:
IModeService
,
@
IWorkbenchEditorService
editorService
:
IWorkbenchEditorService
,
@
IEditorGroupService
private
editorGroupService
:
IEditorGroupService
,
@
IEditorGroupService
editorGroupService
:
IEditorGroupService
,
@
IWindowService
private
windowService
:
IWindowService
,
@
IModelService
modelService
:
IModelService
,
@
IEnvironmentService
private
environmentService
:
IEnvironmentService
)
{
super
(
contextService
,
instantiationService
,
configurationService
,
telemetryService
,
editorService
,
eventService
,
fileService
,
modelService
);
this
.
init
();
super
(
lifecycleService
,
contextService
,
instantiationService
,
configurationService
,
telemetryService
,
editorGroupService
,
editorService
,
eventService
,
fileService
,
modelService
);
}
protected
registerListeners
():
void
{
...
...
@@ -66,23 +63,6 @@ export class TextFileService extends AbstractTextFileService {
// Lifecycle
this
.
lifecycleService
.
onWillShutdown
(
event
=>
event
.
veto
(
this
.
beforeShutdown
()));
this
.
lifecycleService
.
onShutdown
(
this
.
onShutdown
,
this
);
// Application & Editor focus change
window
.
addEventListener
(
'
blur
'
,
()
=>
this
.
onWindowFocusLost
());
window
.
addEventListener
(
'
blur
'
,
()
=>
this
.
onEditorFocusChanged
(),
true
);
this
.
listenerToUnbind
.
push
(
this
.
editorGroupService
.
onEditorsChanged
(()
=>
this
.
onEditorFocusChanged
()));
}
private
onWindowFocusLost
():
void
{
if
(
this
.
configuredAutoSaveOnWindowChange
&&
this
.
isDirty
())
{
this
.
saveAll
().
done
(
null
,
errors
.
onUnexpectedError
);
}
}
private
onEditorFocusChanged
():
void
{
if
(
this
.
configuredAutoSaveOnFocusChange
&&
this
.
isDirty
())
{
this
.
saveAll
().
done
(
null
,
errors
.
onUnexpectedError
);
}
}
public
resolveTextContent
(
resource
:
URI
,
options
?:
IResolveContentOptions
):
TPromise
<
IRawTextContent
>
{
...
...
src/vs/workbench/parts/files/test/browser/events.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -12,10 +12,10 @@ import {FileImportedEvent} from 'vs/workbench/parts/files/browser/fileActions';
suite
(
'
Files - Events
'
,
()
=>
{
test
(
'
File Change Event (simple)
'
,
function
()
{
le
t
origEvent
:
any
=
{};
le
t
oldValue
:
any
=
{
foo
:
'
bar
'
};
le
t
newValue
:
any
=
{
foo
:
'
foo
'
};
le
t
event
=
new
LocalFileChangeEvent
(
oldValue
,
newValue
,
origEvent
);
cons
t
origEvent
:
any
=
{};
cons
t
oldValue
:
any
=
{
foo
:
'
bar
'
};
cons
t
newValue
:
any
=
{
foo
:
'
foo
'
};
cons
t
event
=
new
LocalFileChangeEvent
(
oldValue
,
newValue
,
origEvent
);
assert
.
strictEqual
(
event
.
originalEvent
,
origEvent
);
assert
.
strictEqual
(
event
.
oldValue
,
oldValue
);
...
...
@@ -24,8 +24,8 @@ suite('Files - Events', () => {
});
test
(
'
File Upload Event
'
,
function
()
{
le
t
origEvent
:
any
=
{};
le
t
value
:
any
=
{
foo
:
'
bar
'
};
cons
t
origEvent
:
any
=
{};
cons
t
value
:
any
=
{
foo
:
'
bar
'
};
let
event
=
new
FileImportedEvent
(
value
,
true
,
origEvent
);
assert
.
strictEqual
(
event
.
originalEvent
,
origEvent
);
...
...
src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -6,64 +6,38 @@
import
'
vs/workbench/parts/files/browser/files.contribution
'
;
// load our contribution into the test
import
*
as
assert
from
'
assert
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
join
}
from
'
vs/base/common/paths
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
ITelemetryService
,
NullTelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ILifecycleService
,
NullLifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
IQuickOpenService
}
from
'
vs/workbench/services/quickopen/common/quickOpenService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IPartService
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
ITextFileService
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
FileTracker
}
from
'
vs/workbench/parts/files/browser/fileTracker
'
;
import
{
createMockModelService
,
TestTextFileService
,
TestEditorGroupService
,
TestFileService
,
TestEditorService
,
TestPartService
,
TestConfigurationService
,
TestEventService
,
TestContextService
,
TestQuickOpenService
,
TestStorageService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
IHistoryService
}
from
'
vs/workbench/services/history/common/history
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
textFileServiceInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
function
toResource
(
path
)
{
return
URI
.
file
(
join
(
'
C:
\\
'
,
path
));
}
class
ServiceAccessor
{
constructor
(@
IWorkbenchEditorService
public
editorService
:
IWorkbenchEditorService
)
{
}
}
let
accessor
:
ServiceAccessor
;
suite
(
'
Files - FileEditorInput
'
,
()
=>
{
let
instantiationService
:
TestInstantiationService
;
setup
(()
=>
{
instantiationService
=
new
Test
InstantiationService
();
instantiationService
.
stub
(
IHistoryService
,
'
getHistory
'
,
[]
);
instantiationService
=
textFileService
InstantiationService
();
accessor
=
instantiationService
.
createInstance
(
ServiceAccessor
);
});
test
(
'
FileEditorInput
'
,
function
(
done
)
{
let
editorService
=
new
TestEditorService
(
function
()
{
});
let
eventService
=
new
TestEventService
();
let
telemetryService
=
NullTelemetryService
;
let
contextService
=
new
TestContextService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
IFileService
,
<
any
>
TestFileService
);
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
editorService
);
instantiationService
.
stub
(
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ITelemetryService
,
telemetryService
);
instantiationService
.
stub
(
IEditorGroupService
,
new
TestEditorGroupService
());
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
le
t
otherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
foo/bar/otherfile.js
'
),
'
text/javascript
'
,
void
0
);
le
t
otherInputSame
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
cons
t
otherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
foo/bar/otherfile.js
'
),
'
text/javascript
'
,
void
0
);
cons
t
otherInputSame
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
assert
(
input
.
matches
(
input
));
assert
(
input
.
matches
(
otherInputSame
));
...
...
@@ -78,20 +52,20 @@ suite('Files - FileEditorInput', () => {
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar.html
'
),
'
text/html
'
,
void
0
);
le
t
inputToResolve
:
any
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
le
t
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
cons
t
inputToResolve
:
any
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
cons
t
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
le
t
resolvedModelA
=
resolved
;
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
cons
t
resolvedModelA
=
resolved
;
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
assert
(
resolvedModelA
===
resolved
);
// OK: Resolved Model cached globally per input
return
editorService
.
resolveEditorModel
(
sameOtherInput
,
true
).
then
(
function
(
otherResolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
sameOtherInput
,
true
).
then
(
function
(
otherResolved
)
{
assert
(
otherResolved
===
resolvedModelA
);
// OK: Resolved Model cached globally per input
inputToResolve
.
dispose
(
false
);
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
assert
(
resolvedModelA
===
resolved
);
// Model is still the same because we had 2 clients
inputToResolve
.
dispose
();
...
...
@@ -99,15 +73,15 @@ suite('Files - FileEditorInput', () => {
resolvedModelA
.
dispose
();
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
assert
(
resolvedModelA
!==
resolved
);
// Different instance, because input got disposed
let
stat
=
(
<
any
>
resolved
).
versionOnDiskStat
;
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
assert
(
stat
!==
(
<
any
>
resolved
).
versionOnDiskStat
);
// Different stat, because resolve always goes to the server for refresh
stat
=
(
<
any
>
resolved
).
versionOnDiskStat
;
return
editorService
.
resolveEditorModel
(
inputToResolve
,
false
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
false
).
then
(
function
(
resolved
)
{
assert
(
stat
===
(
<
any
>
resolved
).
versionOnDiskStat
);
// Same stat, because not refreshed
done
();
...
...
@@ -121,15 +95,8 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
Input.matches() - FileEditorInput
'
,
function
()
{
let
eventService
=
new
TestEventService
();
let
contextService
=
new
TestContextService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
fileEditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/updatefile.js
'
),
'
text/javascript
'
,
void
0
);
let
contentEditorInput2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/updatefile.js
'
),
'
text/javascript
'
,
void
0
);
const
fileEditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/updatefile.js
'
),
'
text/javascript
'
,
void
0
);
const
contentEditorInput2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo/bar/updatefile.js
'
),
'
text/javascript
'
,
void
0
);
assert
.
strictEqual
(
fileEditorInput
.
matches
(
null
),
false
);
assert
.
strictEqual
(
fileEditorInput
.
matches
(
fileEditorInput
),
true
);
...
...
@@ -137,33 +104,12 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
FileTracker - dispose()
'
,
function
(
done
)
{
let
editorService
=
new
TestEditorService
(
function
()
{
});
let
telemetryService
=
NullTelemetryService
;
let
contextService
=
new
TestContextService
();
let
eventService
=
new
TestEventService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
IFileService
,
<
any
>
TestFileService
);
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
editorService
);
instantiationService
.
stub
(
IQuickOpenService
,
new
TestQuickOpenService
());
instantiationService
.
stub
(
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IEditorGroupService
,
new
TestEditorGroupService
());
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ITelemetryService
,
telemetryService
);
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
tracker
=
instantiationService
.
createInstance
(
FileTracker
);
let
inputToResolve
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/fooss5/bar/file2.js
'
),
'
text/javascript
'
,
void
0
);
let
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/fooss5/bar/file2.js
'
),
'
text/javascript
'
,
void
0
);
return
editorService
.
resolveEditorModel
(
inputToResolve
).
then
(
function
(
resolved
)
{
return
editorService
.
resolveEditorModel
(
sameOtherInput
).
then
(
function
(
resolved
)
{
const
tracker
=
instantiationService
.
createInstance
(
FileTracker
);
const
inputToResolve
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/fooss5/bar/file2.js
'
),
'
text/javascript
'
,
void
0
);
const
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/fooss5/bar/file2.js
'
),
'
text/javascript
'
,
void
0
);
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
sameOtherInput
).
then
(
function
(
resolved
)
{
tracker
.
handleDeleteOrMove
(
toResource
(
'
/bar
'
),
[]);
assert
(
!
inputToResolve
.
isDisposed
());
assert
(
!
sameOtherInput
.
isDisposed
());
...
...
@@ -179,33 +125,12 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
FileEditorInput - dispose() also works for folders
'
,
function
(
done
)
{
let
editorService
=
new
TestEditorService
(
function
()
{
});
let
telemetryService
=
NullTelemetryService
;
let
contextService
=
new
TestContextService
();
let
eventService
=
new
TestEventService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
IFileService
,
<
any
>
TestFileService
);
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
editorService
);
instantiationService
.
stub
(
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IEditorGroupService
,
new
TestEditorGroupService
());
instantiationService
.
stub
(
IQuickOpenService
,
new
TestQuickOpenService
());
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ITelemetryService
,
telemetryService
);
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
tracker
=
instantiationService
.
createInstance
(
FileTracker
);
let
inputToResolve
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo6/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
let
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo6/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
return
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
editorService
.
resolveEditorModel
(
sameOtherInput
,
true
).
then
(
function
(
resolved
)
{
const
tracker
=
instantiationService
.
createInstance
(
FileTracker
);
const
inputToResolve
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo6/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
const
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/foo6/bar/file.js
'
),
'
text/javascript
'
,
void
0
);
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
function
(
resolved
)
{
return
accessor
.
editorService
.
resolveEditorModel
(
sameOtherInput
,
true
).
then
(
function
(
resolved
)
{
tracker
.
handleDeleteOrMove
(
toResource
(
'
/bar
'
),
[]);
assert
(
!
inputToResolve
.
isDisposed
());
assert
(
!
sameOtherInput
.
isDisposed
());
...
...
src/vs/workbench/parts/files/test/browser/fileEditorModel.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -6,58 +6,34 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
TextFileEditorModel
,
CACHE
}
from
'
vs/workbench/parts/files/common/editors/textFileEditorModel
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ILifecycleService
,
NullLifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
IUntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
PartService
=
require
(
'
vs/workbench/services/part/common/partService
'
);
import
{
ITextFileService
,
EventType
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
createMockModelService
,
TestTextFileService
,
TestFileService
,
TestPartService
,
TestEditorService
,
TestConfigurationService
,
TestUntitledEditorService
,
TestStorageService
,
TestContextService
,
TestMessageService
,
TestEventService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
EventType
,
ITextFileService
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
textFileServiceInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
function
toResource
(
path
)
{
return
URI
.
file
(
paths
.
join
(
'
C:
\\
'
,
path
));
}
let
eventService
:
IEventService
;
let
textFileService
:
TestTextFileService
;
class
ServiceAccessor
{
constructor
(@
IEventService
public
eventService
:
IEventService
,
@
ITextFileService
public
textFileService
:
ITextFileService
)
{
}
}
let
accessor
:
ServiceAccessor
;
suite
(
'
Files - TextFileEditorModel
'
,
()
=>
{
let
instantiationService
:
TestInstantiationService
;
setup
(()
=>
{
instantiationService
=
new
TestInstantiationService
();
eventService
=
new
TestEventService
();
eventService
=
<
IEventService
>
instantiationService
.
stub
(
IEventService
,
new
TestEventService
());
instantiationService
.
stub
(
IMessageService
,
new
TestMessageService
());
instantiationService
.
stub
(
IFileService
,
<
any
>
TestFileService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
new
TestContextService
());
instantiationService
.
stub
(
ITelemetryService
);
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IUntitledEditorService
,
new
TestUntitledEditorService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
new
TestEditorService
());
instantiationService
.
stub
(
PartService
.
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
textFileService
=
<
any
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
);
instantiationService
.
stub
(
ITextFileService
,
textFileService
);
instantiationService
=
textFileServiceInstantiationService
();
accessor
=
instantiationService
.
createInstance
(
ServiceAccessor
);
});
teardown
(()
=>
{
...
...
@@ -65,17 +41,17 @@ suite('Files - TextFileEditorModel', () => {
});
test
(
'
Load does not trigger save
'
,
function
(
done
)
{
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index.txt
'
),
'
utf8
'
);
eventService
.
addListener2
(
'
files:internalFileChanged
'
,
()
=>
{
accessor
.
eventService
.
addListener2
(
'
files:internalFileChanged
'
,
()
=>
{
assert
.
ok
(
false
);
});
eventService
.
addListener2
(
EventType
.
FILE_DIRTY
,
()
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_DIRTY
,
()
=>
{
assert
.
ok
(
false
);
});
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
()
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
()
=>
{
assert
.
ok
(
false
);
});
...
...
@@ -89,7 +65,7 @@ suite('Files - TextFileEditorModel', () => {
});
test
(
'
Load returns dirty model as long as model is dirty
'
,
function
(
done
)
{
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
m1
.
load
().
then
(()
=>
{
m1
.
textEditorModel
.
setValue
(
'
foo
'
);
...
...
@@ -108,11 +84,11 @@ suite('Files - TextFileEditorModel', () => {
test
(
'
Revert
'
,
function
(
done
)
{
let
eventCounter
=
0
;
eventService
.
addListener2
(
EventType
.
FILE_REVERTED
,
()
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_REVERTED
,
()
=>
{
eventCounter
++
;
});
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
m1
.
load
().
then
(()
=>
{
m1
.
textEditorModel
.
setValue
(
'
foo
'
);
...
...
@@ -132,7 +108,7 @@ suite('Files - TextFileEditorModel', () => {
});
test
(
'
Conflict Resolution Mode
'
,
function
(
done
)
{
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
m1
.
load
().
then
(()
=>
{
m1
.
setConflictResolutionMode
();
...
...
@@ -158,16 +134,16 @@ suite('Files - TextFileEditorModel', () => {
test
(
'
Auto Save triggered when model changes
'
,
function
(
done
)
{
let
eventCounter
=
0
;
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index.txt
'
),
'
utf8
'
);
(
<
any
>
m1
).
autoSaveAfterMillies
=
10
;
(
<
any
>
m1
).
autoSaveAfterMilliesEnabled
=
true
;
eventService
.
addListener2
(
EventType
.
FILE_DIRTY
,
()
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_DIRTY
,
()
=>
{
eventCounter
++
;
});
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
()
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
()
=>
{
eventCounter
++
;
});
...
...
@@ -186,29 +162,29 @@ suite('Files - TextFileEditorModel', () => {
});
test
(
'
save() and isDirty() - proper with check for mtimes
'
,
function
(
done
)
{
le
t
c1
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/path/index_async2.txt
'
),
'
text/plain
'
,
'
utf8
'
);
le
t
c2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/path/index_async.txt
'
),
'
text/plain
'
,
'
utf8
'
);
cons
t
c1
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/path/index_async2.txt
'
),
'
text/plain
'
,
'
utf8
'
);
cons
t
c2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/path/index_async.txt
'
),
'
text/plain
'
,
'
utf8
'
);
c1
.
resolve
().
then
((
m1
:
TextFileEditorModel
)
=>
{
c2
.
resolve
().
then
((
m2
:
TextFileEditorModel
)
=>
{
m1
.
textEditorModel
.
setValue
(
'
foo
'
);
le
t
m1Mtime
=
m1
.
getLastModifiedTime
();
le
t
m2Mtime
=
m2
.
getLastModifiedTime
();
cons
t
m1Mtime
=
m1
.
getLastModifiedTime
();
cons
t
m2Mtime
=
m2
.
getLastModifiedTime
();
assert
.
ok
(
m1Mtime
>
0
);
assert
.
ok
(
m2Mtime
>
0
);
assert
.
ok
(
textFileService
.
isDirty
());
assert
.
ok
(
textFileService
.
isDirty
(
toResource
(
'
/path/index_async2.txt
'
)));
assert
.
ok
(
!
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
assert
.
ok
(
accessor
.
textFileService
.
isDirty
());
assert
.
ok
(
accessor
.
textFileService
.
isDirty
(
toResource
(
'
/path/index_async2.txt
'
)));
assert
.
ok
(
!
accessor
.
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
m2
.
textEditorModel
.
setValue
(
'
foo
'
);
assert
.
ok
(
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
assert
.
ok
(
accessor
.
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
return
TPromise
.
timeout
(
10
).
then
(()
=>
{
textFileService
.
saveAll
().
then
(()
=>
{
assert
.
ok
(
!
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
assert
.
ok
(
!
textFileService
.
isDirty
(
toResource
(
'
/path/index_async2.txt
'
)));
accessor
.
textFileService
.
saveAll
().
then
(()
=>
{
assert
.
ok
(
!
accessor
.
textFileService
.
isDirty
(
toResource
(
'
/path/index_async.txt
'
)));
assert
.
ok
(
!
accessor
.
textFileService
.
isDirty
(
toResource
(
'
/path/index_async2.txt
'
)));
assert
.
ok
(
m1
.
getLastModifiedTime
()
>
m1Mtime
);
assert
.
ok
(
m2
.
getLastModifiedTime
()
>
m2Mtime
);
assert
.
ok
(
m1
.
getLastSaveAttemptTime
()
>
m1Mtime
);
...
...
@@ -226,15 +202,15 @@ suite('Files - TextFileEditorModel', () => {
test
(
'
Save Participant
'
,
function
(
done
)
{
let
eventCounter
=
0
;
le
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
cons
t
m1
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
(
'
/path/index_async.txt
'
),
'
utf8
'
);
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
(
e
)
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_SAVED
,
(
e
)
=>
{
assert
.
equal
(
m1
.
getValue
(),
'
bar
'
);
assert
.
ok
(
!
m1
.
isDirty
());
eventCounter
++
;
});
eventService
.
addListener2
(
EventType
.
FILE_SAVING
,
(
e
)
=>
{
accessor
.
eventService
.
addListener2
(
EventType
.
FILE_SAVING
,
(
e
)
=>
{
assert
.
ok
(
m1
.
isDirty
());
m1
.
textEditorModel
.
setValue
(
'
bar
'
);
assert
.
ok
(
m1
.
isDirty
());
...
...
src/vs/workbench/parts/files/test/browser/textFileEditor.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -8,16 +8,12 @@
import
{
strictEqual
,
equal
}
from
'
assert
'
;
import
{
join
}
from
'
vs/base/common/paths
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
{
FileEditorDescriptor
}
from
'
vs/workbench/parts/files/browser/files
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
SyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
Extensions
}
from
'
vs/workbench/common/editor
'
;
import
{
TestTextFileService
,
TestEventService
,
TestContextService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ITextFileService
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
textFileServiceInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
const
ExtensionId
=
Extensions
.
Editors
;
...
...
@@ -27,14 +23,14 @@ class MyOtherClass { }
suite
(
'
Files - TextFileEditor
'
,
()
=>
{
test
(
'
TextFile Editor Registration
'
,
function
()
{
le
t
d1
=
new
FileEditorDescriptor
(
'
ce-id1
'
,
'
name
'
,
'
vs/workbench/parts/files/browser/tests/contentEditor.test
'
,
'
MyClass
'
,
[
'
test-text/html
'
,
'
test-text/javascript
'
]);
le
t
d2
=
new
FileEditorDescriptor
(
'
ce-id2
'
,
'
name
'
,
'
vs/workbench/parts/files/browser/tests/contentEditor.test
'
,
'
MyOtherClass
'
,
[
'
test-text/css
'
,
'
test-text/javascript
'
]);
cons
t
d1
=
new
FileEditorDescriptor
(
'
ce-id1
'
,
'
name
'
,
'
vs/workbench/parts/files/browser/tests/contentEditor.test
'
,
'
MyClass
'
,
[
'
test-text/html
'
,
'
test-text/javascript
'
]);
cons
t
d2
=
new
FileEditorDescriptor
(
'
ce-id2
'
,
'
name
'
,
'
vs/workbench/parts/files/browser/tests/contentEditor.test
'
,
'
MyOtherClass
'
,
[
'
test-text/css
'
,
'
test-text/javascript
'
]);
le
t
oldEditors
=
Registry
.
as
(
ExtensionId
).
getEditors
();
cons
t
oldEditors
=
Registry
.
as
(
ExtensionId
).
getEditors
();
Registry
.
as
(
ExtensionId
).
setEditors
([]);
le
t
oldEditorCnt
=
Registry
.
as
(
ExtensionId
).
getEditors
().
length
;
le
t
oldInputCnt
=
Registry
.
as
(
ExtensionId
).
getEditorInputs
().
length
;
cons
t
oldEditorCnt
=
Registry
.
as
(
ExtensionId
).
getEditors
().
length
;
cons
t
oldInputCnt
=
Registry
.
as
(
ExtensionId
).
getEditorInputs
().
length
;
Registry
.
as
(
ExtensionId
).
registerEditor
(
d1
,
new
SyncDescriptor
(
FileEditorInput
));
Registry
.
as
(
ExtensionId
).
registerEditor
(
d2
,
new
SyncDescriptor
(
FileEditorInput
));
...
...
@@ -42,14 +38,7 @@ suite('Files - TextFileEditor', () => {
equal
(
Registry
.
as
(
ExtensionId
).
getEditors
().
length
,
oldEditorCnt
+
2
);
equal
(
Registry
.
as
(
ExtensionId
).
getEditorInputs
().
length
,
oldInputCnt
+
2
);
let
eventService
=
new
TestEventService
();
let
contextService
=
new
TestContextService
();
let
instantiationService
=
new
TestInstantiationService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
const
instantiationService
=
textFileServiceInstantiationService
();
strictEqual
(
Registry
.
as
(
ExtensionId
).
getEditor
(
instantiationService
.
createInstance
(
FileEditorInput
,
URI
.
file
(
join
(
'
C:
\\
'
,
'
/foo/bar/foobar.html
'
)),
'
test-text/html
'
,
void
0
)),
d1
);
strictEqual
(
Registry
.
as
(
ExtensionId
).
getEditor
(
instantiationService
.
createInstance
(
FileEditorInput
,
URI
.
file
(
join
(
'
C:
\\
'
,
'
/foo/bar/foobar.js
'
)),
'
test-text/javascript
'
,
void
0
)),
d1
);
...
...
src/vs/workbench/parts/files/test/browser/textFileEditorModelCache.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -13,11 +13,11 @@ import {EditorModel} from 'vs/workbench/common/editor';
suite
(
'
Files - TextFileEditorModelCache
'
,
()
=>
{
test
(
'
add, remove, clear
'
,
function
()
{
le
t
cache
=
new
TextFileEditorModelCache
();
cons
t
cache
=
new
TextFileEditorModelCache
();
le
t
m1
=
new
EditorModel
();
le
t
m2
=
new
EditorModel
();
le
t
m3
=
new
EditorModel
();
cons
t
m1
=
new
EditorModel
();
cons
t
m2
=
new
EditorModel
();
cons
t
m3
=
new
EditorModel
();
cache
.
add
(
URI
.
file
(
'
/test.html
'
),
<
any
>
m1
);
cache
.
add
(
URI
.
file
(
'
/some/other.html
'
),
<
any
>
m2
);
...
...
src/vs/workbench/parts/files/test/browser/viewModel.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -26,7 +26,7 @@ function toResource(path) {
suite
(
'
Files - View Model
'
,
()
=>
{
test
(
'
Properties
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
cons
t
d
=
new
Date
().
getTime
();
let
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
true
,
8096
,
d
);
assert
.
strictEqual
(
s
.
isDirectoryResolved
,
false
);
...
...
@@ -42,12 +42,12 @@ suite('Files - View Model', () => {
});
test
(
'
Add and Remove Child, check for hasChild
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
le
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
false
,
8096
,
d
);
cons
t
d
=
new
Date
().
getTime
();
cons
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
false
,
8096
,
d
);
le
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
le
t
child2
=
createStat
(
'
/path/to/stat/bar.html
'
,
'
bar
'
,
false
,
false
,
8096
,
d
);
le
t
child4
=
createStat
(
'
/otherpath/to/other/otherbar.html
'
,
'
otherbar.html
'
,
false
,
false
,
8096
,
d
);
cons
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
cons
t
child2
=
createStat
(
'
/path/to/stat/bar.html
'
,
'
bar
'
,
false
,
false
,
8096
,
d
);
cons
t
child4
=
createStat
(
'
/otherpath/to/other/otherbar.html
'
,
'
otherbar.html
'
,
false
,
false
,
8096
,
d
);
assert
(
!
s
.
hasChild
(
child1
.
name
));
assert
(
!
s
.
hasChild
(
child2
.
name
));
...
...
@@ -74,12 +74,12 @@ suite('Files - View Model', () => {
});
test
(
'
Move
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
cons
t
d
=
new
Date
().
getTime
();
le
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
le
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
le
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
le
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
false
,
false
,
8096
,
d
);
cons
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
cons
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
cons
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
cons
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
false
,
false
,
8096
,
d
);
s1
.
addChild
(
s2
);
s2
.
addChild
(
s3
);
...
...
@@ -96,9 +96,9 @@ suite('Files - View Model', () => {
assert
.
strictEqual
(
s4
.
resource
.
fsPath
,
toResource
(
'
/
'
+
s4
.
name
).
fsPath
);
// Move a subtree with children
le
t
leaf
=
createStat
(
'
/leaf
'
,
'
leaf
'
,
true
,
false
,
8096
,
d
);
le
t
leafC1
=
createStat
(
'
/leaf/folder
'
,
'
folder
'
,
true
,
false
,
8096
,
d
);
le
t
leafCC2
=
createStat
(
'
/leaf/folder/index.html
'
,
'
index.html
'
,
true
,
false
,
8096
,
d
);
cons
t
leaf
=
createStat
(
'
/leaf
'
,
'
leaf
'
,
true
,
false
,
8096
,
d
);
cons
t
leafC1
=
createStat
(
'
/leaf/folder
'
,
'
folder
'
,
true
,
false
,
8096
,
d
);
cons
t
leafCC2
=
createStat
(
'
/leaf/folder/index.html
'
,
'
index.html
'
,
true
,
false
,
8096
,
d
);
leaf
.
addChild
(
leafC1
);
leafC1
.
addChild
(
leafCC2
);
...
...
@@ -110,18 +110,18 @@ suite('Files - View Model', () => {
});
test
(
'
Rename
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
cons
t
d
=
new
Date
().
getTime
();
le
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
le
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
le
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
le
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
cons
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
cons
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
cons
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
cons
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
s1
.
addChild
(
s2
);
s2
.
addChild
(
s3
);
s3
.
addChild
(
s4
);
le
t
s2renamed
=
createStat
(
'
/otherpath
'
,
'
otherpath
'
,
true
,
true
,
8096
,
d
);
cons
t
s2renamed
=
createStat
(
'
/otherpath
'
,
'
otherpath
'
,
true
,
true
,
8096
,
d
);
s2
.
rename
(
s2renamed
);
// Verify the paths have changed including children
...
...
@@ -130,22 +130,22 @@ suite('Files - View Model', () => {
assert
.
strictEqual
(
s3
.
resource
.
fsPath
,
toResource
(
'
/otherpath/to
'
).
fsPath
);
assert
.
strictEqual
(
s4
.
resource
.
fsPath
,
toResource
(
'
/otherpath/to/stat
'
).
fsPath
);
le
t
s4renamed
=
createStat
(
'
/otherpath/to/statother.js
'
,
'
statother.js
'
,
true
,
false
,
8096
,
d
);
cons
t
s4renamed
=
createStat
(
'
/otherpath/to/statother.js
'
,
'
statother.js
'
,
true
,
false
,
8096
,
d
);
s4
.
rename
(
s4renamed
);
assert
.
strictEqual
(
s4
.
name
,
s4renamed
.
name
);
assert
.
strictEqual
(
s4
.
resource
.
fsPath
,
s4renamed
.
resource
.
fsPath
);
});
test
(
'
Find
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
cons
t
d
=
new
Date
().
getTime
();
le
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
le
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
le
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
le
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
cons
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
cons
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
cons
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
cons
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
le
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
le
t
child2
=
createStat
(
'
/path/to/stat/foo/bar.html
'
,
'
bar.html
'
,
false
,
false
,
8096
,
d
);
cons
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
cons
t
child2
=
createStat
(
'
/path/to/stat/foo/bar.html
'
,
'
bar.html
'
,
false
,
false
,
8096
,
d
);
s1
.
addChild
(
s2
);
s2
.
addChild
(
s3
);
...
...
@@ -165,15 +165,15 @@ suite('Files - View Model', () => {
});
test
(
'
Find with mixed case
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
cons
t
d
=
new
Date
().
getTime
();
le
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
le
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
le
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
le
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
cons
t
s1
=
createStat
(
'
/
'
,
'
/
'
,
true
,
false
,
8096
,
d
);
cons
t
s2
=
createStat
(
'
/path
'
,
'
path
'
,
true
,
false
,
8096
,
d
);
cons
t
s3
=
createStat
(
'
/path/to
'
,
'
to
'
,
true
,
false
,
8096
,
d
);
cons
t
s4
=
createStat
(
'
/path/to/stat
'
,
'
stat
'
,
true
,
false
,
8096
,
d
);
le
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
le
t
child2
=
createStat
(
'
/path/to/stat/foo/bar.html
'
,
'
bar.html
'
,
false
,
false
,
8096
,
d
);
cons
t
child1
=
createStat
(
'
/path/to/stat/foo
'
,
'
foo
'
,
true
,
false
,
8096
,
d
);
cons
t
child2
=
createStat
(
'
/path/to/stat/foo/bar.html
'
,
'
bar.html
'
,
false
,
false
,
8096
,
d
);
s1
.
addChild
(
s2
);
s2
.
addChild
(
s3
);
...
...
@@ -191,9 +191,9 @@ suite('Files - View Model', () => {
});
test
(
'
Validate File Name (For Create)
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
le
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
true
,
8096
,
d
);
le
t
sChild
=
createStat
(
'
/path/to/stat/alles.klar
'
,
'
alles.klar
'
,
true
,
true
,
8096
,
d
);
cons
t
d
=
new
Date
().
getTime
();
cons
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
true
,
8096
,
d
);
cons
t
sChild
=
createStat
(
'
/path/to/stat/alles.klar
'
,
'
alles.klar
'
,
true
,
true
,
8096
,
d
);
s
.
addChild
(
sChild
);
assert
(
validateFileName
(
s
,
null
)
!==
null
);
...
...
@@ -218,9 +218,9 @@ suite('Files - View Model', () => {
});
test
(
'
Validate File Name (For Rename)
'
,
function
()
{
le
t
d
=
new
Date
().
getTime
();
le
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
true
,
8096
,
d
);
le
t
sChild
=
createStat
(
'
/path/to/stat/alles.klar
'
,
'
alles.klar
'
,
true
,
true
,
8096
,
d
);
cons
t
d
=
new
Date
().
getTime
();
cons
t
s
=
createStat
(
'
/path/to/stat
'
,
'
sName
'
,
true
,
true
,
8096
,
d
);
cons
t
sChild
=
createStat
(
'
/path/to/stat/alles.klar
'
,
'
alles.klar
'
,
true
,
true
,
8096
,
d
);
s
.
addChild
(
sChild
);
assert
(
validateFileName
(
s
,
'
alles.klar
'
)
!==
null
);
...
...
@@ -239,10 +239,10 @@ suite('Files - View Model', () => {
});
test
(
'
File Change Event (with stats)
'
,
function
()
{
le
t
d
=
new
Date
().
toUTCString
();
le
t
s1
=
new
FileStat
(
toResource
(
'
/path/to/sName
'
),
false
,
false
,
'
sName
'
,
void
0
,
8096
/* Size */
,
d
);
le
t
s2
=
new
FileStat
(
toResource
(
'
/path/to/sName
'
),
false
,
false
,
'
sName
'
,
void
0
,
16000
/* Size */
,
d
);
le
t
s3
=
new
FileStat
(
toResource
(
'
/path/to/sNameMoved
'
),
false
,
false
,
'
sNameMoved
'
,
void
0
,
8096
/* Size */
,
d
);
cons
t
d
=
new
Date
().
toUTCString
();
cons
t
s1
=
new
FileStat
(
toResource
(
'
/path/to/sName
'
),
false
,
false
,
'
sName
'
,
void
0
,
8096
/* Size */
,
d
);
cons
t
s2
=
new
FileStat
(
toResource
(
'
/path/to/sName
'
),
false
,
false
,
'
sName
'
,
void
0
,
16000
/* Size */
,
d
);
cons
t
s3
=
new
FileStat
(
toResource
(
'
/path/to/sNameMoved
'
),
false
,
false
,
'
sNameMoved
'
,
void
0
,
8096
/* Size */
,
d
);
// Got Added
let
event
=
new
LocalFileChangeEvent
(
null
,
s1
);
...
...
@@ -281,10 +281,10 @@ suite('Files - View Model', () => {
});
test
(
'
Merge Local with Disk
'
,
function
()
{
le
t
d
=
new
Date
().
toUTCString
();
cons
t
d
=
new
Date
().
toUTCString
();
le
t
merge1
=
new
FileStat
(
URI
.
file
(
join
(
'
C:
\\
'
,
'
/path/to
'
)),
true
,
false
,
'
to
'
,
void
0
,
8096
,
d
);
le
t
merge2
=
new
FileStat
(
URI
.
file
(
join
(
'
C:
\\
'
,
'
/path/to
'
)),
true
,
false
,
'
to
'
,
void
0
,
16000
,
new
Date
(
0
).
toUTCString
());
cons
t
merge1
=
new
FileStat
(
URI
.
file
(
join
(
'
C:
\\
'
,
'
/path/to
'
)),
true
,
false
,
'
to
'
,
void
0
,
8096
,
d
);
cons
t
merge2
=
new
FileStat
(
URI
.
file
(
join
(
'
C:
\\
'
,
'
/path/to
'
)),
true
,
false
,
'
to
'
,
void
0
,
16000
,
new
Date
(
0
).
toUTCString
());
// Merge Properties
FileStat
.
mergeLocalWithDisk
(
merge2
,
merge1
);
...
...
@@ -306,7 +306,7 @@ suite('Files - View Model', () => {
assert
.
deepEqual
(
merge1
.
children
[
0
].
parent
,
merge1
,
'
Check parent
'
);
// Verify that merge does not replace existing children, but updates properties in that case
le
t
existingChild
=
merge1
.
children
[
0
];
cons
t
existingChild
=
merge1
.
children
[
0
];
FileStat
.
mergeLocalWithDisk
(
merge2
,
merge1
);
assert
.
ok
(
existingChild
===
merge1
.
children
[
0
]);
});
...
...
src/vs/workbench/test/browser/services.test.ts
浏览文件 @
9b0e1d35
...
...
@@ -7,39 +7,25 @@
import
*
as
assert
from
'
assert
'
;
import
{
IAction
,
IActionItem
}
from
'
vs/base/common/actions
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
{
Promise
,
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
IEditorControl
}
from
'
vs/platform/editor/common/editor
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ILifecycleService
,
NullLifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
PartService
=
require
(
'
vs/workbench/services/part/common/partService
'
);
import
{
BaseEditor
}
from
'
vs/workbench/browser/parts/editor/baseEditor
'
;
import
{
EditorInput
,
EditorOptions
,
TextEditorOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
StringEditorInput
}
from
'
vs/workbench/common/editor/stringEditorInput
'
;
import
{
StringEditorModel
}
from
'
vs/workbench/common/editor/stringEditorModel
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/parts/files/common/editors/textFileEditorModel
'
;
import
{
ITextFileService
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
createMockModelService
,
TestTextFileService
,
TestEventService
,
TestPartService
,
TestStorageService
,
TestConfigurationService
,
TestContextService
,
TestWorkspace
,
TestEditorService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
textFileServiceInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
Viewlet
}
from
'
vs/workbench/browser/viewlet
'
;
import
{
IPanel
}
from
'
vs/workbench/common/panel
'
;
import
{
ITelemetryService
,
NullTelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IUntitledEditorService
,
UntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
WorkbenchProgressService
,
ScopedService
}
from
'
vs/workbench/services/progress/browser/progressService
'
;
import
{
DelegatingWorkbenchEditorService
,
WorkbenchEditorService
,
IEditorPart
}
from
'
vs/workbench/services/editor/browser/editorService
'
;
import
{
IViewletService
}
from
'
vs/workbench/services/viewlet/common/viewletService
'
;
import
{
IPanelService
}
from
'
vs/workbench/services/panel/common/panelService
'
;
import
{
IViewlet
}
from
'
vs/workbench/common/viewlet
'
;
import
{
Position
,
Direction
,
IEditor
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
let
activeViewlet
:
Viewlet
=
<
any
>
{};
...
...
@@ -284,73 +270,7 @@ class TestProgressBar {
suite
(
'
Workbench UI Services
'
,
()
=>
{
test
(
'
WorkbenchEditorService
'
,
function
()
{
const
TestFileService
=
{
resolveContent
:
function
(
resource
)
{
return
TPromise
.
as
({
resource
:
resource
,
value
:
'
Hello Html
'
,
etag
:
'
index.txt
'
,
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
paths
.
basename
(
resource
.
fsPath
)
});
},
resolveStreamContent
:
function
(
resource
)
{
return
TPromise
.
as
({
resource
:
resource
,
value
:
{
on
:
(
event
:
string
,
callback
:
Function
):
void
=>
{
if
(
event
===
'
data
'
)
{
callback
(
'
Hello Html
'
);
}
if
(
event
===
'
end
'
)
{
callback
();
}
}
},
etag
:
'
index.txt
'
,
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
paths
.
basename
(
resource
.
fsPath
)
});
},
updateContent
:
function
(
res
)
{
return
TPromise
.
timeout
(
1
).
then
(()
=>
{
return
{
resource
:
res
,
etag
:
'
index.txt
'
,
mime
:
'
text/plain
'
,
encoding
:
'
utf8
'
,
mtime
:
new
Date
().
getTime
(),
name
:
paths
.
basename
(
res
.
fsPath
)
};
});
}
};
let
editorService
=
new
TestEditorService
(
function
()
{
});
let
eventService
=
new
TestEventService
();
let
contextService
=
new
TestContextService
(
TestWorkspace
);
let
instantiationService
=
new
TestInstantiationService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
ITelemetryService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
IUntitledEditorService
,
instantiationService
.
createInstance
(
UntitledEditorService
));
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IWorkbenchEditorService
,
editorService
);
instantiationService
.
stub
(
PartService
.
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
IModeService
);
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IFileService
,
<
any
>
TestFileService
);
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
instantiationService
=
textFileServiceInstantiationService
();
let
activeInput
:
EditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/something.js
'
),
'
text/javascript
'
,
void
0
);
...
...
@@ -413,22 +333,7 @@ suite('Workbench UI Services', () => {
});
test
(
'
DelegatingWorkbenchEditorService
'
,
function
()
{
let
editorService
=
new
TestEditorService
(
function
()
{
});
let
contextService
=
new
TestContextService
(
TestWorkspace
);
let
eventService
=
new
TestEventService
();
let
telemetryService
=
NullTelemetryService
;
let
instantiationService
=
new
TestInstantiationService
();
instantiationService
.
stub
(
IEventService
,
eventService
);
instantiationService
.
stub
(
ITelemetryService
,
telemetryService
);
instantiationService
.
stub
(
IStorageService
,
new
TestStorageService
());
instantiationService
.
stub
(
IUntitledEditorService
,
instantiationService
.
createInstance
(
UntitledEditorService
));
instantiationService
.
stub
(
IWorkbenchEditorService
,
editorService
);
instantiationService
.
stub
(
PartService
.
IPartService
,
new
TestPartService
());
instantiationService
.
stub
(
ILifecycleService
,
NullLifecycleService
);
instantiationService
.
stub
(
IWorkspaceContextService
,
contextService
);
instantiationService
.
stub
(
IConfigurationService
,
new
TestConfigurationService
());
instantiationService
.
stub
(
ITextFileService
,
<
ITextFileService
>
instantiationService
.
createInstance
(
<
any
>
TestTextFileService
));
let
instantiationService
=
textFileServiceInstantiationService
();
let
activeInput
:
EditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
(
'
/something.js
'
),
'
text/javascript
'
,
void
0
);
let
testEditorPart
=
new
TestEditorPart
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录