Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2553f5dc
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,发现更多精彩内容 >>
提交
2553f5dc
编写于
2月 27, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix global storage change events for deletes ( #91582)
上级
66698913
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
28 deletion
+63
-28
src/vs/base/parts/storage/common/storage.ts
src/vs/base/parts/storage/common/storage.ts
+6
-4
src/vs/base/parts/storage/test/node/storage.test.ts
src/vs/base/parts/storage/test/node/storage.test.ts
+9
-10
src/vs/platform/storage/browser/storageService.ts
src/vs/platform/storage/browser/storageService.ts
+28
-1
src/vs/platform/storage/node/storageIpc.ts
src/vs/platform/storage/node/storageIpc.ts
+15
-8
src/vs/platform/storage/node/storageService.ts
src/vs/platform/storage/node/storageService.ts
+5
-5
未找到文件。
src/vs/base/parts/storage/common/storage.ts
浏览文件 @
2553f5dc
...
@@ -27,7 +27,8 @@ export interface IUpdateRequest {
...
@@ -27,7 +27,8 @@ export interface IUpdateRequest {
}
}
export
interface
IStorageItemsChangeEvent
{
export
interface
IStorageItemsChangeEvent
{
items
:
Map
<
string
,
string
>
;
changed
?:
Map
<
string
,
string
>
;
deleted
?:
Set
<
string
>
;
}
}
export
interface
IStorageDatabase
{
export
interface
IStorageDatabase
{
...
@@ -104,10 +105,11 @@ export class Storage extends Disposable implements IStorage {
...
@@ -104,10 +105,11 @@ export class Storage extends Disposable implements IStorage {
// items that change external require us to update our
// items that change external require us to update our
// caches with the values. we just accept the value and
// caches with the values. we just accept the value and
// emit an event if there is a change.
// emit an event if there is a change.
e
.
items
.
forEach
((
value
,
key
)
=>
this
.
accept
(
key
,
value
));
e
.
changed
?.
forEach
((
value
,
key
)
=>
this
.
accept
(
key
,
value
));
e
.
deleted
?.
forEach
(
key
=>
this
.
accept
(
key
,
undefined
));
}
}
private
accept
(
key
:
string
,
value
:
string
):
void
{
private
accept
(
key
:
string
,
value
:
string
|
undefined
):
void
{
if
(
this
.
state
===
StorageState
.
Closed
)
{
if
(
this
.
state
===
StorageState
.
Closed
)
{
return
;
// Return early if we are already closed
return
;
// Return early if we are already closed
}
}
...
@@ -315,4 +317,4 @@ export class InMemoryStorageDatabase implements IStorageDatabase {
...
@@ -315,4 +317,4 @@ export class InMemoryStorageDatabase implements IStorageDatabase {
close
():
Promise
<
void
>
{
close
():
Promise
<
void
>
{
return
Promise
.
resolve
();
return
Promise
.
resolve
();
}
}
}
}
\ No newline at end of file
src/vs/base/parts/storage/test/node/storage.test.ts
浏览文件 @
2553f5dc
...
@@ -124,28 +124,27 @@ suite('Storage Library', () => {
...
@@ -124,28 +124,27 @@ suite('Storage Library', () => {
changes
.
clear
();
changes
.
clear
();
// Nothing happens if changing to same value
// Nothing happens if changing to same value
const
change
=
new
Map
<
string
,
string
>
();
const
change
d
=
new
Map
<
string
,
string
>
();
change
.
set
(
'
foo
'
,
'
bar
'
);
change
d
.
set
(
'
foo
'
,
'
bar
'
);
database
.
fireDidChangeItemsExternal
({
items
:
change
});
database
.
fireDidChangeItemsExternal
({
changed
});
equal
(
changes
.
size
,
0
);
equal
(
changes
.
size
,
0
);
// Change is accepted if valid
// Change is accepted if valid
change
.
set
(
'
foo
'
,
'
bar1
'
);
change
d
.
set
(
'
foo
'
,
'
bar1
'
);
database
.
fireDidChangeItemsExternal
({
items
:
change
});
database
.
fireDidChangeItemsExternal
({
changed
});
ok
(
changes
.
has
(
'
foo
'
));
ok
(
changes
.
has
(
'
foo
'
));
equal
(
storage
.
get
(
'
foo
'
),
'
bar1
'
);
equal
(
storage
.
get
(
'
foo
'
),
'
bar1
'
);
changes
.
clear
();
changes
.
clear
();
// Delete is accepted
// Delete is accepted
c
hange
.
set
(
'
foo
'
,
undefined
!
);
c
onst
deleted
=
new
Set
<
string
>
([
'
foo
'
]
);
database
.
fireDidChangeItemsExternal
({
items
:
change
});
database
.
fireDidChangeItemsExternal
({
deleted
});
ok
(
changes
.
has
(
'
foo
'
));
ok
(
changes
.
has
(
'
foo
'
));
equal
(
storage
.
get
(
'
foo
'
,
null
!
),
null
);
equal
(
storage
.
get
(
'
foo
'
,
undefined
),
undefined
);
changes
.
clear
();
changes
.
clear
();
// Nothing happens if changing to same value
// Nothing happens if changing to same value
change
.
set
(
'
foo
'
,
undefined
!
);
database
.
fireDidChangeItemsExternal
({
deleted
});
database
.
fireDidChangeItemsExternal
({
items
:
change
});
equal
(
changes
.
size
,
0
);
equal
(
changes
.
size
,
0
);
await
storage
.
close
();
await
storage
.
close
();
...
...
src/vs/platform/storage/browser/storageService.ts
浏览文件 @
2553f5dc
...
@@ -240,9 +240,36 @@ export class FileStorageDatabase extends Disposable implements IStorageDatabase
...
@@ -240,9 +240,36 @@ export class FileStorageDatabase extends Disposable implements IStorageDatabase
private
async
onDidStorageChangeExternal
():
Promise
<
void
>
{
private
async
onDidStorageChangeExternal
():
Promise
<
void
>
{
const
items
=
await
this
.
doGetItemsFromFile
();
const
items
=
await
this
.
doGetItemsFromFile
();
// pervious cache, diff for changes
let
changed
=
new
Map
<
string
,
string
>
();
let
deleted
=
new
Set
<
string
>
();
if
(
this
.
cache
)
{
items
.
forEach
((
value
,
key
)
=>
{
const
existingValue
=
this
.
cache
?.
get
(
key
);
if
(
existingValue
!==
value
)
{
changed
.
set
(
key
,
value
);
}
});
this
.
cache
.
forEach
((
_
,
key
)
=>
{
if
(
!
items
.
has
(
key
))
{
deleted
.
add
(
key
);
}
});
}
// no previous cache, consider all as changed
else
{
changed
=
items
;
}
// Update cache
this
.
cache
=
items
;
this
.
cache
=
items
;
this
.
_onDidChangeItemsExternal
.
fire
({
items
});
// Emit as event as needed
if
(
changed
.
size
>
0
||
deleted
.
size
>
0
)
{
this
.
_onDidChangeItemsExternal
.
fire
({
changed
,
deleted
});
}
}
}
async
getItems
():
Promise
<
Map
<
string
,
string
>>
{
async
getItems
():
Promise
<
Map
<
string
,
string
>>
{
...
...
src/vs/platform/storage/node/storageIpc.ts
浏览文件 @
2553f5dc
...
@@ -24,15 +24,16 @@ interface ISerializableUpdateRequest {
...
@@ -24,15 +24,16 @@ interface ISerializableUpdateRequest {
}
}
interface
ISerializableItemsChangeEvent
{
interface
ISerializableItemsChangeEvent
{
items
:
Item
[];
changed
?:
Item
[];
deleted
?:
Key
[];
}
}
export
class
GlobalStorageDatabaseChannel
extends
Disposable
implements
IServerChannel
{
export
class
GlobalStorageDatabaseChannel
extends
Disposable
implements
IServerChannel
{
private
static
readonly
STORAGE_CHANGE_DEBOUNCE_TIME
=
100
;
private
static
readonly
STORAGE_CHANGE_DEBOUNCE_TIME
=
100
;
private
readonly
_onDidChangeItems
:
Emitter
<
ISerializableItemsChangeEvent
>
=
this
.
_register
(
new
Emitter
<
ISerializableItemsChangeEvent
>
());
private
readonly
_onDidChangeItems
=
this
.
_register
(
new
Emitter
<
ISerializableItemsChangeEvent
>
());
readonly
onDidChangeItems
:
Event
<
ISerializableItemsChangeEvent
>
=
this
.
_onDidChangeItems
.
event
;
readonly
onDidChangeItems
=
this
.
_onDidChangeItems
.
event
;
private
whenReady
:
Promise
<
void
>
;
private
whenReady
:
Promise
<
void
>
;
...
@@ -99,15 +100,18 @@ export class GlobalStorageDatabaseChannel extends Disposable implements IServerC
...
@@ -99,15 +100,18 @@ export class GlobalStorageDatabaseChannel extends Disposable implements IServerC
}
}
private
serializeEvents
(
events
:
IStorageChangeEvent
[]):
ISerializableItemsChangeEvent
{
private
serializeEvents
(
events
:
IStorageChangeEvent
[]):
ISerializableItemsChangeEvent
{
const
items
=
new
Map
<
Key
,
Value
>
();
const
changed
=
new
Map
<
Key
,
Value
>
();
const
deleted
=
new
Set
<
Key
>
();
events
.
forEach
(
event
=>
{
events
.
forEach
(
event
=>
{
const
existing
=
this
.
storageMainService
.
get
(
event
.
key
);
const
existing
=
this
.
storageMainService
.
get
(
event
.
key
);
if
(
typeof
existing
===
'
string
'
)
{
if
(
typeof
existing
===
'
string
'
)
{
items
.
set
(
event
.
key
,
existing
);
changed
.
set
(
event
.
key
,
existing
);
}
else
{
deleted
.
add
(
event
.
key
);
}
}
});
});
return
{
items
:
mapToSerializable
(
items
)
};
return
{
changed
:
mapToSerializable
(
changed
),
deleted
:
values
(
deleted
)
};
}
}
listen
(
_
:
unknown
,
event
:
string
):
Event
<
any
>
{
listen
(
_
:
unknown
,
event
:
string
):
Event
<
any
>
{
...
@@ -170,8 +174,11 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS
...
@@ -170,8 +174,11 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS
}
}
private
onDidChangeItemsOnMain
(
e
:
ISerializableItemsChangeEvent
):
void
{
private
onDidChangeItemsOnMain
(
e
:
ISerializableItemsChangeEvent
):
void
{
if
(
Array
.
isArray
(
e
.
items
))
{
if
(
Array
.
isArray
(
e
.
changed
)
||
Array
.
isArray
(
e
.
deleted
))
{
this
.
_onDidChangeItemsExternal
.
fire
({
items
:
serializableToMap
(
e
.
items
)
});
this
.
_onDidChangeItemsExternal
.
fire
({
changed
:
e
.
changed
?
serializableToMap
(
e
.
changed
)
:
undefined
,
deleted
:
e
.
deleted
?
new
Set
<
string
>
(
e
.
deleted
)
:
undefined
});
}
}
}
}
...
...
src/vs/platform/storage/node/storageService.ts
浏览文件 @
2553f5dc
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
E
vent
,
E
mitter
}
from
'
vs/base/common/event
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ILogService
,
LogLevel
}
from
'
vs/platform/log/common/log
'
;
import
{
ILogService
,
LogLevel
}
from
'
vs/platform/log/common/log
'
;
import
{
IWorkspaceStorageChangeEvent
,
IStorageService
,
StorageScope
,
IWillSaveStateEvent
,
WillSaveStateReason
,
logStorage
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IWorkspaceStorageChangeEvent
,
IStorageService
,
StorageScope
,
IWillSaveStateEvent
,
WillSaveStateReason
,
logStorage
}
from
'
vs/platform/storage/common/storage
'
;
import
{
SQLiteStorageDatabase
,
ISQLiteStorageDatabaseLoggingOptions
}
from
'
vs/base/parts/storage/node/storage
'
;
import
{
SQLiteStorageDatabase
,
ISQLiteStorageDatabaseLoggingOptions
}
from
'
vs/base/parts/storage/node/storage
'
;
...
@@ -25,11 +25,11 @@ export class NativeStorageService extends Disposable implements IStorageService
...
@@ -25,11 +25,11 @@ export class NativeStorageService extends Disposable implements IStorageService
private
static
readonly
WORKSPACE_STORAGE_NAME
=
'
state.vscdb
'
;
private
static
readonly
WORKSPACE_STORAGE_NAME
=
'
state.vscdb
'
;
private
static
readonly
WORKSPACE_META_NAME
=
'
workspace.json
'
;
private
static
readonly
WORKSPACE_META_NAME
=
'
workspace.json
'
;
private
readonly
_onDidChangeStorage
:
Emitter
<
IWorkspaceStorageChangeEvent
>
=
this
.
_register
(
new
Emitter
<
IWorkspaceStorageChangeEvent
>
());
private
readonly
_onDidChangeStorage
=
this
.
_register
(
new
Emitter
<
IWorkspaceStorageChangeEvent
>
());
readonly
onDidChangeStorage
:
Event
<
IWorkspaceStorageChangeEvent
>
=
this
.
_onDidChangeStorage
.
event
;
readonly
onDidChangeStorage
=
this
.
_onDidChangeStorage
.
event
;
private
readonly
_onWillSaveState
:
Emitter
<
IWillSaveStateEvent
>
=
this
.
_register
(
new
Emitter
<
IWillSaveStateEvent
>
());
private
readonly
_onWillSaveState
=
this
.
_register
(
new
Emitter
<
IWillSaveStateEvent
>
());
readonly
onWillSaveState
:
Event
<
IWillSaveStateEvent
>
=
this
.
_onWillSaveState
.
event
;
readonly
onWillSaveState
=
this
.
_onWillSaveState
.
event
;
private
globalStorage
:
IStorage
;
private
globalStorage
:
IStorage
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录