Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
5dc80043
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,发现更多精彩内容 >>
未验证
提交
5dc80043
编写于
6月 29, 2021
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more editor service tests
上级
8f7851d0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
175 addition
and
19 deletion
+175
-19
src/vs/workbench/services/editor/test/browser/editorService.test.ts
...kbench/services/editor/test/browser/editorService.test.ts
+154
-17
src/vs/workbench/test/browser/workbenchTestServices.ts
src/vs/workbench/test/browser/workbenchTestServices.ts
+21
-2
未找到文件。
src/vs/workbench/services/editor/test/browser/editorService.test.ts
浏览文件 @
5dc80043
...
...
@@ -8,7 +8,7 @@ import { EditorActivation, EditorOverride, IResourceEditorInput } from 'vs/platf
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
DEFAULT_EDITOR_ASSOCIATION
,
EditorsOrder
,
GroupIdentifier
,
IEditorInputWithOptions
,
IEditorPane
,
IResourceDiffEditorInput
,
isEditorInputWithOptions
,
isResourceDiffEditorInput
,
isUntitledResourceEditorInput
,
IUntitledTextResourceEditorInput
,
IUntypedEditorInput
,
UntypedEditorContext
}
from
'
vs/workbench/common/editor
'
;
import
{
workbenchInstantiationService
,
TestServiceAccessor
,
registerTestEditor
,
TestFileEditorInput
,
ITestInstantiationService
,
registerTestResourceEditor
,
registerTestSideBySideEditor
,
createEditorPart
,
registerTestFileEditor
}
from
'
vs/workbench/test/browser/workbenchTestServices
'
;
import
{
workbenchInstantiationService
,
TestServiceAccessor
,
registerTestEditor
,
TestFileEditorInput
,
ITestInstantiationService
,
registerTestResourceEditor
,
registerTestSideBySideEditor
,
createEditorPart
,
registerTestFileEditor
,
TestEditorWithOptions
,
TestTextFileEditor
}
from
'
vs/workbench/test/browser/workbenchTestServices
'
;
import
{
TextResourceEditorInput
}
from
'
vs/workbench/common/editor/textResourceEditorInput
'
;
import
{
EditorService
}
from
'
vs/workbench/services/editor/browser/editorService
'
;
import
{
IEditorGroup
,
IEditorGroupsService
,
GroupDirection
,
GroupsArrangement
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
...
...
@@ -71,7 +71,7 @@ suite('EditorService', () => {
return
[
part
,
editorService
,
instantiationService
.
createInstance
(
TestServiceAccessor
)];
}
test
(
'
openEditor
'
,
async
()
=>
{
test
(
'
basics
'
,
async
()
=>
{
const
[,
service
]
=
await
createEditorService
();
let
input
=
new
TestFileEditorInput
(
URI
.
parse
(
'
my://resource-basics
'
),
TEST_EDITOR_INPUT_ID
);
...
...
@@ -178,11 +178,11 @@ suite('EditorService', () => {
didCloseEditorListener
.
dispose
();
});
test
(
'
openEditor
- override handling
'
,
()
=>
{
test
(
'
openEditor
()
'
,
()
=>
{
return
testOpenEditors
(
false
);
});
test
(
'
openEditors
- override handling
'
,
()
=>
{
test
(
'
openEditors
()
'
,
()
=>
{
return
testOpenEditors
(
true
);
});
...
...
@@ -265,10 +265,11 @@ suite('EditorService', () => {
{
let
untypedEditor
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file.editor-service-override-tests
'
)
};
let
pane
=
await
openEditor
(
untypedEditor
);
let
typedEditor
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
input
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
pane
.
input
.
resource
.
toString
(),
untypedEditor
.
resource
.
toString
());
assert
.
ok
(
typedEditor
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedEditor
.
resource
.
toString
(),
untypedEditor
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
1
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
...
...
@@ -278,6 +279,31 @@ suite('EditorService', () => {
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
// opening the same editor should not create
// a new editor input
pane
=
await
openEditor
(
untypedEditor
);
assert
.
strictEqual
(
pane
?.
input
,
typedEditor
);
// replaceEditors should work too
let
untypedEditorReplacement
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file-replaced.editor-service-override-tests
'
)
};
await
service
.
replaceEditors
([{
editor
:
typedEditor
,
replacement
:
untypedEditorReplacement
}],
rootGroup
);
typedEditor
=
rootGroup
.
activeEditor
!
;
assert
.
ok
(
typedEditor
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedEditor
.
resource
.
toString
(),
untypedEditorReplacement
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
3
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
assert
.
strictEqual
(
diffEditorFactoryCalled
,
0
);
assert
.
strictEqual
(
lastEditorFactoryEditor
,
untypedEditorReplacement
);
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
await
resetTestState
();
}
...
...
@@ -285,10 +311,11 @@ suite('EditorService', () => {
{
let
untypedEditor
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file.editor-service-override-tests
'
),
options
:
{
override
:
EditorOverride
.
DISABLED
}
};
let
pane
=
await
openEditor
(
untypedEditor
);
let
typedEditor
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
input
instanceof
FileEditorInput
);
assert
.
strictEqual
(
pane
.
input
.
resource
.
toString
(),
untypedEditor
.
resource
.
toString
());
assert
.
ok
(
typedEditor
instanceof
FileEditorInput
);
assert
.
strictEqual
(
typedEditor
.
resource
.
toString
(),
untypedEditor
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
0
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
...
...
@@ -298,6 +325,11 @@ suite('EditorService', () => {
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
// opening the same editor should not create
// a new editor input
pane
=
await
openEditor
(
untypedEditor
);
assert
.
strictEqual
(
pane
?.
input
,
typedEditor
);
await
resetTestState
();
}
...
...
@@ -458,10 +490,11 @@ suite('EditorService', () => {
{
let
typedEditor
=
new
TestFileEditorInput
(
URI
.
file
(
'
file.editor-service-override-tests
'
),
TEST_EDITOR_INPUT_ID
);
let
pane
=
await
openEditor
({
editor
:
typedEditor
});
let
typedInput
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
i
nput
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
pane
.
i
nput
.
resource
.
toString
(),
typedEditor
.
resource
.
toString
());
assert
.
ok
(
typedI
nput
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedI
nput
.
resource
.
toString
(),
typedEditor
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
1
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
...
...
@@ -471,6 +504,31 @@ suite('EditorService', () => {
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
// opening the same editor should not create
// a new editor input
pane
=
await
openEditor
(
typedEditor
);
assert
.
strictEqual
(
pane
?.
input
,
typedInput
);
// replaceEditors should work too
let
typedEditorReplacement
=
new
TestFileEditorInput
(
URI
.
file
(
'
file-replaced.editor-service-override-tests
'
),
TEST_EDITOR_INPUT_ID
);
await
service
.
replaceEditors
([{
editor
:
typedEditor
,
replacement
:
typedEditorReplacement
}],
rootGroup
);
typedInput
=
rootGroup
.
activeEditor
!
;
assert
.
ok
(
typedInput
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedInput
.
resource
.
toString
(),
typedEditorReplacement
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
3
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
assert
.
strictEqual
(
diffEditorFactoryCalled
,
0
);
assert
.
strictEqual
((
lastEditorFactoryEditor
as
IResourceEditorInput
).
resource
.
toString
(),
typedInput
.
resource
.
toString
());
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
await
resetTestState
();
}
...
...
@@ -478,10 +536,11 @@ suite('EditorService', () => {
{
let
typedEditor
=
new
TestFileEditorInput
(
URI
.
file
(
'
file.editor-service-override-tests
'
),
TEST_EDITOR_INPUT_ID
);
let
pane
=
await
openEditor
({
editor
:
typedEditor
,
options
:
{
override
:
EditorOverride
.
DISABLED
}
});
let
typedInput
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
i
nput
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
pane
.
i
nput
.
resource
.
toString
(),
typedEditor
.
resource
.
toString
());
assert
.
ok
(
typedI
nput
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedI
nput
.
resource
.
toString
(),
typedEditor
.
resource
.
toString
());
assert
.
strictEqual
(
editorFactoryCalled
,
0
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
...
...
@@ -491,6 +550,11 @@ suite('EditorService', () => {
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
// opening the same editor should not create
// a new editor input
pane
=
await
openEditor
(
typedEditor
);
assert
.
strictEqual
(
pane
?.
input
,
typedInput
);
await
resetTestState
();
}
...
...
@@ -692,10 +756,11 @@ suite('EditorService', () => {
{
let
untypedEditor
:
IUntitledTextResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file-original.editor-service-override-tests
'
).
with
({
scheme
:
'
untitled
'
})
};
let
pane
=
await
openEditor
(
untypedEditor
);
let
typedEditor
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
input
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
pane
.
input
.
resource
.
scheme
,
'
untitled
'
);
assert
.
ok
(
typedEditor
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
typedEditor
.
resource
.
scheme
,
'
untitled
'
);
assert
.
strictEqual
(
editorFactoryCalled
,
0
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
1
);
...
...
@@ -705,6 +770,11 @@ suite('EditorService', () => {
assert
.
strictEqual
(
lastUntitledEditorFactoryEditor
,
untypedEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
// opening the same editor should not create
// a new editor input
pane
=
await
openEditor
(
untypedEditor
);
assert
.
strictEqual
(
pane
?.
input
,
typedEditor
);
await
resetTestState
();
}
...
...
@@ -736,11 +806,16 @@ suite('EditorService', () => {
{
// untyped diff editor, no options, no group
{
let
untypedEditor
:
IResourceDiffEditorInput
=
{
originalInput
:
{
resource
:
URI
.
file
(
'
file-original.editor-service-override-tests
'
)
},
modifiedInput
:
{
resource
:
URI
.
file
(
'
file-modified.editor-service-override-tests
'
)
},
options
:
{
override
:
'
editorServiceOverrideTests
'
}
};
let
untypedEditor
:
IResourceDiffEditorInput
=
{
originalInput
:
{
resource
:
URI
.
file
(
'
file-original.editor-service-override-tests
'
)
},
modifiedInput
:
{
resource
:
URI
.
file
(
'
file-modified.editor-service-override-tests
'
)
},
options
:
{
override
:
'
editorServiceOverrideTests
'
}
};
let
pane
=
await
openEditor
(
untypedEditor
);
let
typedEditor
=
pane
?.
input
;
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
ok
(
pane
.
input
instanceof
TestFileEditorInput
);
assert
.
ok
(
typedEditor
instanceof
TestFileEditorInput
);
assert
.
strictEqual
(
editorFactoryCalled
,
0
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
...
...
@@ -755,7 +830,11 @@ suite('EditorService', () => {
// untyped diff editor, no options, SIDE_GROUP
{
let
untypedEditor
:
IResourceDiffEditorInput
=
{
originalInput
:
{
resource
:
URI
.
file
(
'
file-original.editor-service-override-tests
'
)
},
modifiedInput
:
{
resource
:
URI
.
file
(
'
file-modified.editor-service-override-tests
'
)
},
options
:
{
override
:
'
editorServiceOverrideTests
'
}
};
let
untypedEditor
:
IResourceDiffEditorInput
=
{
originalInput
:
{
resource
:
URI
.
file
(
'
file-original.editor-service-override-tests
'
)
},
modifiedInput
:
{
resource
:
URI
.
file
(
'
file-modified.editor-service-override-tests
'
)
},
options
:
{
override
:
'
editorServiceOverrideTests
'
}
};
let
pane
=
await
openEditor
(
untypedEditor
,
SIDE_GROUP
);
assert
.
strictEqual
(
accessor
.
editorGroupService
.
groups
.
length
,
2
);
...
...
@@ -893,8 +972,66 @@ suite('EditorService', () => {
await
resetTestState
();
}
}
// openEditors with >1 editor
if
(
useOpenEditors
)
{
// mix of untyped and typed editors
{
let
untypedEditor1
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file1.editor-service-override-tests
'
)
};
let
untypedEditor2
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file2.editor-service-override-tests
'
),
options
:
{
override
:
EditorOverride
.
DISABLED
}
};
let
untypedEditor3
:
IEditorInputWithOptions
=
{
editor
:
new
TestFileEditorInput
(
URI
.
file
(
'
file3.editor-service-override-tests
'
),
TEST_EDITOR_INPUT_ID
)
};
let
untypedEditor4
:
IEditorInputWithOptions
=
{
editor
:
new
TestFileEditorInput
(
URI
.
file
(
'
file4.editor-service-override-tests
'
),
TEST_EDITOR_INPUT_ID
),
options
:
{
override
:
EditorOverride
.
DISABLED
}
};
let
untypedEditor5
:
IResourceEditorInput
=
{
resource
:
URI
.
file
(
'
file5.editor-service-override-tests
'
)
};
let
pane
=
(
await
service
.
openEditors
([
untypedEditor1
,
untypedEditor2
,
untypedEditor3
,
untypedEditor4
,
untypedEditor5
]))[
0
];
assert
.
strictEqual
(
pane
?.
group
,
rootGroup
);
assert
.
strictEqual
(
pane
?.
group
.
count
,
5
);
assert
.
strictEqual
(
editorFactoryCalled
,
3
);
assert
.
strictEqual
(
untitledEditorFactoryCalled
,
0
);
assert
.
strictEqual
(
diffEditorFactoryCalled
,
0
);
assert
.
ok
(
lastEditorFactoryEditor
);
assert
.
ok
(
!
lastUntitledEditorFactoryEditor
);
assert
.
ok
(
!
lastDiffEditorFactoryEditor
);
await
resetTestState
();
}
}
}
test
(
'
openEditor() applies options if editor already opened
'
,
async
()
=>
{
disposables
.
add
(
registerTestFileEditor
());
const
[,
service
,
accessor
]
=
await
createEditorService
();
disposables
.
add
(
accessor
.
editorOverrideService
.
registerEditor
(
'
*.editor-service-override-tests
'
,
{
id
:
'
editorServiceOverrideTests
'
,
label
:
'
Label
'
,
priority
:
RegisteredEditorPriority
.
exclusive
},
{},
editor
=>
({
editor
:
new
TestFileEditorInput
(
editor
.
resource
,
'
editorServiceOverrideTests
'
)
})
));
// Typed editor
let
pane
=
await
service
.
openEditor
(
new
TestFileEditorInput
(
URI
.
parse
(
'
my://resource-openEditors
'
),
'
editorServiceOverrideTests
'
));
pane
=
await
service
.
openEditor
(
new
TestFileEditorInput
(
URI
.
parse
(
'
my://resource-openEditors
'
),
'
editorServiceOverrideTests
'
),
{
sticky
:
true
,
preserveFocus
:
true
});
assert
.
ok
(
pane
instanceof
TestEditorWithOptions
);
assert
.
strictEqual
(
pane
.
lastSetOptions
?.
sticky
,
true
);
assert
.
strictEqual
(
pane
.
lastSetOptions
?.
preserveFocus
,
true
);
await
pane
.
group
?.
closeAllEditors
();
// Untyped editor (without registered editor)
pane
=
await
service
.
openEditor
({
resource
:
URI
.
file
(
'
resource-openEditors
'
)
});
pane
=
await
service
.
openEditor
({
resource
:
URI
.
file
(
'
resource-openEditors
'
),
options
:
{
sticky
:
true
,
preserveFocus
:
true
}
});
assert
.
ok
(
pane
instanceof
TestTextFileEditor
);
assert
.
strictEqual
(
pane
.
lastSetOptions
?.
sticky
,
true
);
assert
.
strictEqual
(
pane
.
lastSetOptions
?.
preserveFocus
,
true
);
});
test
(
'
isOpen() with side by side editor
'
,
async
()
=>
{
const
[
part
,
service
]
=
await
createEditorService
();
...
...
src/vs/workbench/test/browser/workbenchTestServices.ts
浏览文件 @
5dc80043
...
...
@@ -18,7 +18,7 @@ import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configur
import
{
IWorkbenchLayoutService
,
Parts
,
Position
as
PartPosition
}
from
'
vs/workbench/services/layout/browser/layoutService
'
;
import
{
TextModelResolverService
}
from
'
vs/workbench/services/textmodelResolver/common/textModelResolverService
'
;
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
IEditorOptions
,
IResourceEditorInput
,
IEditorModel
,
IResourceEditorInputIdentifier
,
ITextResourceEditorInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorOptions
,
IResourceEditorInput
,
IEditorModel
,
IResourceEditorInputIdentifier
,
ITextResourceEditorInput
,
ITextEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IUntitledTextEditorService
,
UntitledTextEditorService
}
from
'
vs/workbench/services/untitled/common/untitledTextEditorService
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ILifecycleService
,
BeforeShutdownEvent
,
ShutdownReason
,
StartupKind
,
LifecyclePhase
,
WillShutdownEvent
}
from
'
vs/workbench/services/lifecycle/common/lifecycle
'
;
...
...
@@ -168,6 +168,14 @@ export class TestTextResourceEditor extends TextResourceEditor {
export
class
TestTextFileEditor
extends
TextFileEditor
{
lastSetOptions
:
ITextEditorOptions
|
undefined
=
undefined
;
override
setOptions
(
options
:
ITextEditorOptions
|
undefined
):
void
{
this
.
lastSetOptions
=
options
;
super
.
setOptions
(
options
);
}
protected
override
createEditorControl
(
parent
:
HTMLElement
,
configuration
:
any
):
IEditor
{
return
this
.
instantiationService
.
createInstance
(
TestCodeEditor
,
parent
,
configuration
,
{});
}
...
...
@@ -1310,8 +1318,19 @@ export class TestEditorInput extends EditorInput {
}
}
export
abstract
class
TestEditorWithOptions
extends
EditorPane
{
lastSetOptions
:
ITextEditorOptions
|
undefined
=
undefined
;
override
setOptions
(
options
:
ITextEditorOptions
|
undefined
):
void
{
this
.
lastSetOptions
=
options
;
super
.
setOptions
(
options
);
}
}
export
function
registerTestEditor
(
id
:
string
,
inputs
:
SyncDescriptor
<
EditorInput
>
[],
serializerInputId
?:
string
):
IDisposable
{
class
TestEditor
extends
EditorPane
{
class
TestEditor
extends
TestEditorWithOptions
{
private
_scopedContextKeyService
:
IContextKeyService
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录