Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
c6315a3d
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,发现更多精彩内容 >>
提交
c6315a3d
编写于
3月 05, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - more services cleanup
上级
f0983abe
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
134 addition
and
46 deletion
+134
-46
src/vs/platform/lifecycle/common/lifecycle.ts
src/vs/platform/lifecycle/common/lifecycle.ts
+1
-1
src/vs/workbench/electron-browser/workbench.ts
src/vs/workbench/electron-browser/workbench.ts
+48
-40
src/vs/workbench/services/backup/node/backupFileService.ts
src/vs/workbench/services/backup/node/backupFileService.ts
+64
-3
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
...es/backup/test/electron-browser/backupFileService.test.ts
+20
-2
src/vs/workbench/workbench.main.ts
src/vs/workbench/workbench.main.ts
+1
-0
未找到文件。
src/vs/platform/lifecycle/common/lifecycle.ts
浏览文件 @
c6315a3d
...
@@ -133,7 +133,7 @@ export interface ILifecycleService {
...
@@ -133,7 +133,7 @@ export interface ILifecycleService {
/**
/**
* A flag indicating in what phase of the lifecycle we currently are.
* A flag indicating in what phase of the lifecycle we currently are.
*/
*/
readonly
phase
:
LifecyclePhase
;
phase
:
LifecyclePhase
;
/**
/**
* Fired before shutdown happens. Allows listeners to veto against the
* Fired before shutdown happens. Allows listeners to veto against the
...
...
src/vs/workbench/electron-browser/workbench.ts
浏览文件 @
c6315a3d
...
@@ -105,8 +105,6 @@ import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys';
...
@@ -105,8 +105,6 @@ import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys';
import
{
ServicesAccessor
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ServicesAccessor
}
from
'
vs/editor/browser/editorExtensions
'
;
// import@node
// import@node
import
{
BackupFileService
,
InMemoryBackupFileService
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
WorkspaceService
}
from
'
vs/workbench/services/configuration/node/configurationService
'
;
import
{
getDelayedChannel
}
from
'
vs/base/parts/ipc/node/ipc
'
;
import
{
getDelayedChannel
}
from
'
vs/base/parts/ipc/node/ipc
'
;
import
{
connect
as
connectNet
}
from
'
vs/base/parts/ipc/node/ipc.net
'
;
import
{
connect
as
connectNet
}
from
'
vs/base/parts/ipc/node/ipc.net
'
;
import
{
DialogChannel
}
from
'
vs/platform/dialogs/node/dialogIpc
'
;
import
{
DialogChannel
}
from
'
vs/platform/dialogs/node/dialogIpc
'
;
...
@@ -190,13 +188,13 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -190,13 +188,13 @@ export class Workbench extends Disposable implements IPartService {
private
editorService
:
EditorService
;
private
editorService
:
EditorService
;
private
editorGroupService
:
IEditorGroupsService
;
private
editorGroupService
:
IEditorGroupsService
;
private
contextViewService
:
ContextViewService
;
private
contextViewService
:
ContextViewService
;
private
backupFileService
:
IBackupFileService
;
private
windowService
:
IWindowService
;
private
windowService
:
IWindowService
;
private
lifecycleService
:
LifecycleService
;
private
lifecycleService
:
ILifecycleService
;
private
instantiationService
:
IInstantiationService
;
private
instantiationService
:
IInstantiationService
;
private
contextService
:
IWorkspaceContextService
;
private
contextService
:
IWorkspaceContextService
;
private
storageService
:
IStorageService
;
private
storageService
:
IStorageService
;
private
configurationService
:
Workspace
Service
;
private
configurationService
:
IConfiguration
Service
;
private
environmentService
:
IEnvironmentService
;
private
environmentService
:
IEnvironmentService
;
private
logService
:
ILogService
;
private
logService
:
ILogService
;
private
windowsService
:
IWindowsService
;
private
windowsService
:
IWindowsService
;
...
@@ -221,7 +219,7 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -221,7 +219,7 @@ export class Workbench extends Disposable implements IPartService {
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
,
@
IStorageService
storageService
:
IStorageService
,
@
IStorageService
storageService
:
IStorageService
,
@
IConfigurationService
configurationService
:
Workspace
Service
,
@
IConfigurationService
configurationService
:
IConfiguration
Service
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
ILogService
logService
:
ILogService
,
@
ILogService
logService
:
ILogService
,
@
IWindowsService
windowsService
:
IWindowsService
@
IWindowsService
windowsService
:
IWindowsService
...
@@ -333,7 +331,7 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -333,7 +331,7 @@ export class Workbench extends Disposable implements IPartService {
this
.
registerLayoutListeners
();
this
.
registerLayoutListeners
();
// Layout State
// Layout State
this
.
in
itLayoutState
(
);
this
.
in
stantiationService
.
invokeFunction
(
accessor
=>
this
.
initLayoutState
(
accessor
)
);
// Render Workbench
// Render Workbench
this
.
renderWorkbench
();
this
.
renderWorkbench
();
...
@@ -525,14 +523,6 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -525,14 +523,6 @@ export class Workbench extends Disposable implements IPartService {
// History
// History
serviceCollection
.
set
(
IHistoryService
,
new
SyncDescriptor
(
HistoryService
));
serviceCollection
.
set
(
IHistoryService
,
new
SyncDescriptor
(
HistoryService
));
// Backup File Service
if
(
this
.
configuration
.
backupPath
)
{
this
.
backupFileService
=
this
.
instantiationService
.
createInstance
(
BackupFileService
,
this
.
configuration
.
backupPath
);
}
else
{
this
.
backupFileService
=
new
InMemoryBackupFileService
();
}
serviceCollection
.
set
(
IBackupFileService
,
this
.
backupFileService
);
// Quick open service (quick open controller)
// Quick open service (quick open controller)
this
.
quickOpen
=
this
.
instantiationService
.
createInstance
(
QuickOpenController
);
this
.
quickOpen
=
this
.
instantiationService
.
createInstance
(
QuickOpenController
);
serviceCollection
.
set
(
IQuickOpenService
,
this
.
quickOpen
);
serviceCollection
.
set
(
IQuickOpenService
,
this
.
quickOpen
);
...
@@ -561,12 +551,20 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -561,12 +551,20 @@ export class Workbench extends Disposable implements IPartService {
this
.
instantiationService
.
invokeFunction
(
accessor
=>
{
this
.
instantiationService
.
invokeFunction
(
accessor
=>
{
const
fileService
=
accessor
.
get
(
IFileService
);
const
fileService
=
accessor
.
get
(
IFileService
);
const
instantiationService
=
accessor
.
get
(
IInstantiationService
);
const
instantiationService
=
accessor
.
get
(
IInstantiationService
);
const
themeService
=
accessor
.
get
(
IWorkbenchThemeService
)
as
WorkbenchThemeService
;
const
configurationService
=
accessor
.
get
(
IConfigurationService
)
as
any
;
const
themeService
=
accessor
.
get
(
IWorkbenchThemeService
)
as
any
;
this
.
configurationService
.
acquireFileService
(
fileService
);
if
(
typeof
configurationService
.
acquireFileService
===
'
function
'
)
{
this
.
configurationService
.
acquireInstantiationService
(
instantiationService
);
configurationService
.
acquireFileService
(
fileService
);
}
if
(
typeof
configurationService
.
acquireInstantiationService
===
'
function
'
)
{
configurationService
.
acquireInstantiationService
(
instantiationService
);
}
if
(
typeof
themeService
.
acquireFileService
===
'
function
'
)
{
themeService
.
acquireFileService
(
fileService
);
themeService
.
acquireFileService
(
fileService
);
}
});
});
}
}
...
@@ -785,7 +783,7 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -785,7 +783,7 @@ export class Workbench extends Disposable implements IPartService {
}
}
private
whenStarted
(
accessor
:
ServicesAccessor
,
error
?:
Error
):
void
{
private
whenStarted
(
accessor
:
ServicesAccessor
,
error
?:
Error
):
void
{
const
lifecycleService
=
accessor
.
get
(
ILifecycleService
)
as
LifecycleService
;
const
lifecycleService
=
accessor
.
get
(
ILifecycleService
);
this
.
restored
=
true
;
this
.
restored
=
true
;
...
@@ -1020,22 +1018,27 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1020,22 +1018,27 @@ export class Workbench extends Disposable implements IPartService {
}
}
}
}
private
initLayoutState
():
void
{
private
initLayoutState
(
accessor
:
ServicesAccessor
):
void
{
const
configurationService
=
accessor
.
get
(
IConfigurationService
);
const
storageService
=
accessor
.
get
(
IStorageService
);
const
lifecycleService
=
accessor
.
get
(
ILifecycleService
);
const
contextService
=
accessor
.
get
(
IWorkspaceContextService
);
const
environmentService
=
accessor
.
get
(
IEnvironmentService
);
// Fullscreen
// Fullscreen
this
.
state
.
fullscreen
=
isFullscreen
();
this
.
state
.
fullscreen
=
isFullscreen
();
// Menubar visibility
// Menubar visibility
this
.
state
.
menuBar
.
visibility
=
this
.
configurationService
.
getValue
<
MenuBarVisibility
>
(
Settings
.
MENUBAR_VISIBLE
);
this
.
state
.
menuBar
.
visibility
=
configurationService
.
getValue
<
MenuBarVisibility
>
(
Settings
.
MENUBAR_VISIBLE
);
// Activity bar visibility
// Activity bar visibility
this
.
state
.
activityBar
.
hidden
=
!
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
ACTIVITYBAR_VISIBLE
);
this
.
state
.
activityBar
.
hidden
=
!
configurationService
.
getValue
<
string
>
(
Settings
.
ACTIVITYBAR_VISIBLE
);
// Sidebar visibility
// Sidebar visibility
this
.
state
.
sideBar
.
hidden
=
this
.
storageService
.
getBoolean
(
Storage
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
,
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
);
this
.
state
.
sideBar
.
hidden
=
storageService
.
getBoolean
(
Storage
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
,
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
);
// Sidebar position
// Sidebar position
this
.
state
.
sideBar
.
position
=
(
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
SIDEBAR_POSITION
)
===
'
right
'
)
?
Position
.
RIGHT
:
Position
.
LEFT
;
this
.
state
.
sideBar
.
position
=
(
configurationService
.
getValue
<
string
>
(
Settings
.
SIDEBAR_POSITION
)
===
'
right
'
)
?
Position
.
RIGHT
:
Position
.
LEFT
;
// Sidebar viewlet
// Sidebar viewlet
if
(
!
this
.
state
.
sideBar
.
hidden
)
{
if
(
!
this
.
state
.
sideBar
.
hidden
)
{
...
@@ -1043,8 +1046,8 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1043,8 +1046,8 @@ export class Workbench extends Disposable implements IPartService {
// Only restore last viewlet if window was reloaded or we are in development mode
// Only restore last viewlet if window was reloaded or we are in development mode
let
viewletToRestore
:
string
;
let
viewletToRestore
:
string
;
if
(
!
this
.
environmentService
.
isBuilt
||
this
.
lifecycleService
.
startupKind
===
StartupKind
.
ReloadedWindow
)
{
if
(
!
environmentService
.
isBuilt
||
lifecycleService
.
startupKind
===
StartupKind
.
ReloadedWindow
)
{
viewletToRestore
=
this
.
storageService
.
get
(
SidebarPart
.
activeViewletSettingsKey
,
StorageScope
.
WORKSPACE
,
viewletRegistry
.
getDefaultViewletId
());
viewletToRestore
=
storageService
.
get
(
SidebarPart
.
activeViewletSettingsKey
,
StorageScope
.
WORKSPACE
,
viewletRegistry
.
getDefaultViewletId
());
}
else
{
}
else
{
viewletToRestore
=
viewletRegistry
.
getDefaultViewletId
();
viewletToRestore
=
viewletRegistry
.
getDefaultViewletId
();
}
}
...
@@ -1057,13 +1060,13 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1057,13 +1060,13 @@ export class Workbench extends Disposable implements IPartService {
}
}
// Editor centered layout
// Editor centered layout
this
.
state
.
editor
.
restoreCentered
=
this
.
storageService
.
getBoolean
(
Storage
.
CENTERED_LAYOUT_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
this
.
state
.
editor
.
restoreCentered
=
storageService
.
getBoolean
(
Storage
.
CENTERED_LAYOUT_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
// Editors to open
// Editors to open
this
.
state
.
editor
.
editorsToOpen
=
this
.
resolveEditorsToOpen
();
this
.
state
.
editor
.
editorsToOpen
=
this
.
resolveEditorsToOpen
(
accessor
);
// Panel visibility
// Panel visibility
this
.
state
.
panel
.
hidden
=
this
.
storageService
.
getBoolean
(
Storage
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
,
true
);
this
.
state
.
panel
.
hidden
=
storageService
.
getBoolean
(
Storage
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
,
true
);
// Panel position
// Panel position
this
.
updatePanelPosition
();
this
.
updatePanelPosition
();
...
@@ -1072,7 +1075,7 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1072,7 +1075,7 @@ export class Workbench extends Disposable implements IPartService {
if
(
!
this
.
state
.
panel
.
hidden
)
{
if
(
!
this
.
state
.
panel
.
hidden
)
{
const
panelRegistry
=
Registry
.
as
<
PanelRegistry
>
(
PanelExtensions
.
Panels
);
const
panelRegistry
=
Registry
.
as
<
PanelRegistry
>
(
PanelExtensions
.
Panels
);
let
panelToRestore
=
this
.
storageService
.
get
(
PanelPart
.
activePanelSettingsKey
,
StorageScope
.
WORKSPACE
,
panelRegistry
.
getDefaultPanelId
());
let
panelToRestore
=
storageService
.
get
(
PanelPart
.
activePanelSettingsKey
,
StorageScope
.
WORKSPACE
,
panelRegistry
.
getDefaultPanelId
());
if
(
!
panelRegistry
.
hasPanel
(
panelToRestore
))
{
if
(
!
panelRegistry
.
hasPanel
(
panelToRestore
))
{
panelToRestore
=
panelRegistry
.
getDefaultPanelId
();
// fallback to default if panel is unknown
panelToRestore
=
panelRegistry
.
getDefaultPanelId
();
// fallback to default if panel is unknown
}
}
...
@@ -1085,19 +1088,24 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1085,19 +1088,24 @@ export class Workbench extends Disposable implements IPartService {
}
}
// Statusbar visibility
// Statusbar visibility
this
.
state
.
statusBar
.
hidden
=
!
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
STATUSBAR_VISIBLE
);
this
.
state
.
statusBar
.
hidden
=
!
configurationService
.
getValue
<
string
>
(
Settings
.
STATUSBAR_VISIBLE
);
// Zen mode enablement
// Zen mode enablement
this
.
state
.
zenMode
.
restore
=
this
.
storageService
.
getBoolean
(
Storage
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
,
false
)
&&
this
.
configurationService
.
getValue
(
Settings
.
ZEN_MODE_RESTORE
);
this
.
state
.
zenMode
.
restore
=
storageService
.
getBoolean
(
Storage
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
,
false
)
&&
configurationService
.
getValue
(
Settings
.
ZEN_MODE_RESTORE
);
}
}
private
resolveEditorsToOpen
():
Promise
<
IResourceEditor
[]
>
|
IResourceEditor
[]
{
private
resolveEditorsToOpen
(
accessor
:
ServicesAccessor
):
Promise
<
IResourceEditor
[]
>
|
IResourceEditor
[]
{
const
configuration
=
accessor
.
get
(
IWindowService
).
getConfiguration
();
const
configurationService
=
accessor
.
get
(
IConfigurationService
);
const
contextService
=
accessor
.
get
(
IWorkspaceContextService
);
const
editorGroupService
=
accessor
.
get
(
IEditorGroupsService
);
const
backupFileService
=
accessor
.
get
(
IBackupFileService
);
// Files to open, diff or create
// Files to open, diff or create
if
(
this
.
hasInitialFilesToOpen
())
{
if
(
this
.
hasInitialFilesToOpen
())
{
// Files to diff is exclusive
// Files to diff is exclusive
const
filesToDiff
=
this
.
toInputs
(
this
.
configuration
.
filesToDiff
,
false
);
const
filesToDiff
=
this
.
toInputs
(
configuration
.
filesToDiff
,
false
);
if
(
filesToDiff
&&
filesToDiff
.
length
===
2
)
{
if
(
filesToDiff
&&
filesToDiff
.
length
===
2
)
{
return
[
<
IResourceDiffInput
>
{
return
[
<
IResourceDiffInput
>
{
leftResource
:
filesToDiff
[
0
].
resource
,
leftResource
:
filesToDiff
[
0
].
resource
,
...
@@ -1107,21 +1115,21 @@ export class Workbench extends Disposable implements IPartService {
...
@@ -1107,21 +1115,21 @@ export class Workbench extends Disposable implements IPartService {
}];
}];
}
}
const
filesToCreate
=
this
.
toInputs
(
this
.
configuration
.
filesToCreate
,
true
);
const
filesToCreate
=
this
.
toInputs
(
configuration
.
filesToCreate
,
true
);
const
filesToOpen
=
this
.
toInputs
(
this
.
configuration
.
filesToOpen
,
false
);
const
filesToOpen
=
this
.
toInputs
(
configuration
.
filesToOpen
,
false
);
// Otherwise: Open/Create files
// Otherwise: Open/Create files
return
[...
filesToOpen
,
...
filesToCreate
];
return
[...
filesToOpen
,
...
filesToCreate
];
}
}
// Empty workbench
// Empty workbench
else
if
(
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
&&
this
.
configurationService
.
inspect
(
'
workbench.startupEditor
'
).
value
===
'
newUntitledFile
'
)
{
else
if
(
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
&&
configurationService
.
inspect
(
'
workbench.startupEditor
'
).
value
===
'
newUntitledFile
'
)
{
const
isEmpty
=
this
.
editorGroupService
.
count
===
1
&&
this
.
editorGroupService
.
activeGroup
.
count
===
0
;
const
isEmpty
=
editorGroupService
.
count
===
1
&&
editorGroupService
.
activeGroup
.
count
===
0
;
if
(
!
isEmpty
)
{
if
(
!
isEmpty
)
{
return
[];
// do not open any empty untitled file if we restored editors from previous session
return
[];
// do not open any empty untitled file if we restored editors from previous session
}
}
return
this
.
backupFileService
.
hasBackups
().
then
(
hasBackups
=>
{
return
backupFileService
.
hasBackups
().
then
(
hasBackups
=>
{
if
(
hasBackups
)
{
if
(
hasBackups
)
{
return
[];
// do not open any empty untitled file if we have backups to restore
return
[];
// do not open any empty untitled file if we have backups to restore
}
}
...
...
src/vs/workbench/services/backup/node/backupFileService.ts
浏览文件 @
c6315a3d
...
@@ -15,6 +15,8 @@ import { ITextBufferFactory } from 'vs/editor/common/model';
...
@@ -15,6 +15,8 @@ import { ITextBufferFactory } from 'vs/editor/common/model';
import
{
createTextBufferFactoryFromStream
,
createTextBufferFactoryFromSnapshot
}
from
'
vs/editor/common/model/textModel
'
;
import
{
createTextBufferFactoryFromStream
,
createTextBufferFactoryFromSnapshot
}
from
'
vs/editor/common/model/textModel
'
;
import
{
keys
}
from
'
vs/base/common/map
'
;
import
{
keys
}
from
'
vs/base/common/map
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
export
interface
IBackupFilesModel
{
export
interface
IBackupFilesModel
{
resolve
(
backupRoot
:
string
):
Promise
<
IBackupFilesModel
>
;
resolve
(
backupRoot
:
string
):
Promise
<
IBackupFilesModel
>
;
...
@@ -107,6 +109,63 @@ export class BackupFilesModel implements IBackupFilesModel {
...
@@ -107,6 +109,63 @@ export class BackupFilesModel implements IBackupFilesModel {
export
class
BackupFileService
implements
IBackupFileService
{
export
class
BackupFileService
implements
IBackupFileService
{
_serviceBrand
:
any
;
private
impl
:
IBackupFileService
;
constructor
(
@
IWindowService
windowService
:
IWindowService
,
@
IFileService
fileService
:
IFileService
)
{
const
backupWorkspacePath
=
windowService
.
getConfiguration
().
backupPath
;
if
(
backupWorkspacePath
)
{
this
.
impl
=
new
BackupFileServiceImpl
(
backupWorkspacePath
,
fileService
);
}
else
{
this
.
impl
=
new
InMemoryBackupFileService
();
}
}
initialize
(
backupWorkspacePath
:
string
):
void
{
if
(
this
.
impl
instanceof
BackupFileServiceImpl
)
{
this
.
impl
.
initialize
(
backupWorkspacePath
);
}
}
hasBackups
():
Promise
<
boolean
>
{
return
this
.
impl
.
hasBackups
();
}
loadBackupResource
(
resource
:
Uri
):
Promise
<
Uri
|
undefined
>
{
return
this
.
impl
.
loadBackupResource
(
resource
);
}
backupResource
(
resource
:
Uri
,
content
:
ITextSnapshot
,
versionId
?:
number
):
Promise
<
void
>
{
return
this
.
impl
.
backupResource
(
resource
,
content
,
versionId
);
}
discardResourceBackup
(
resource
:
Uri
):
Promise
<
void
>
{
return
this
.
impl
.
discardResourceBackup
(
resource
);
}
discardAllWorkspaceBackups
():
Promise
<
void
>
{
return
this
.
impl
.
discardAllWorkspaceBackups
();
}
getWorkspaceFileBackups
():
Promise
<
Uri
[]
>
{
return
this
.
impl
.
getWorkspaceFileBackups
();
}
resolveBackupContent
(
backup
:
Uri
):
Promise
<
ITextBufferFactory
>
{
return
this
.
impl
.
resolveBackupContent
(
backup
);
}
toBackupResource
(
resource
:
Uri
):
Uri
{
return
this
.
impl
.
toBackupResource
(
resource
);
}
}
class
BackupFileServiceImpl
implements
IBackupFileService
{
private
static
readonly
META_MARKER
=
'
\n
'
;
private
static
readonly
META_MARKER
=
'
\n
'
;
_serviceBrand
:
any
;
_serviceBrand
:
any
;
...
@@ -170,7 +229,7 @@ export class BackupFileService implements IBackupFileService {
...
@@ -170,7 +229,7 @@ export class BackupFileService implements IBackupFileService {
}
}
return
this
.
ioOperationQueues
.
queueFor
(
backupResource
).
queue
(()
=>
{
return
this
.
ioOperationQueues
.
queueFor
(
backupResource
).
queue
(()
=>
{
const
preamble
=
`
${
resource
.
toString
()}${
BackupFileService
.
META_MARKER
}
`
;
const
preamble
=
`
${
resource
.
toString
()}${
BackupFileService
Impl
.
META_MARKER
}
`
;
// Update content with value
// Update content with value
return
this
.
fileService
.
updateContent
(
backupResource
,
new
BackupSnapshot
(
content
,
preamble
),
BACKUP_FILE_UPDATE_OPTIONS
).
then
(()
=>
model
.
add
(
backupResource
,
versionId
));
return
this
.
fileService
.
updateContent
(
backupResource
,
new
BackupSnapshot
(
content
,
preamble
),
BACKUP_FILE_UPDATE_OPTIONS
).
then
(()
=>
model
.
add
(
backupResource
,
versionId
));
...
@@ -202,7 +261,7 @@ export class BackupFileService implements IBackupFileService {
...
@@ -202,7 +261,7 @@ export class BackupFileService implements IBackupFileService {
model
.
get
().
forEach
(
fileBackup
=>
{
model
.
get
().
forEach
(
fileBackup
=>
{
readPromises
.
push
(
readPromises
.
push
(
readToMatchingString
(
fileBackup
.
fsPath
,
BackupFileService
.
META_MARKER
,
2000
,
10000
).
then
(
Uri
.
parse
)
readToMatchingString
(
fileBackup
.
fsPath
,
BackupFileService
Impl
.
META_MARKER
,
2000
,
10000
).
then
(
Uri
.
parse
)
);
);
});
});
...
@@ -217,7 +276,7 @@ export class BackupFileService implements IBackupFileService {
...
@@ -217,7 +276,7 @@ export class BackupFileService implements IBackupFileService {
let
metaFound
=
false
;
let
metaFound
=
false
;
const
metaPreambleFilter
=
(
chunk
:
string
)
=>
{
const
metaPreambleFilter
=
(
chunk
:
string
)
=>
{
if
(
!
metaFound
&&
chunk
)
{
if
(
!
metaFound
&&
chunk
)
{
const
metaIndex
=
chunk
.
indexOf
(
BackupFileService
.
META_MARKER
);
const
metaIndex
=
chunk
.
indexOf
(
BackupFileService
Impl
.
META_MARKER
);
if
(
metaIndex
===
-
1
)
{
if
(
metaIndex
===
-
1
)
{
return
''
;
// meta not yet found, return empty string
return
''
;
// meta not yet found, return empty string
}
}
...
@@ -302,3 +361,5 @@ export function hashPath(resource: Uri): string {
...
@@ -302,3 +361,5 @@ export function hashPath(resource: Uri): string {
const
str
=
resource
.
scheme
===
Schemas
.
file
?
resource
.
fsPath
:
resource
.
toString
();
const
str
=
resource
.
scheme
===
Schemas
.
file
?
resource
.
fsPath
:
resource
.
toString
();
return
crypto
.
createHash
(
'
md5
'
).
update
(
str
).
digest
(
'
hex
'
);
return
crypto
.
createHash
(
'
md5
'
).
update
(
str
).
digest
(
'
hex
'
);
}
}
registerSingleton
(
IBackupFileService
,
BackupFileService
);
\ No newline at end of file
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
浏览文件 @
c6315a3d
...
@@ -13,7 +13,7 @@ import { URI as Uri } from 'vs/base/common/uri';
...
@@ -13,7 +13,7 @@ import { URI as Uri } from 'vs/base/common/uri';
import
{
BackupFileService
,
BackupFilesModel
,
hashPath
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
BackupFileService
,
BackupFilesModel
,
hashPath
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
FileService
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
FileService
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
TextModel
,
createTextBufferFactory
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModel
,
createTextBufferFactory
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TestContextService
,
TestTextResourceConfigurationService
,
TestLifecycleService
,
TestEnvironmentService
,
TestStorageService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
TestContextService
,
TestTextResourceConfigurationService
,
TestLifecycleService
,
TestEnvironmentService
,
TestStorageService
,
TestWindowService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
getRandomTestPath
}
from
'
vs/base/test/node/testUtils
'
;
import
{
getRandomTestPath
}
from
'
vs/base/test/node/testUtils
'
;
import
{
TestNotificationService
}
from
'
vs/platform/notification/test/common/testNotificationService
'
;
import
{
TestNotificationService
}
from
'
vs/platform/notification/test/common/testNotificationService
'
;
import
{
Workspace
,
toWorkspaceFolders
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
Workspace
,
toWorkspaceFolders
}
from
'
vs/platform/workspace/common/workspace
'
;
...
@@ -21,6 +21,7 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
...
@@ -21,6 +21,7 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
import
{
DefaultEndOfLine
}
from
'
vs/editor/common/model
'
;
import
{
DefaultEndOfLine
}
from
'
vs/editor/common/model
'
;
import
{
snapshotToString
}
from
'
vs/platform/files/common/files
'
;
import
{
snapshotToString
}
from
'
vs/platform/files/common/files
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
IWindowConfiguration
}
from
'
vs/platform/windows/common/windows
'
;
const
parentDir
=
getRandomTestPath
(
os
.
tmpdir
(),
'
vsctests
'
,
'
backupfileservice
'
);
const
parentDir
=
getRandomTestPath
(
os
.
tmpdir
(),
'
vsctests
'
,
'
backupfileservice
'
);
const
backupHome
=
path
.
join
(
parentDir
,
'
Backups
'
);
const
backupHome
=
path
.
join
(
parentDir
,
'
Backups
'
);
...
@@ -35,11 +36,28 @@ const fooBackupPath = path.join(workspaceBackupPath, 'file', hashPath(fooFile));
...
@@ -35,11 +36,28 @@ const fooBackupPath = path.join(workspaceBackupPath, 'file', hashPath(fooFile));
const
barBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
file
'
,
hashPath
(
barFile
));
const
barBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
file
'
,
hashPath
(
barFile
));
const
untitledBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
untitled
'
,
hashPath
(
untitledFile
));
const
untitledBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
untitled
'
,
hashPath
(
untitledFile
));
class
TestBackupWindowService
extends
TestWindowService
{
private
config
:
IWindowConfiguration
;
constructor
(
workspaceBackupPath
:
string
)
{
super
();
this
.
config
=
Object
.
create
(
null
);
this
.
config
.
backupPath
=
workspaceBackupPath
;
}
getConfiguration
():
IWindowConfiguration
{
return
this
.
config
;
}
}
class
TestBackupFileService
extends
BackupFileService
{
class
TestBackupFileService
extends
BackupFileService
{
constructor
(
workspace
:
Uri
,
backupHome
:
string
,
workspacesJsonPath
:
string
)
{
constructor
(
workspace
:
Uri
,
backupHome
:
string
,
workspacesJsonPath
:
string
)
{
const
fileService
=
new
FileService
(
new
TestContextService
(
new
Workspace
(
workspace
.
fsPath
,
toWorkspaceFolders
([{
path
:
workspace
.
fsPath
}]))),
TestEnvironmentService
,
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
new
TestLifecycleService
(),
new
TestStorageService
(),
new
TestNotificationService
(),
{
disableWatcher
:
true
});
const
fileService
=
new
FileService
(
new
TestContextService
(
new
Workspace
(
workspace
.
fsPath
,
toWorkspaceFolders
([{
path
:
workspace
.
fsPath
}]))),
TestEnvironmentService
,
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
new
TestLifecycleService
(),
new
TestStorageService
(),
new
TestNotificationService
(),
{
disableWatcher
:
true
});
const
windowService
=
new
TestBackupWindowService
(
workspaceBackupPath
);
super
(
w
orkspaceBackupPath
,
fileService
);
super
(
w
indowService
,
fileService
);
}
}
public
toBackupResource
(
resource
:
Uri
):
Uri
{
public
toBackupResource
(
resource
:
Uri
):
Uri
{
...
...
src/vs/workbench/workbench.main.ts
浏览文件 @
c6315a3d
...
@@ -73,6 +73,7 @@ import 'vs/workbench/services/configuration/node/jsonEditingService';
...
@@ -73,6 +73,7 @@ import 'vs/workbench/services/configuration/node/jsonEditingService';
import
'
vs/workbench/services/textmodelResolver/common/textModelResolverService
'
;
import
'
vs/workbench/services/textmodelResolver/common/textModelResolverService
'
;
import
'
vs/workbench/services/textfile/common/textFileService
'
;
import
'
vs/workbench/services/textfile/common/textFileService
'
;
import
'
vs/workbench/services/dialogs/electron-browser/dialogService
'
;
import
'
vs/workbench/services/dialogs/electron-browser/dialogService
'
;
import
'
vs/workbench/services/backup/node/backupFileService
'
;
registerSingleton
(
IMenuService
,
MenuService
,
true
);
registerSingleton
(
IMenuService
,
MenuService
,
true
);
registerSingleton
(
IListService
,
ListService
,
true
);
registerSingleton
(
IListService
,
ListService
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录