Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f345c948
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,体验更适合开发者的 AI 搜索 >>
提交
f345c948
编写于
1月 12, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virtual doc - support content provider signalling change via onDidChange event
上级
0bdf9ca8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
4 deletion
+73
-4
extensions/vscode-api-tests/src/workspace.test.ts
extensions/vscode-api-tests/src/workspace.test.ts
+46
-3
src/vs/workbench/api/node/extHostDocuments.ts
src/vs/workbench/api/node/extHostDocuments.ts
+27
-1
未找到文件。
extensions/vscode-api-tests/src/workspace.test.ts
浏览文件 @
f345c948
...
...
@@ -6,11 +6,10 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
workspace
,
TextDocument
,
window
,
Position
,
Uri
,
CancellationTokenSource
}
from
'
vscode
'
;
import
{
workspace
,
TextDocument
,
window
,
Position
,
Uri
,
CancellationTokenSource
,
Disposable
}
from
'
vscode
'
;
import
{
createRandomFile
,
deleteFile
,
cleanUp
,
pathEquals
}
from
'
./utils
'
;
import
{
join
,
basename
}
from
'
path
'
;
import
*
as
fs
from
'
fs
'
;
import
*
as
os
from
'
os
'
;
suite
(
'
workspace-namespace
'
,
()
=>
{
...
...
@@ -209,6 +208,50 @@ suite('workspace-namespace', () => {
});
});
test
(
'
registerTextDocumentContentProvider, change event
'
,
function
()
{
let
callCount
=
0
;
let
listeners
:
Function
[]
=
[];
let
registration
=
workspace
.
registerTextDocumentContentProvider
(
'
foo
'
,
{
onDidChange
(
callback
,
thisArg
,
disposables
)
{
let
actual
=
thisArg
?
callback
.
bind
(
thisArg
)
:
callback
;
listeners
.
push
(
actual
);
let
subscription
=
new
Disposable
(()
=>
{
const
idx
=
listeners
.
indexOf
(
actual
);
listeners
.
splice
(
idx
,
1
);
});
if
(
Array
.
isArray
(
disposables
))
{
disposables
.
push
(
subscription
);
}
return
subscription
;
},
provideTextDocumentContent
(
uri
)
{
return
'
call
'
+
(
callCount
++
);
}
});
const
uri
=
Uri
.
parse
(
'
foo://testing/path2
'
);
return
workspace
.
openTextDocument
(
uri
).
then
(
doc
=>
{
assert
.
equal
(
callCount
,
1
);
assert
.
equal
(
doc
.
getText
(),
'
call0
'
);
return
new
Promise
((
resolve
,
reject
)
=>
{
workspace
.
onDidChangeTextDocument
(
event
=>
{
assert
.
ok
(
event
.
document
===
doc
);
assert
.
equal
(
event
.
document
.
getText
(),
'
call1
'
);
resolve
();
});
listeners
.
forEach
(
l
=>
l
(
doc
.
uri
));
registration
.
dispose
();
});
});
});
test
(
'
findFiles
'
,
()
=>
{
return
workspace
.
findFiles
(
'
*.js
'
,
null
).
then
((
res
)
=>
{
assert
.
equal
(
res
.
length
,
1
);
...
...
@@ -226,4 +269,4 @@ suite('workspace-namespace', () => {
assert
.
equal
(
res
,
void
0
);
});
});
});
\ No newline at end of file
});
src/vs/workbench/api/node/extHostDocuments.ts
浏览文件 @
f345c948
...
...
@@ -134,7 +134,23 @@ export class ExtHostModelService {
throw
new
Error
(
`scheme '
${
scheme
}
' already registered`
);
}
this
.
_documentContentProviders
[
scheme
]
=
provider
;
return
new
Disposable
(()
=>
delete
this
.
_documentContentProviders
[
scheme
]);
let
subscription
:
IDisposable
;
if
(
typeof
provider
.
onDidChange
===
'
function
'
)
{
subscription
=
provider
.
onDidChange
(
uri
=>
{
if
(
this
.
_documentData
[
uri
.
toString
()])
{
this
.
$provideTextDocumentContent
(
<
URI
>
uri
).
then
(
value
=>
{
return
this
.
_proxy
.
$onVirtualDocumentChange
(
<
URI
>
uri
,
value
);
},
onUnexpectedError
);
}
});
}
return
new
Disposable
(()
=>
{
delete
this
.
_documentContentProviders
[
scheme
];
if
(
subscription
)
{
subscription
.
dispose
();
}
});
}
$provideTextDocumentContent
(
uri
:
URI
):
TPromise
<
string
>
{
...
...
@@ -599,6 +615,8 @@ export class MainThreadDocuments {
});
}
// --- virtual document logic
private
_handleAnyScheme
(
uri
:
URI
):
TPromise
<
boolean
>
{
if
(
this
.
_modelService
.
getModel
(
uri
))
{
...
...
@@ -633,4 +651,12 @@ export class MainThreadDocuments {
return
true
;
});
}
$onVirtualDocumentChange
(
uri
:
URI
,
value
:
string
):
TPromise
<
any
>
{
const
model
=
this
.
_modelService
.
getModel
(
uri
);
if
(
model
)
{
model
.
setValue
(
value
);
return
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录