Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
8cfe1716
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
8cfe1716
编写于
12月 04, 2017
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use element as handle when element is a string identifier
上级
5a89b5c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
138 addition
and
80 deletion
+138
-80
src/vs/workbench/api/node/extHostTreeViews.ts
src/vs/workbench/api/node/extHostTreeViews.ts
+3
-3
src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts
...kbench/test/electron-browser/api/extHostTreeViews.test.ts
+135
-77
未找到文件。
src/vs/workbench/api/node/extHostTreeViews.ts
浏览文件 @
8cfe1716
...
...
@@ -156,16 +156,16 @@ class ExtHostTreeView<T> extends Disposable {
private
resolveElement
(
element
:
T
,
index
:
number
,
parentHandle
?:
TreeItemHandle
):
TPromise
<
ITreeItem
>
{
return
asWinJsPromise
(()
=>
this
.
dataProvider
.
getTreeItem
(
element
))
.
then
(
extTreeItem
=>
this
.
massageTreeItem
(
extTreeItem
,
index
,
parentHandle
));
.
then
(
extTreeItem
=>
this
.
massageTreeItem
(
e
lement
,
e
xtTreeItem
,
index
,
parentHandle
));
}
private
massageTreeItem
(
extensionTreeItem
:
vscode
.
TreeItem
,
index
:
number
,
parentHandle
:
TreeItemHandle
):
ITreeItem
{
private
massageTreeItem
(
e
lement
:
T
,
e
xtensionTreeItem
:
vscode
.
TreeItem
,
index
:
number
,
parentHandle
:
TreeItemHandle
):
ITreeItem
{
if
(
!
extensionTreeItem
)
{
return
null
;
}
const
icon
=
this
.
getLightIconPath
(
extensionTreeItem
);
const
label
=
extensionTreeItem
.
label
;
const
handle
=
this
.
generateHandle
(
label
,
index
,
parentHandle
);
const
handle
=
t
ypeof
element
===
'
string
'
?
element
:
t
his
.
generateHandle
(
label
,
index
,
parentHandle
);
return
{
handle
,
parentHandle
,
...
...
src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts
浏览文件 @
8cfe1716
...
...
@@ -22,7 +22,6 @@ import { TreeItemCollapsibleState, ITreeItem } from 'vs/workbench/common/views';
suite
(
'
ExtHostTreeView
'
,
function
()
{
class
RecordingShape
extends
mock
<
MainThreadTreeViewsShape
>
()
{
onRefresh
=
new
Emitter
<
{
[
treeItemHandle
:
string
]:
ITreeItem
}
>
();
...
...
@@ -37,9 +36,9 @@ suite('ExtHostTreeView', function () {
let
testObject
:
ExtHostTreeViews
;
let
target
:
RecordingShape
;
let
onDidChangeTree
Data
:
Emitter
<
string
>
;
let
tree
;
let
label
s
;
let
onDidChangeTree
Node
:
Emitter
<
{
key
:
string
}
>
;
let
onDidChangeTreeKey
:
Emitter
<
string
>
;
let
tree
,
labels
,
node
s
;
setup
(()
=>
{
tree
=
{
...
...
@@ -54,6 +53,7 @@ suite('ExtHostTreeView', function () {
};
labels
=
{};
nodes
=
{};
let
threadService
=
new
TestThreadService
();
// Use IInstantiationService to get typechecking when instantiating
...
...
@@ -66,38 +66,68 @@ suite('ExtHostTreeView', function () {
threadService
.
setTestInstance
(
MainContext
.
MainThreadCommands
,
inst
.
createInstance
(
MainThreadCommands
,
threadService
));
target
=
new
RecordingShape
();
testObject
=
new
ExtHostTreeViews
(
target
,
new
ExtHostCommands
(
threadService
,
new
ExtHostHeapService
()));
onDidChangeTreeData
=
new
Emitter
<
string
>
();
testObject
.
registerTreeDataProvider
(
'
testDataProvider
'
,
aTreeDataProvider
());
onDidChangeTreeNode
=
new
Emitter
<
{
key
:
string
}
>
();
onDidChangeTreeKey
=
new
Emitter
<
string
>
();
testObject
.
registerTreeDataProvider
(
'
testNodeTreeProvider
'
,
aNodeTreeDataProvider
());
testObject
.
registerTreeDataProvider
(
'
testStringTreeProvider
'
,
aStringTreeDataProvider
());
testObject
.
$getElements
(
'
test
Data
Provider
'
).
then
(
elements
=>
{
testObject
.
$getElements
(
'
test
NodeTree
Provider
'
).
then
(
elements
=>
{
for
(
const
element
of
elements
)
{
testObject
.
$getChildren
(
'
test
Data
Provider
'
,
element
.
handle
);
testObject
.
$getChildren
(
'
test
NodeTree
Provider
'
,
element
.
handle
);
}
});
});
test
(
'
construct tree
'
,
()
=>
{
return
testObject
.
$getElements
(
'
test
Data
Provider
'
)
test
(
'
construct
node
tree
'
,
()
=>
{
return
testObject
.
$getElements
(
'
test
NodeTree
Provider
'
)
.
then
(
elements
=>
{
const
actuals
=
elements
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
0/0:a
'
,
'
0/1:b
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
test
Data
Provider
'
,
'
0/0:a
'
)
testObject
.
$getChildren
(
'
test
NodeTree
Provider
'
,
'
0/0:a
'
)
.
then
(
children
=>
{
const
actuals
=
children
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
0/0:a/0:aa
'
,
'
0/0:a/1:ab
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
test
Data
Provider
'
,
'
0/0:a/0:aa
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
test
Data
Provider
'
,
'
0/0:a/1:ab
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
testObject
.
$getChildren
(
'
test
NodeTree
Provider
'
,
'
0/0:a/0:aa
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
test
NodeTree
Provider
'
,
'
0/0:a/1:ab
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
]);
}),
testObject
.
$getChildren
(
'
test
Data
Provider
'
,
'
0/1:b
'
)
testObject
.
$getChildren
(
'
test
NodeTree
Provider
'
,
'
0/1:b
'
)
.
then
(
children
=>
{
const
actuals
=
children
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
0/1:b/0:ba
'
,
'
0/1:b/1:bb
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
testDataProvider
'
,
'
0/1:b/0:ba
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
testDataProvider
'
,
'
0/1:b/1:bb
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
testObject
.
$getChildren
(
'
testNodeTreeProvider
'
,
'
0/1:b/0:ba
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
testNodeTreeProvider
'
,
'
0/1:b/1:bb
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
]);
})
]);
});
});
test
(
'
construct string tree
'
,
()
=>
{
return
testObject
.
$getElements
(
'
testStringTreeProvider
'
)
.
then
(
elements
=>
{
const
actuals
=
elements
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
a
'
,
'
b
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
a
'
)
.
then
(
children
=>
{
const
actuals
=
children
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
aa
'
,
'
ab
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
aa
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
ab
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
]);
}),
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
b
'
)
.
then
(
children
=>
{
const
actuals
=
children
.
map
(
e
=>
e
.
handle
);
assert
.
deepEqual
(
actuals
,
[
'
ba
'
,
'
bb
'
]);
return
TPromise
.
join
([
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
ba
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
)),
testObject
.
$getChildren
(
'
testStringTreeProvider
'
,
'
bb
'
).
then
(
children
=>
assert
.
equal
(
children
.
length
,
0
))
]);
})
]);
...
...
@@ -109,7 +139,7 @@ suite('ExtHostTreeView', function () {
assert
.
equal
(
undefined
,
actuals
);
done
();
});
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Node
.
fire
();
});
test
(
'
refresh a parent node
'
,
()
=>
{
...
...
@@ -122,7 +152,7 @@ suite('ExtHostTreeView', function () {
});
c
(
null
);
});
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
});
});
...
...
@@ -136,7 +166,7 @@ suite('ExtHostTreeView', function () {
});
done
();
});
onDidChangeTree
Data
.
fire
(
'
bb
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
bb
'
)
);
});
test
(
'
refresh parent and child node trigger refresh only on parent - scenario 1
'
,
function
(
done
)
{
...
...
@@ -153,9 +183,9 @@ suite('ExtHostTreeView', function () {
});
done
();
});
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
(
'
aa
'
);
onDidChangeTree
Data
.
fire
(
'
bb
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
aa
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
bb
'
)
);
});
test
(
'
refresh parent and child node trigger refresh only on parent - scenario 2
'
,
function
(
done
)
{
...
...
@@ -172,9 +202,9 @@ suite('ExtHostTreeView', function () {
});
done
();
});
onDidChangeTree
Data
.
fire
(
'
bb
'
);
onDidChangeTree
Data
.
fire
(
'
aa
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
bb
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
aa
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
});
test
(
'
refresh an element for label change
'
,
function
(
done
)
{
...
...
@@ -187,7 +217,7 @@ suite('ExtHostTreeView', function () {
});
done
();
});
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
});
test
(
'
refresh calls are throttled on roots
'
,
function
(
done
)
{
...
...
@@ -195,10 +225,10 @@ suite('ExtHostTreeView', function () {
assert
.
equal
(
undefined
,
actuals
);
done
();
});
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Node
.
fire
();
onDidChangeTree
Node
.
fire
();
onDidChangeTree
Node
.
fire
();
onDidChangeTree
Node
.
fire
();
});
test
(
'
refresh calls are throttled on elements
'
,
function
(
done
)
{
...
...
@@ -207,10 +237,10 @@ suite('ExtHostTreeView', function () {
done
();
});
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
});
test
(
'
refresh calls are throttled on unknown elements
'
,
function
(
done
)
{
...
...
@@ -219,10 +249,10 @@ suite('ExtHostTreeView', function () {
done
();
});
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
(
'
g
'
);
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
g
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
});
test
(
'
refresh calls are throttled on unknown elements and root
'
,
function
(
done
)
{
...
...
@@ -231,10 +261,10 @@ suite('ExtHostTreeView', function () {
done
();
});
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
(
'
g
'
);
onDidChangeTree
Data
.
fire
(
''
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
g
'
)
);
onDidChangeTree
Node
.
fire
(
);
});
test
(
'
refresh calls are throttled on elements and root
'
,
function
(
done
)
{
...
...
@@ -243,10 +273,10 @@ suite('ExtHostTreeView', function () {
done
();
});
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Data
.
fire
(
'
b
'
);
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Data
.
fire
(
'
a
'
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
onDidChangeTree
Node
.
fire
(
getNode
(
'
b
'
)
);
onDidChangeTree
Node
.
fire
();
onDidChangeTree
Node
.
fire
(
getNode
(
'
a
'
)
);
});
test
(
'
generate unique handles from labels by escaping them
'
,
()
=>
{
...
...
@@ -254,9 +284,9 @@ suite('ExtHostTreeView', function () {
'
a/0:b
'
:
{}
};
onDidChangeTree
Data
.
fire
();
onDidChangeTree
Node
.
fire
();
return
testObject
.
$getElements
(
'
test
Data
Provider
'
)
return
testObject
.
$getElements
(
'
test
NodeTree
Provider
'
)
.
then
(
elements
=>
{
assert
.
deepEqual
(
elements
.
map
(
e
=>
e
.
handle
),
[
'
0/0:a//0:b
'
]);
});
...
...
@@ -272,42 +302,70 @@ suite('ExtHostTreeView', function () {
return
result
;
}
function
aTreeDataProvider
():
TreeDataProvider
<
string
>
{
const
getTreeElement
=
(
element
)
=>
{
let
parent
=
tree
;
for
(
let
i
=
0
;
i
<
element
.
length
;
i
++
)
{
parent
=
parent
[
element
.
substring
(
0
,
i
+
1
)];
if
(
!
parent
)
{
return
null
;
}
}
return
parent
;
function
aNodeTreeDataProvider
():
TreeDataProvider
<
{
key
:
string
}
>
{
return
{
getChildren
:
(
element
:
{
key
:
string
}):
{
key
:
string
}[]
=>
{
return
getChildren
(
element
?
element
.
key
:
undefined
).
map
(
key
=>
getNode
(
key
));
},
getTreeItem
:
(
element
:
{
key
:
string
}):
TreeItem
=>
{
return
getTreeItem
(
element
.
key
);
},
onDidChangeTreeData
:
onDidChangeTreeNode
.
event
};
}
function
aStringTreeDataProvider
():
TreeDataProvider
<
string
>
{
return
{
getChildren
:
(
element
:
string
):
string
[]
=>
{
if
(
!
element
)
{
return
Object
.
keys
(
tree
);
}
let
treeElement
=
getTreeElement
(
element
);
if
(
treeElement
)
{
const
children
=
Object
.
keys
(
treeElement
);
const
collapsibleStateIndex
=
children
.
indexOf
(
'
collapsibleState
'
);
if
(
collapsibleStateIndex
!==
-
1
)
{
children
.
splice
(
collapsibleStateIndex
,
1
);
}
return
children
;
}
return
[];
return
getChildren
(
element
);
},
getTreeItem
:
(
element
:
string
):
TreeItem
=>
{
const
treeElement
=
getTreeElement
(
element
);
return
{
label
:
labels
[
element
]
||
element
,
collapsibleState
:
treeElement
?
treeElement
[
'
collapsibleState
'
]
:
TreeItemCollapsibleState
.
Collapsed
};
return
getTreeItem
(
element
);
},
onDidChangeTreeData
:
onDidChangeTreeData
.
event
onDidChangeTreeData
:
onDidChangeTreeKey
.
event
};
}
function
getTreeElement
(
element
):
any
{
let
parent
=
tree
;
for
(
let
i
=
0
;
i
<
element
.
length
;
i
++
)
{
parent
=
parent
[
element
.
substring
(
0
,
i
+
1
)];
if
(
!
parent
)
{
return
null
;
}
}
return
parent
;
}
function
getChildren
(
key
:
string
):
string
[]
{
if
(
!
key
)
{
return
Object
.
keys
(
tree
);
}
let
treeElement
=
getTreeElement
(
key
);
if
(
treeElement
)
{
const
children
=
Object
.
keys
(
treeElement
);
const
collapsibleStateIndex
=
children
.
indexOf
(
'
collapsibleState
'
);
if
(
collapsibleStateIndex
!==
-
1
)
{
children
.
splice
(
collapsibleStateIndex
,
1
);
}
return
children
;
}
return
[];
}
function
getTreeItem
(
key
:
string
):
TreeItem
{
const
treeElement
=
getTreeElement
(
key
);
return
{
label
:
labels
[
key
]
||
key
,
collapsibleState
:
treeElement
?
treeElement
[
'
collapsibleState
'
]
:
TreeItemCollapsibleState
.
Collapsed
};
}
function
getNode
(
key
:
string
):
{
key
:
string
}
{
if
(
!
nodes
[
key
])
{
nodes
[
key
]
=
{
key
};
}
return
nodes
[
key
];
}
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录