Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f26416cd
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,发现更多精彩内容 >>
提交
f26416cd
编写于
12月 01, 2019
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support syncing keybindings per platform
上级
17b53573
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
78 addition
and
12 deletion
+78
-12
src/vs/platform/userDataSync/common/keybindingsSync.ts
src/vs/platform/userDataSync/common/keybindingsSync.ts
+72
-12
src/vs/platform/userDataSync/common/userDataSync.ts
src/vs/platform/userDataSync/common/userDataSync.ts
+6
-0
未找到文件。
src/vs/platform/userDataSync/common/keybindingsSync.ts
浏览文件 @
f26416cd
...
...
@@ -17,6 +17,15 @@ import { URI } from 'vs/base/common/uri';
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
OS
,
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
isUndefined
}
from
'
vs/base/common/types
'
;
interface
ISyncContent
{
mac
?:
string
;
linux
?:
string
;
windows
?:
string
;
all
?:
string
;
}
interface
ISyncPreviewResult
{
readonly
fileContent
:
IFileContent
|
null
;
...
...
@@ -54,6 +63,7 @@ export class KeybindingsSynchroniser extends Disposable implements ISynchroniser
super
();
this
.
lastSyncKeybindingsResource
=
joinPath
(
this
.
environmentService
.
userRoamingDataHome
,
'
.lastSyncKeybindings.json
'
);
this
.
throttledDelayer
=
this
.
_register
(
new
ThrottledDelayer
<
void
>
(
500
));
this
.
_register
(
this
.
fileService
.
watch
(
this
.
environmentService
.
keybindingsResource
));
this
.
_register
(
Event
.
filter
(
this
.
fileService
.
onFileChanges
,
e
=>
e
.
contains
(
this
.
environmentService
.
keybindingsResource
))(()
=>
this
.
throttledDelayer
.
trigger
(()
=>
this
.
onDidChangeKeybindings
())));
}
...
...
@@ -166,12 +176,14 @@ export class KeybindingsSynchroniser extends Disposable implements ISynchroniser
}
if
(
hasRemoteChanged
)
{
this
.
logService
.
info
(
'
Keybindings: Updating remote keybindings
'
);
const
ref
=
await
this
.
updateRemoteContent
(
content
,
remoteUserData
.
ref
);
remoteUserData
=
{
ref
,
content
};
const
remoteContents
=
this
.
updateSyncContent
(
content
,
remoteUserData
.
content
);
const
ref
=
await
this
.
updateRemoteUserData
(
remoteContents
,
remoteUserData
.
ref
);
remoteUserData
=
{
ref
,
content
:
remoteContents
};
}
if
(
remoteUserData
.
content
)
{
this
.
logService
.
info
(
'
Keybindings: Updating last synchronised keybindings
'
);
await
this
.
updateLastSyncUserData
(
remoteUserData
);
const
lastSyncContent
=
this
.
updateSyncContent
(
content
,
null
);
await
this
.
updateLastSyncUserData
({
ref
:
remoteUserData
.
ref
,
content
:
lastSyncContent
});
}
// Delete the preview
...
...
@@ -200,8 +212,9 @@ export class KeybindingsSynchroniser extends Disposable implements ISynchroniser
private
async
generatePreview
(
token
:
CancellationToken
):
Promise
<
ISyncPreviewResult
>
{
const
lastSyncData
=
await
this
.
getLastSyncUserData
();
const
remoteUserData
=
await
this
.
getRemoteContent
(
lastSyncData
);
const
remoteContent
:
string
|
null
=
remoteUserData
.
content
;
const
lastSyncContent
=
lastSyncData
&&
lastSyncData
.
content
?
this
.
getKeybindingsContentFromSyncContent
(
lastSyncData
.
content
)
:
null
;
const
remoteUserData
=
await
this
.
getRemoteUserData
(
lastSyncData
);
const
remoteContent
=
remoteUserData
.
content
?
this
.
getKeybindingsContentFromSyncContent
(
remoteUserData
.
content
)
:
null
;
// Get file content last to get the latest
const
fileContent
=
await
this
.
getLocalContent
();
let
hasLocalChanged
:
boolean
=
false
;
...
...
@@ -216,13 +229,13 @@ export class KeybindingsSynchroniser extends Disposable implements ISynchroniser
return
{
fileContent
,
remoteUserData
,
hasLocalChanged
,
hasRemoteChanged
,
hasConflicts
};
}
if
(
!
lastSync
Data
// First time sync
||
lastSync
Data
.
c
ontent
!==
localContent
// Local has forwarded
||
lastSync
Data
.
c
ontent
!==
remoteContent
// Remote has forwarded
if
(
!
lastSync
Content
// First time sync
||
lastSync
C
ontent
!==
localContent
// Local has forwarded
||
lastSync
C
ontent
!==
remoteContent
// Remote has forwarded
)
{
this
.
logService
.
trace
(
'
Keybindings: Merging remote keybindings with local keybindings...
'
);
const
keys
=
await
this
.
userKeybindingsResolverService
.
resolveUserKeybindings
(
localContent
,
remoteContent
,
lastSync
Data
?
lastSyncData
.
content
:
null
);
const
result
=
merge
(
localContent
,
remoteContent
,
lastSync
Data
?
lastSyncData
.
content
:
null
,
keys
);
const
keys
=
await
this
.
userKeybindingsResolverService
.
resolveUserKeybindings
(
localContent
,
remoteContent
,
lastSync
Content
);
const
result
=
merge
(
localContent
,
remoteContent
,
lastSync
Content
,
keys
);
// Sync only if there are changes
if
(
result
.
hasChanges
)
{
hasLocalChanged
=
result
.
mergeContent
!==
localContent
;
...
...
@@ -278,11 +291,58 @@ export class KeybindingsSynchroniser extends Disposable implements ISynchroniser
await
this
.
fileService
.
writeFile
(
this
.
lastSyncKeybindingsResource
,
VSBuffer
.
fromString
(
JSON
.
stringify
(
remoteUserData
)));
}
private
async
getRemote
Content
(
lastSyncData
:
IUserData
|
null
):
Promise
<
IUserData
>
{
private
async
getRemote
UserData
(
lastSyncData
:
IUserData
|
null
):
Promise
<
IUserData
>
{
return
this
.
userDataSyncStoreService
.
read
(
KeybindingsSynchroniser
.
EXTERNAL_USER_DATA_KEYBINDINGS_KEY
,
lastSyncData
);
}
private
async
updateRemote
Content
(
content
:
string
,
ref
:
string
|
null
):
Promise
<
string
>
{
private
async
updateRemote
UserData
(
content
:
string
,
ref
:
string
|
null
):
Promise
<
string
>
{
return
this
.
userDataSyncStoreService
.
write
(
KeybindingsSynchroniser
.
EXTERNAL_USER_DATA_KEYBINDINGS_KEY
,
content
,
ref
);
}
private
getKeybindingsContentFromSyncContent
(
syncContent
:
string
):
string
|
null
{
try
{
const
parsed
=
<
ISyncContent
>
JSON
.
parse
(
syncContent
);
if
(
!
this
.
configurationService
.
getValue
<
boolean
>
(
'
sync.keybindingsPerPlatform
'
))
{
return
isUndefined
(
parsed
.
all
)
?
null
:
parsed
.
all
;
}
switch
(
OS
)
{
case
OperatingSystem
.
Macintosh
:
return
isUndefined
(
parsed
.
mac
)
?
null
:
parsed
.
mac
;
case
OperatingSystem
.
Linux
:
return
isUndefined
(
parsed
.
linux
)
?
null
:
parsed
.
linux
;
case
OperatingSystem
.
Windows
:
return
isUndefined
(
parsed
.
windows
)
?
null
:
parsed
.
windows
;
}
}
catch
(
e
)
{
this
.
logService
.
error
(
e
);
return
null
;
}
}
private
updateSyncContent
(
keybindingsContent
:
string
,
syncContent
:
string
|
null
):
string
{
let
parsed
:
ISyncContent
=
{};
try
{
parsed
=
JSON
.
parse
(
syncContent
||
'
{}
'
);
}
catch
(
e
)
{
this
.
logService
.
error
(
e
);
}
if
(
!
this
.
configurationService
.
getValue
<
boolean
>
(
'
sync.keybindingsPerPlatform
'
))
{
parsed
.
all
=
keybindingsContent
;
}
else
{
delete
parsed
.
all
;
}
switch
(
OS
)
{
case
OperatingSystem
.
Macintosh
:
parsed
.
mac
=
keybindingsContent
;
break
;
case
OperatingSystem
.
Linux
:
parsed
.
linux
=
keybindingsContent
;
break
;
case
OperatingSystem
.
Windows
:
parsed
.
windows
=
keybindingsContent
;
break
;
}
return
JSON
.
stringify
(
parsed
);
}
}
src/vs/platform/userDataSync/common/userDataSync.ts
浏览文件 @
f26416cd
...
...
@@ -59,6 +59,12 @@ export function registerConfiguration(): IDisposable {
default
:
true
,
scope
:
ConfigurationScope
.
APPLICATION
,
},
'
sync.keybindingsPerPlatform
'
:
{
type
:
'
boolean
'
,
description
:
localize
(
'
sync.keybindingsPerPlatform
'
,
"
Synchronize keybindings per platform.
"
),
default
:
true
,
scope
:
ConfigurationScope
.
APPLICATION
,
},
'
sync.ignoredExtensions
'
:
{
'
type
'
:
'
array
'
,
description
:
localize
(
'
sync.ignoredExtensions
'
,
"
Configure extensions to be ignored while synchronizing.
"
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录