Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
0113b40f
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,发现更多精彩内容 >>
提交
0113b40f
编写于
6月 19, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #52212
上级
260ee328
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
83 addition
and
60 deletion
+83
-60
extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts
...vscode-api-tests/src/singlefolder-tests/workspace.test.ts
+7
-11
src/vs/workbench/electron-browser/workbench.ts
src/vs/workbench/electron-browser/workbench.ts
+6
-2
src/vs/workbench/parts/backup/common/backupModelTracker.ts
src/vs/workbench/parts/backup/common/backupModelTracker.ts
+0
-3
src/vs/workbench/parts/backup/common/backupRestorer.ts
src/vs/workbench/parts/backup/common/backupRestorer.ts
+3
-5
src/vs/workbench/services/backup/common/backup.ts
src/vs/workbench/services/backup/common/backup.ts
+0
-5
src/vs/workbench/services/backup/node/backupFileService.ts
src/vs/workbench/services/backup/node/backupFileService.ts
+64
-30
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
...kbench/services/workspace/node/workspaceEditingService.ts
+3
-2
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+0
-2
未找到文件。
extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts
浏览文件 @
0113b40f
...
...
@@ -564,9 +564,8 @@ suite('workspace-namespace', () => {
let
success
=
await
vscode
.
workspace
.
applyEdit
(
edit
);
assert
.
equal
(
success
,
true
);
// todo@ben https://github.com/Microsoft/vscode/issues/52212
// let doc = await vscode.workspace.openTextDocument(newUri);
// assert.equal(doc.getText(), 'AFTERBEFORE');
let
doc
=
await
vscode
.
workspace
.
openTextDocument
(
newUri
);
assert
.
equal
(
doc
.
getText
(),
'
AFTERBEFORE
'
);
});
function
nameWithUnderscore
(
uri
:
vscode
.
Uri
)
{
...
...
@@ -584,9 +583,8 @@ suite('workspace-namespace', () => {
we
.
insert
(
newUri
,
new
vscode
.
Position
(
0
,
0
),
'
Bar
'
);
assert
.
ok
(
await
vscode
.
workspace
.
applyEdit
(
we
));
// todo@ben https://github.com/Microsoft/vscode/issues/52212
// let doc = await vscode.workspace.openTextDocument(newUri);
// assert.equal(doc.getText(), 'BarHelloFoo');
let
doc
=
await
vscode
.
workspace
.
openTextDocument
(
newUri
);
assert
.
equal
(
doc
.
getText
(),
'
BarHelloFoo
'
);
});
test
(
'
WorkspaceEdit: Problem recreating a renamed resource #42634
'
,
async
function
()
{
...
...
@@ -603,9 +601,8 @@ suite('workspace-namespace', () => {
assert
.
ok
(
await
vscode
.
workspace
.
applyEdit
(
we
));
// todo@ben https://github.com/Microsoft/vscode/issues/52212
// let newDoc = await vscode.workspace.openTextDocument(newUri);
// assert.equal(newDoc.getText(), 'HelloFoo');
let
newDoc
=
await
vscode
.
workspace
.
openTextDocument
(
newUri
);
assert
.
equal
(
newDoc
.
getText
(),
'
HelloFoo
'
);
// let doc = await vscode.workspace.openTextDocument(docUri);
// assert.equal(doc.getText(), 'Bar');
});
...
...
@@ -653,8 +650,7 @@ suite('workspace-namespace', () => {
let
doc
=
await
vscode
.
workspace
.
openTextDocument
(
newUri
);
assert
.
ok
(
doc
);
// todo@ben https://github.com/Microsoft/vscode/issues/52212
// assert.equal(doc.getText(), 'Hello');
assert
.
equal
(
doc
.
getText
(),
'
Hello
'
);
});
test
(
'
WorkspaceEdit: rename resource followed by edit does not work #42638
'
,
async
function
()
{
...
...
src/vs/workbench/electron-browser/workbench.ts
浏览文件 @
0113b40f
...
...
@@ -17,7 +17,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import
*
as
browser
from
'
vs/base/browser/browser
'
;
import
*
as
perf
from
'
vs/base/common/performance
'
;
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
{
BackupFileService
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
BackupFileService
,
InMemoryBackupFileService
}
from
'
vs/workbench/services/backup/node/backupFileService
'
;
import
{
IBackupFileService
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
isWindows
,
isLinux
,
isMacintosh
}
from
'
vs/base/common/platform
'
;
...
...
@@ -415,7 +415,11 @@ export class Workbench extends Disposable implements IPartService {
this
.
menubarPart
=
this
.
instantiationService
.
createInstance
(
MenubarPart
,
Identifiers
.
MENUBAR_PART
);
// Backup File Service
this
.
backupFileService
=
this
.
instantiationService
.
createInstance
(
BackupFileService
,
this
.
workbenchParams
.
configuration
.
backupPath
);
if
(
this
.
workbenchParams
.
configuration
.
backupPath
)
{
this
.
backupFileService
=
this
.
instantiationService
.
createInstance
(
BackupFileService
,
this
.
workbenchParams
.
configuration
.
backupPath
);
}
else
{
this
.
backupFileService
=
new
InMemoryBackupFileService
();
}
serviceCollection
.
set
(
IBackupFileService
,
this
.
backupFileService
);
// Text File Service
...
...
src/vs/workbench/parts/backup/common/backupModelTracker.ts
浏览文件 @
0113b40f
...
...
@@ -36,9 +36,6 @@ export class BackupModelTracker implements IWorkbenchContribution {
}
private
registerListeners
()
{
if
(
!
this
.
backupFileService
.
backupEnabled
)
{
return
;
}
// Listen for text file model changes
this
.
toDispose
.
push
(
this
.
textFileService
.
models
.
onModelContentChanged
((
e
)
=>
this
.
onTextFileModelChanged
(
e
)));
...
...
src/vs/workbench/parts/backup/common/backupRestorer.ts
浏览文件 @
0113b40f
...
...
@@ -35,11 +35,9 @@ export class BackupRestorer implements IWorkbenchContribution {
}
private
restoreBackups
():
void
{
if
(
this
.
backupFileService
.
backupEnabled
)
{
this
.
lifecycleService
.
when
(
LifecyclePhase
.
Running
).
then
(()
=>
{
this
.
doRestoreBackups
().
done
(
null
,
errors
.
onUnexpectedError
);
});
}
this
.
lifecycleService
.
when
(
LifecyclePhase
.
Running
).
then
(()
=>
{
this
.
doRestoreBackups
().
done
(
null
,
errors
.
onUnexpectedError
);
});
}
private
doRestoreBackups
():
TPromise
<
URI
[]
>
{
...
...
src/vs/workbench/services/backup/common/backup.ts
浏览文件 @
0113b40f
...
...
@@ -22,11 +22,6 @@ export const BACKUP_FILE_UPDATE_OPTIONS: IUpdateContentOptions = { encoding: 'ut
export
interface
IBackupFileService
{
_serviceBrand
:
any
;
/**
* If backups are enabled.
*/
backupEnabled
:
boolean
;
/**
* Finds out if there are any backups stored.
*/
...
...
src/vs/workbench/services/backup/node/backupFileService.ts
浏览文件 @
0113b40f
...
...
@@ -15,7 +15,8 @@ import { IFileService, ITextSnapshot } from 'vs/platform/files/common/files';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
readToMatchingString
}
from
'
vs/base/node/stream
'
;
import
{
ITextBufferFactory
}
from
'
vs/editor/common/model
'
;
import
{
createTextBufferFactoryFromStream
}
from
'
vs/editor/common/model/textModel
'
;
import
{
createTextBufferFactoryFromStream
,
createTextBufferFactoryFromSnapshot
}
from
'
vs/editor/common/model/textModel
'
;
import
{
keys
}
from
'
vs/base/common/map
'
;
export
interface
IBackupFilesModel
{
resolve
(
backupRoot
:
string
):
TPromise
<
IBackupFilesModel
>
;
...
...
@@ -135,17 +136,9 @@ export class BackupFileService implements IBackupFileService {
this
.
ready
=
this
.
init
();
}
public
get
backupEnabled
():
boolean
{
return
!!
this
.
backupWorkspacePath
;
// Hot exit requires a backup path
}
private
init
():
TPromise
<
IBackupFilesModel
>
{
const
model
=
new
BackupFilesModel
();
if
(
!
this
.
backupEnabled
)
{
return
TPromise
.
as
(
model
);
}
return
model
.
resolve
(
this
.
backupWorkspacePath
);
}
...
...
@@ -157,12 +150,9 @@ export class BackupFileService implements IBackupFileService {
public
loadBackupResource
(
resource
:
Uri
):
TPromise
<
Uri
>
{
return
this
.
ready
.
then
(
model
=>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
!
backupResource
)
{
return
void
0
;
}
// Return directly if we have a known backup with that resource
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
model
.
has
(
backupResource
))
{
return
backupResource
;
}
...
...
@@ -178,10 +168,6 @@ export class BackupFileService implements IBackupFileService {
return
this
.
ready
.
then
(
model
=>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
!
backupResource
)
{
return
void
0
;
}
if
(
model
.
has
(
backupResource
,
versionId
))
{
return
void
0
;
// return early if backup version id matches requested one
}
...
...
@@ -198,9 +184,6 @@ export class BackupFileService implements IBackupFileService {
public
discardResourceBackup
(
resource
:
Uri
):
TPromise
<
void
>
{
return
this
.
ready
.
then
(
model
=>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
!
backupResource
)
{
return
void
0
;
}
return
this
.
ioOperationQueues
.
queueFor
(
backupResource
).
queue
(()
=>
{
return
pfs
.
del
(
backupResource
.
fsPath
).
then
(()
=>
model
.
remove
(
backupResource
));
...
...
@@ -212,10 +195,6 @@ export class BackupFileService implements IBackupFileService {
this
.
isShuttingDown
=
true
;
return
this
.
ready
.
then
(
model
=>
{
if
(
!
this
.
backupEnabled
)
{
return
void
0
;
}
return
pfs
.
del
(
this
.
backupWorkspacePath
).
then
(()
=>
model
.
clear
());
});
}
...
...
@@ -226,8 +205,7 @@ export class BackupFileService implements IBackupFileService {
model
.
get
().
forEach
(
fileBackup
=>
{
readPromises
.
push
(
readToMatchingString
(
fileBackup
.
fsPath
,
BackupFileService
.
META_MARKER
,
2000
,
10000
)
.
then
(
Uri
.
parse
)
readToMatchingString
(
fileBackup
.
fsPath
,
BackupFileService
.
META_MARKER
,
2000
,
10000
).
then
(
Uri
.
parse
)
);
});
...
...
@@ -259,10 +237,6 @@ export class BackupFileService implements IBackupFileService {
}
public
toBackupResource
(
resource
:
Uri
):
Uri
{
if
(
!
this
.
backupEnabled
)
{
return
null
;
}
return
Uri
.
file
(
path
.
join
(
this
.
backupWorkspacePath
,
resource
.
scheme
,
this
.
hashPath
(
resource
)));
}
...
...
@@ -270,3 +244,63 @@ export class BackupFileService implements IBackupFileService {
return
crypto
.
createHash
(
'
md5
'
).
update
(
resource
.
fsPath
).
digest
(
'
hex
'
);
}
}
export
class
InMemoryBackupFileService
implements
IBackupFileService
{
public
_serviceBrand
:
any
;
private
backups
:
Map
<
string
,
ITextSnapshot
>
=
new
Map
();
hasBackups
():
TPromise
<
boolean
>
{
return
TPromise
.
as
(
this
.
backups
.
size
>
0
);
}
loadBackupResource
(
resource
:
Uri
):
TPromise
<
Uri
>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
this
.
backups
.
has
(
backupResource
.
toString
()))
{
return
TPromise
.
as
(
backupResource
);
}
return
TPromise
.
as
(
void
0
);
}
backupResource
(
resource
:
Uri
,
content
:
ITextSnapshot
,
versionId
?:
number
):
TPromise
<
void
>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
this
.
backups
.
set
(
backupResource
.
toString
(),
content
);
return
TPromise
.
as
(
void
0
);
}
resolveBackupContent
(
backupResource
:
Uri
):
TPromise
<
ITextBufferFactory
>
{
const
snapshot
=
this
.
backups
.
get
(
backupResource
.
toString
());
if
(
snapshot
)
{
return
TPromise
.
as
(
createTextBufferFactoryFromSnapshot
(
snapshot
));
}
return
TPromise
.
as
(
void
0
);
}
getWorkspaceFileBackups
():
TPromise
<
Uri
[]
>
{
return
TPromise
.
as
(
keys
(
this
.
backups
).
map
(
key
=>
Uri
.
parse
(
key
)));
}
discardResourceBackup
(
resource
:
Uri
):
TPromise
<
void
>
{
this
.
backups
.
delete
(
this
.
toBackupResource
(
resource
).
toString
());
return
TPromise
.
as
(
void
0
);
}
discardAllWorkspaceBackups
():
TPromise
<
void
>
{
this
.
backups
.
clear
();
return
TPromise
.
as
(
void
0
);
}
toBackupResource
(
resource
:
Uri
):
Uri
{
return
Uri
.
file
(
path
.
join
(
resource
.
scheme
,
this
.
hashPath
(
resource
)));
}
private
hashPath
(
resource
:
Uri
):
string
{
return
crypto
.
createHash
(
'
md5
'
).
update
(
resource
.
fsPath
).
digest
(
'
hex
'
);
}
}
\ No newline at end of file
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
浏览文件 @
0113b40f
...
...
@@ -202,8 +202,9 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
// TODO@Ben TODO@Sandeep the following requires ugly casts and should probably have a service interface
// Reinitialize backup service
const
backupFileService
=
this
.
backupFileService
as
BackupFileService
;
backupFileService
.
initialize
(
result
.
backupPath
);
if
(
this
.
backupFileService
instanceof
BackupFileService
)
{
this
.
backupFileService
.
initialize
(
result
.
backupPath
);
}
// Reinitialize configuration service
const
workspaceImpl
=
this
.
contextService
as
WorkspaceService
;
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
0113b40f
...
...
@@ -871,8 +871,6 @@ export class TestFileService implements IFileService {
export
class
TestBackupFileService
implements
IBackupFileService
{
public
_serviceBrand
:
any
;
public
backupEnabled
:
boolean
;
public
hasBackups
():
TPromise
<
boolean
>
{
return
TPromise
.
as
(
false
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录