Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a6a41fd6
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,发现更多精彩内容 >>
提交
a6a41fd6
编写于
3月 23, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding TextDocument#isVisible and internals for a visbility change event, #15723
上级
c01a6160
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
202 addition
and
9 deletion
+202
-9
extensions/vscode-api-tests/src/workspace.test.ts
extensions/vscode-api-tests/src/workspace.test.ts
+12
-0
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+6
-1
src/vs/workbench/api/node/extHostDocumentData.ts
src/vs/workbench/api/node/extHostDocumentData.ts
+13
-0
src/vs/workbench/api/node/extHostDocumentsAndEditors.ts
src/vs/workbench/api/node/extHostDocumentsAndEditors.ts
+26
-8
src/vs/workbench/test/node/api/extHostDocumentsAndEditors.test.ts
...orkbench/test/node/api/extHostDocumentsAndEditors.test.ts
+145
-0
未找到文件。
extensions/vscode-api-tests/src/workspace.test.ts
浏览文件 @
a6a41fd6
...
...
@@ -160,6 +160,18 @@ suite('workspace-namespace', () => {
});
});
test
(
'
openTextDocument, visible/invisible
'
,
function
()
{
return
createRandomFile
().
then
(
file
=>
{
return
workspace
.
openTextDocument
(
file
);
}).
then
(
doc
=>
{
assert
.
equal
(
doc
.
isVisible
,
false
);
return
window
.
showTextDocument
(
doc
).
then
(
editor
=>
{
assert
.
ok
(
editor
.
document
===
doc
);
assert
.
equal
(
doc
.
isVisible
,
true
);
});
});
});
test
(
'
events: onDidOpenTextDocument, onDidChangeTextDocument, onDidSaveTextDocument
'
,
()
=>
{
return
createRandomFile
().
then
(
file
=>
{
let
disposables
:
Disposable
[]
=
[];
...
...
src/vs/vscode.d.ts
浏览文件 @
a6a41fd6
...
...
@@ -112,7 +112,12 @@ declare module 'vscode' {
readonly
version
:
number
;
/**
* true if there are unpersisted changes.
* `true` if this document is showing in one or more [editors](#TextEditor).
*/
readonly
isVisible
:
boolean
;
/**
* `true` if there are unpersisted changes.
*/
readonly
isDirty
:
boolean
;
...
...
src/vs/workbench/api/node/extHostDocumentData.ts
浏览文件 @
a6a41fd6
...
...
@@ -28,6 +28,7 @@ export class ExtHostDocumentData extends MirrorModel2 {
private
_proxy
:
MainThreadDocumentsShape
;
private
_languageId
:
string
;
private
_isDirty
:
boolean
;
private
_isVisible
:
boolean
=
false
;
private
_document
:
vscode
.
TextDocument
;
private
_textLines
:
vscode
.
TextLine
[]
=
[];
private
_isDisposed
:
boolean
=
false
;
...
...
@@ -48,6 +49,7 @@ export class ExtHostDocumentData extends MirrorModel2 {
ok
(
!
this
.
_isDisposed
);
this
.
_isDisposed
=
true
;
this
.
_isDirty
=
false
;
this
.
_isVisible
=
false
;
}
equalLines
({
lines
}:
ITextSource
):
boolean
{
...
...
@@ -72,6 +74,7 @@ export class ExtHostDocumentData extends MirrorModel2 {
get
isUntitled
()
{
return
data
.
_uri
.
scheme
!==
'
file
'
;
},
get
languageId
()
{
return
data
.
_languageId
;
},
get
version
()
{
return
data
.
_versionId
;
},
get
isVisible
()
{
return
data
.
_isVisible
;
},
get
isDirty
()
{
return
data
.
_isDirty
;
},
save
()
{
return
data
.
_save
();
},
getText
(
range
?)
{
return
range
?
data
.
_getTextInRange
(
range
)
:
data
.
getText
();
},
...
...
@@ -97,6 +100,16 @@ export class ExtHostDocumentData extends MirrorModel2 {
this
.
_isDirty
=
isDirty
;
}
_acceptIsVisible
(
value
:
boolean
):
boolean
{
ok
(
!
this
.
_isDisposed
);
if
(
this
.
_isVisible
===
value
)
{
return
false
;
}
else
{
this
.
_isVisible
=
value
;
return
true
;
}
}
private
_save
():
TPromise
<
boolean
>
{
if
(
this
.
_isDisposed
)
{
return
TPromise
.
wrapError
<
boolean
>
(
'
Document has been closed
'
);
...
...
src/vs/workbench/api/node/extHostDocumentsAndEditors.ts
浏览文件 @
a6a41fd6
...
...
@@ -23,11 +23,13 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape
private
readonly
_onDidRemoveDocuments
=
new
Emitter
<
ExtHostDocumentData
[]
>
();
private
readonly
_onDidChangeVisibleTextEditors
=
new
Emitter
<
ExtHostTextEditor
[]
>
();
private
readonly
_onDidChangeActiveTextEditor
=
new
Emitter
<
ExtHostTextEditor
>
();
private
readonly
_onDidChangeVisibleDocuments
=
new
Emitter
<
ExtHostDocumentData
[]
>
();
readonly
onDidAddDocuments
:
Event
<
ExtHostDocumentData
[]
>
=
this
.
_onDidAddDocuments
.
event
;
readonly
onDidRemoveDocuments
:
Event
<
ExtHostDocumentData
[]
>
=
this
.
_onDidRemoveDocuments
.
event
;
readonly
onDidChangeVisibleTextEditors
:
Event
<
ExtHostTextEditor
[]
>
=
this
.
_onDidChangeVisibleTextEditors
.
event
;
readonly
onDidChangeActiveTextEditor
:
Event
<
ExtHostTextEditor
>
=
this
.
_onDidChangeActiveTextEditor
.
event
;
readonly
onDidChangeVisibleTextDocuments
:
Event
<
ExtHostDocumentData
[]
>
=
this
.
_onDidChangeVisibleDocuments
.
event
;
constructor
(
@
IThreadService
private
_threadService
:
IThreadService
...
...
@@ -40,6 +42,21 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape
const
removedDocuments
:
ExtHostDocumentData
[]
=
[];
const
addedDocuments
:
ExtHostDocumentData
[]
=
[];
const
removedEditors
:
ExtHostTextEditor
[]
=
[];
const
visibilityChangedDocuments
=
new
Set
<
ExtHostDocumentData
>
();
if
(
delta
.
removedEditors
)
{
for
(
const
id
of
delta
.
removedEditors
)
{
const
editor
=
this
.
_editors
.
get
(
id
);
this
.
_editors
.
delete
(
id
);
removedEditors
.
push
(
editor
);
const
uri
=
editor
.
document
.
uri
.
toString
();
const
data
=
this
.
_documents
.
get
(
uri
);
if
(
data
.
_acceptIsVisible
(
false
))
{
visibilityChangedDocuments
.
add
(
data
);
}
}
}
if
(
delta
.
removedDocuments
)
{
for
(
const
id
of
delta
.
removedDocuments
)
{
...
...
@@ -67,14 +84,6 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape
}
}
if
(
delta
.
removedEditors
)
{
for
(
const
id
of
delta
.
removedEditors
)
{
const
editor
=
this
.
_editors
.
get
(
id
);
this
.
_editors
.
delete
(
id
);
removedEditors
.
push
(
editor
);
}
}
if
(
delta
.
addedEditors
)
{
for
(
const
data
of
delta
.
addedEditors
)
{
assert
.
ok
(
this
.
_documents
.
has
(
data
.
document
.
toString
()),
`document '
${
data
.
document
}
' does not exist`
);
...
...
@@ -90,6 +99,9 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape
typeConverters
.
toViewColumn
(
data
.
editorPosition
)
);
this
.
_editors
.
set
(
data
.
id
,
editor
);
if
(
documentData
.
_acceptIsVisible
(
true
))
{
visibilityChangedDocuments
.
add
(
documentData
);
}
}
}
...
...
@@ -113,6 +125,12 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape
this
.
_onDidChangeActiveTextEditor
.
fire
(
this
.
activeEditor
());
}
if
(
visibilityChangedDocuments
.
size
>
0
)
{
const
documents
:
ExtHostDocumentData
[]
=
[];
visibilityChangedDocuments
.
forEach
(
data
=>
documents
.
push
(
data
));
this
.
_onDidChangeVisibleDocuments
.
fire
(
documents
);
}
// now that the events are out, dispose removed documents and editors
dispose
(
removedDocuments
);
dispose
(
removedEditors
);
...
...
src/vs/workbench/test/node/api/extHostDocumentsAndEditors.test.ts
0 → 100644
浏览文件 @
a6a41fd6
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
ExtHostDocumentData
}
from
'
vs/workbench/api/node/extHostDocumentData
'
;
import
{
ITextEditorAddData
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/node/extHostDocumentsAndEditors
'
;
import
{
OneGetThreadService
}
from
'
./testThreadService
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
suite
(
'
ExtHostDocumentsAndEditors
'
,
()
=>
{
function
modelAddData
(
model
:
Model
)
{
return
{
isDirty
:
false
,
versionId
:
model
.
getVersionId
(),
modeId
:
model
.
getLanguageIdentifier
().
language
,
url
:
model
.
uri
,
lines
:
model
.
getValue
().
split
(
model
.
getEOL
()),
EOL
:
model
.
getEOL
(),
};
}
function
editorAddData
(
model
:
Model
,
id
=
model
.
id
):
ITextEditorAddData
{
return
{
id
,
document
:
model
.
uri
,
options
:
{
tabSize
:
4
,
insertSpaces
:
true
,
cursorStyle
:
0
,
lineNumbers
:
0
},
selections
:
[],
editorPosition
:
1
};
}
let
documentsAndEditors
:
ExtHostDocumentsAndEditors
;
setup
(()
=>
{
documentsAndEditors
=
new
ExtHostDocumentsAndEditors
(
OneGetThreadService
(
null
));
});
test
(
'
onDidChangeVisibleTextDocuments, new document => no event
'
,
()
=>
{
const
model
=
Model
.
createFromString
(
'
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar
'
));
let
docs
:
ExtHostDocumentData
[]
=
[];
let
sub
=
documentsAndEditors
.
onDidChangeVisibleTextDocuments
(
e
=>
docs
.
push
(
null
));
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedDocuments
:
[
modelAddData
(
model
)]
});
assert
.
equal
(
docs
.
length
,
0
);
sub
.
dispose
();
});
test
(
'
onDidChangeVisibleTextDocuments, new editor => event
'
,
()
=>
{
const
model
=
Model
.
createFromString
(
'
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar
'
));
let
docs
:
ExtHostDocumentData
[]
=
[];
let
sub
=
documentsAndEditors
.
onDidChangeVisibleTextDocuments
(
e
=>
docs
.
push
(...
e
));
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedDocuments
:
[
modelAddData
(
model
)]
});
assert
.
equal
(
docs
.
length
,
0
);
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedEditors
:
[
editorAddData
(
model
)]
});
assert
.
equal
(
docs
.
length
,
1
);
assert
.
equal
(
docs
[
0
].
document
.
uri
.
toString
(),
model
.
uri
.
toString
());
sub
.
dispose
();
});
test
(
'
onDidChangeVisibleTextDocuments, removed editor => event
'
,
()
=>
{
const
model
=
Model
.
createFromString
(
'
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar
'
));
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedDocuments
:
[
modelAddData
(
model
)],
addedEditors
:
[
editorAddData
(
model
)]
});
const
all
=
documentsAndEditors
.
allDocuments
();
assert
.
equal
(
1
,
all
.
length
);
assert
.
equal
(
all
[
0
].
document
.
isVisible
,
true
);
let
docs
:
ExtHostDocumentData
[]
=
[];
let
sub
=
documentsAndEditors
.
onDidChangeVisibleTextDocuments
(
e
=>
docs
.
push
(...
e
));
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
removedEditors
:
[
model
.
id
]
});
assert
.
equal
(
docs
.
length
,
1
);
assert
.
equal
(
docs
[
0
].
document
.
uri
.
toString
(),
model
.
uri
.
toString
());
assert
.
equal
(
docs
[
0
].
document
.
isVisible
,
false
);
sub
.
dispose
();
});
test
(
'
onDidChangeVisibleTextDocuments, removed/added editor => event
'
,
()
=>
{
const
model1
=
Model
.
createFromString
(
'
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar
'
));
const
model2
=
Model
.
createFromString
(
'
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar2
'
));
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedDocuments
:
[
modelAddData
(
model1
)],
addedEditors
:
[
editorAddData
(
model1
,
'
left
'
)]
});
const
all
=
documentsAndEditors
.
allDocuments
();
assert
.
equal
(
1
,
all
.
length
);
assert
.
equal
(
all
[
0
].
document
.
isVisible
,
true
);
let
docs
:
ExtHostDocumentData
[]
=
[];
let
sub
=
documentsAndEditors
.
onDidChangeVisibleTextDocuments
(
e
=>
docs
.
push
(...
e
));
// left gets a new editor and right get the document from left
documentsAndEditors
.
$acceptDocumentsAndEditorsDelta
({
addedDocuments
:
[
modelAddData
(
model2
)],
addedEditors
:
[
editorAddData
(
model2
,
'
newLeft
'
),
editorAddData
(
model1
,
'
right
'
)],
removedEditors
:
[
'
left
'
]
});
assert
.
equal
(
docs
.
length
,
2
);
let
[
left
,
right
]
=
docs
;
assert
.
equal
(
left
.
document
.
isVisible
,
true
);
assert
.
equal
(
right
.
document
.
isVisible
,
true
);
sub
.
dispose
();
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录