Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ea79f0a9
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,发现更多精彩内容 >>
提交
ea79f0a9
编写于
1月 15, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
untitled - reduce service methods
上级
c5fb0adc
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
52 addition
and
81 deletion
+52
-81
src/vs/workbench/contrib/backup/test/electron-browser/backupOnShutdown.test.ts
...rib/backup/test/electron-browser/backupOnShutdown.test.ts
+0
-3
src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts
...ntrib/backup/test/electron-browser/backupRestorer.test.ts
+2
-1
src/vs/workbench/contrib/backup/test/electron-browser/backupTracker.test.ts
...ontrib/backup/test/electron-browser/backupTracker.test.ts
+0
-1
src/vs/workbench/services/textfile/browser/textFileService.ts
...vs/workbench/services/textfile/browser/textFileService.ts
+27
-7
src/vs/workbench/services/textfile/test/textFileService.io.test.ts
...rkbench/services/textfile/test/textFileService.io.test.ts
+1
-4
src/vs/workbench/services/textfile/test/textFileService.test.ts
.../workbench/services/textfile/test/textFileService.test.ts
+2
-1
src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts
...s/textmodelResolver/test/textModelResolverService.test.ts
+1
-1
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
...nch/services/untitled/common/untitledTextEditorService.ts
+0
-54
src/vs/workbench/test/common/editor/editor.test.ts
src/vs/workbench/test/common/editor/editor.test.ts
+1
-3
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
...s/workbench/test/common/editor/untitledTextEditor.test.ts
+18
-6
未找到文件。
src/vs/workbench/contrib/backup/test/electron-browser/backupOnShutdown.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -11,7 +11,6 @@ import { toResource } from 'vs/base/test/common/utils';
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/services/textfile/common/textFileEditorModel
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
IUntitledTextEditorService
}
from
'
vs/workbench/services/untitled/common/untitledTextEditorService
'
;
import
{
HotExitConfiguration
,
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
TextFileEditorModelManager
}
from
'
vs/workbench/services/textfile/common/textFileEditorModelManager
'
;
import
{
IWorkspaceContextService
,
Workspace
}
from
'
vs/platform/workspace/common/workspace
'
;
...
...
@@ -29,7 +28,6 @@ class ServiceAccessor {
@
ILifecycleService
public
lifecycleService
:
TestLifecycleService
,
@
ITextFileService
public
textFileService
:
TestTextFileService
,
@
IFilesConfigurationService
public
filesConfigurationService
:
TestFilesConfigurationService
,
@
IUntitledTextEditorService
public
untitledTextEditorService
:
IUntitledTextEditorService
,
@
IWorkspaceContextService
public
contextService
:
TestContextService
,
@
IModelService
public
modelService
:
ModelServiceImpl
,
@
IFileService
public
fileService
:
TestFileService
,
...
...
@@ -69,7 +67,6 @@ suite('BackupOnShutdown', () => {
model
.
dispose
();
}
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
backupOnShutdown
.
dispose
();
});
...
...
src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -87,7 +87,6 @@ suite('BackupRestorer', () => {
disposables
=
[];
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
return
pfs
.
rimraf
(
backupHome
,
pfs
.
RimRafMode
.
MOVE
);
});
...
...
@@ -132,10 +131,12 @@ suite('BackupRestorer', () => {
if
(
isEqual
(
resource
,
untitledFile1
))
{
const
model
=
await
accessor
.
untitledTextEditorService
.
createOrGet
(
resource
).
resolve
();
assert
.
equal
(
model
.
textEditorModel
.
getValue
(),
'
untitled-1
'
);
model
.
dispose
();
counter
++
;
}
else
if
(
isEqual
(
resource
,
untitledFile2
))
{
const
model
=
await
accessor
.
untitledTextEditorService
.
createOrGet
(
resource
).
resolve
();
assert
.
equal
(
model
.
textEditorModel
.
getValue
(),
'
untitled-2
'
);
model
.
dispose
();
counter
++
;
}
else
if
(
isEqual
(
resource
,
fooFile
))
{
const
model
=
await
accessor
.
textFileService
.
models
.
get
(
resource
!
)?.
load
();
...
...
src/vs/workbench/contrib/backup/test/electron-browser/backupTracker.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -93,7 +93,6 @@ suite('BackupTracker', () => {
disposables
=
[];
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
return
pfs
.
rimraf
(
backupHome
,
pfs
.
RimRafMode
.
MOVE
);
});
...
...
src/vs/workbench/services/textfile/browser/textFileService.ts
浏览文件 @
ea79f0a9
...
...
@@ -592,7 +592,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
}
private
suggestFileName
(
untitledResource
:
URI
):
URI
{
const
untitledFileName
=
this
.
untitledTextEditorService
.
suggestFileN
ame
(
untitledResource
);
const
untitledFileName
=
this
.
untitledTextEditorService
.
exists
(
untitledResource
)
?
this
.
untitledTextEditorService
.
createOrGet
(
untitledResource
).
suggestFileName
()
:
basen
ame
(
untitledResource
);
const
remoteAuthority
=
this
.
environmentService
.
configuration
.
remoteAuthority
;
const
schemeFilter
=
remoteAuthority
?
Schemas
.
vscodeRemote
:
Schemas
.
file
;
...
...
@@ -618,19 +618,23 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
return
!
(
await
this
.
doRevertAll
([
resource
],
options
)).
results
.
some
(
result
=>
result
.
error
);
}
private
async
doRevertAll
(
resources
?
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
private
async
doRevertAll
(
resources
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
// Revert files first
const
revertOperationResult
=
await
this
.
doRevertAllFiles
(
resources
,
options
);
const
revert
File
OperationResult
=
await
this
.
doRevertAllFiles
(
resources
,
options
);
// Revert untitled
const
untitledReverted
=
this
.
untitledTextEditorService
.
revertAll
(
resources
);
untitledReverted
.
forEach
(
untitled
=>
revertOperationResult
.
results
.
push
({
source
:
untitled
}));
const
revertUntitledOperationResult
=
await
this
.
doRevertAllUntitled
(
resources
,
options
);
return
revertOperationResult
;
return
{
results
:
[
...
revertFileOperationResult
.
results
,
...
revertUntitledOperationResult
.
results
]
};
}
private
async
doRevertAllFiles
(
resources
?
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
private
async
doRevertAllFiles
(
resources
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
const
fileModels
=
options
?.
force
?
this
.
getFileModels
(
resources
)
:
this
.
getDirtyFileModels
(
resources
);
const
mapResourceToResult
=
new
ResourceMap
<
IResult
>
();
...
...
@@ -668,6 +672,22 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
return
{
results
:
mapResourceToResult
.
values
()
};
}
private
async
doRevertAllUntitled
(
resources
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
const
result
:
ITextFileOperationResult
=
{
results
:
[]
};
await
Promise
.
all
(
resources
.
map
(
resource
=>
{
if
(
this
.
untitledTextEditorService
.
exists
(
resource
))
{
result
.
results
.
push
({
source
:
resource
});
return
this
.
untitledTextEditorService
.
createOrGet
(
resource
).
revert
(
options
);
}
return
Promise
.
resolve
(
undefined
);
}));
return
result
;
}
//#endregion
//#region dirty
...
...
src/vs/workbench/services/textfile/test/textFileService.io.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -6,7 +6,6 @@ import * as assert from 'assert';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
workbenchInstantiationService
,
TestTextFileService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
ITextFileService
,
snapshotToString
,
TextFileOperationResult
,
TextFileOperationError
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
IUntitledTextEditorService
}
from
'
vs/workbench/services/untitled/common/untitledTextEditorService
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
TextFileEditorModelManager
}
from
'
vs/workbench/services/textfile/common/textFileEditorModelManager
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
...
...
@@ -31,8 +30,7 @@ import { detectEncodingByBOM } from 'vs/base/test/node/encoding/encoding.test';
class
ServiceAccessor
{
constructor
(
@
ITextFileService
public
textFileService
:
TestTextFileService
,
@
IUntitledTextEditorService
public
untitledTextEditorService
:
IUntitledTextEditorService
@
ITextFileService
public
textFileService
:
TestTextFileService
)
{
}
}
...
...
@@ -95,7 +93,6 @@ suite('Files - TextFileService i/o', () => {
teardown
(
async
()
=>
{
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
disposables
.
clear
();
...
...
src/vs/workbench/services/textfile/test/textFileService.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -53,7 +53,6 @@ suite('Files - TextFileService', () => {
model
.
dispose
();
}
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
});
test
(
'
isDirty/getDirty - files and untitled
'
,
async
function
()
{
...
...
@@ -79,6 +78,8 @@ suite('Files - TextFileService', () => {
assert
.
ok
(
accessor
.
textFileService
.
isDirty
(
untitled
.
getResource
()));
assert
.
equal
(
accessor
.
textFileService
.
getDirty
().
length
,
2
);
assert
.
equal
(
accessor
.
textFileService
.
getDirty
([
untitled
.
getResource
()])[
0
].
toString
(),
untitled
.
getResource
().
toString
());
untitledModel
.
dispose
();
});
test
(
'
save - file
'
,
async
function
()
{
...
...
src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -49,7 +49,6 @@ suite('Workbench - TextModelResolverService', () => {
model
=
(
undefined
)
!
;
}
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
dispose
();
accessor
.
untitledTextEditorService
.
revertAll
();
});
test
(
'
resolve resource
'
,
async
()
=>
{
...
...
@@ -120,6 +119,7 @@ suite('Workbench - TextModelResolverService', () => {
assert
.
ok
(
editorModel
);
ref
.
dispose
();
input
.
dispose
();
model
.
dispose
();
});
test
(
'
even loading documents should be refcounted
'
,
async
()
=>
{
...
...
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
浏览文件 @
ea79f0a9
...
...
@@ -14,7 +14,6 @@ import { ResourceMap } from 'vs/base/common/map';
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
basename
}
from
'
vs/base/common/resources
'
;
export
const
IUntitledTextEditorService
=
createDecorator
<
IUntitledTextEditorService
>
(
'
untitledTextEditorService
'
);
...
...
@@ -60,16 +59,6 @@ export interface IUntitledTextEditorService {
*/
isDirty
(
resource
:
URI
):
boolean
;
/**
* Find out if a backup with the provided resource exists and has a backup on disk.
*/
hasBackup
(
resource
:
URI
):
boolean
;
/**
* Reverts the untitled resources if found.
*/
revertAll
(
resources
?:
URI
[]):
URI
[];
/**
* Creates a new untitled input with the optional resource URI or returns an existing one
* if the provided resource exists already as untitled input.
...
...
@@ -84,16 +73,6 @@ export interface IUntitledTextEditorService {
* A check to find out if a untitled resource has a file path associated or not.
*/
hasAssociatedFilePath
(
resource
:
URI
):
boolean
;
/**
* Suggests a filename for the given untitled resource if it is known.
*/
suggestFileName
(
resource
:
URI
):
string
;
/**
* Get the configured encoding for the given untitled resource if any.
*/
getEncoding
(
resource
:
URI
):
string
|
undefined
;
}
export
class
UntitledTextEditorService
extends
Disposable
implements
IUntitledTextEditorService
{
...
...
@@ -136,33 +115,12 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
this
.
mapResourceToInput
.
has
(
resource
);
}
revertAll
(
resources
?:
URI
[],
force
?:
boolean
):
URI
[]
{
const
reverted
:
URI
[]
=
[];
const
untitledInputs
=
this
.
getAll
(
resources
);
untitledInputs
.
forEach
(
input
=>
{
if
(
input
)
{
input
.
revert
();
reverted
.
push
(
input
.
getResource
());
}
});
return
reverted
;
}
isDirty
(
resource
:
URI
):
boolean
{
const
input
=
this
.
get
(
resource
);
return
input
?
input
.
isDirty
()
:
false
;
}
hasBackup
(
resource
:
URI
):
boolean
{
const
input
=
this
.
get
(
resource
);
return
input
?
input
.
hasBackup
()
:
false
;
}
getDirty
(
resources
?:
URI
[]):
URI
[]
{
let
inputs
:
UntitledTextEditorInput
[];
if
(
resources
)
{
...
...
@@ -253,18 +211,6 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
hasAssociatedFilePath
(
resource
:
URI
):
boolean
{
return
this
.
mapResourceToAssociatedFilePath
.
has
(
resource
);
}
suggestFileName
(
resource
:
URI
):
string
{
const
input
=
this
.
get
(
resource
);
return
input
?
input
.
suggestFileName
()
:
basename
(
resource
);
}
getEncoding
(
resource
:
URI
):
string
|
undefined
{
const
input
=
this
.
get
(
resource
);
return
input
?
input
.
getEncoding
()
:
undefined
;
}
}
registerSingleton
(
IUntitledTextEditorService
,
UntitledTextEditorService
,
true
);
src/vs/workbench/test/common/editor/editor.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -14,8 +14,7 @@ import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestSe
import
{
Schemas
}
from
'
vs/base/common/network
'
;
class
ServiceAccessor
{
constructor
(@
IUntitledTextEditorService
public
untitledTextEditorService
:
UntitledTextEditorService
)
{
}
constructor
(@
IUntitledTextEditorService
public
untitledTextEditorService
:
UntitledTextEditorService
)
{
}
}
class
FileEditorInput
extends
EditorInput
{
...
...
@@ -48,7 +47,6 @@ suite('Workbench editor', () => {
});
teardown
(()
=>
{
accessor
.
untitledTextEditorService
.
revertAll
();
accessor
.
untitledTextEditorService
.
dispose
();
});
...
...
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
浏览文件 @
ea79f0a9
...
...
@@ -44,7 +44,6 @@ suite('Workbench untitled text editors', () => {
});
teardown
(()
=>
{
accessor
.
untitledTextEditorService
.
revertAll
();
accessor
.
untitledTextEditorService
.
dispose
();
});
...
...
@@ -67,8 +66,8 @@ suite('Workbench untitled text editors', () => {
assert
.
equal
(
service
.
getAll
().
length
,
2
);
assert
.
equal
(
service
.
getAll
([
input1
.
getResource
(),
input2
.
getResource
()]).
length
,
2
);
// revert
All
()
service
.
revertAll
([
input1
.
getResource
()]
);
// revert()
input1
.
revert
(
);
assert
.
ok
(
input1
.
isDisposed
());
assert
.
equal
(
service
.
getAll
().
length
,
1
);
...
...
@@ -90,7 +89,8 @@ suite('Workbench untitled text editors', () => {
assert
.
ok
(
workingCopyService
.
isDirty
(
input2
.
getResource
()));
assert
.
equal
(
workingCopyService
.
dirtyCount
,
1
);
service
.
revertAll
();
input1
.
revert
();
input2
.
revert
();
assert
.
equal
(
service
.
getAll
().
length
,
0
);
assert
.
ok
(
!
input2
.
isDirty
());
assert
.
ok
(
!
model
.
isDirty
());
...
...
@@ -109,6 +109,9 @@ suite('Workbench untitled text editors', () => {
});
model
.
textEditorModel
.
setValue
(
'
foo bar
'
);
model
.
dispose
();
input1
.
dispose
();
input2
.
dispose
();
});
test
(
'
Untitled with associated resource is dirty
'
,
()
=>
{
...
...
@@ -136,6 +139,7 @@ suite('Workbench untitled text editors', () => {
assert
.
ok
(
!
model
.
isDirty
());
assert
.
ok
(
!
workingCopyService
.
isDirty
(
model
.
resource
));
input
.
dispose
();
model
.
dispose
();
});
test
(
'
Untitled via createOrGet options
'
,
async
()
=>
{
...
...
@@ -174,7 +178,8 @@ suite('Workbench untitled text editors', () => {
const
service
=
accessor
.
untitledTextEditorService
;
const
input
=
service
.
createOrGet
();
assert
.
ok
(
service
.
suggestFileName
(
input
.
getResource
()));
assert
.
ok
(
input
.
suggestFileName
().
length
>
0
);
input
.
dispose
();
});
test
(
'
Untitled with associated path remains dirty when content gets empty
'
,
async
()
=>
{
...
...
@@ -189,6 +194,7 @@ suite('Workbench untitled text editors', () => {
model
.
textEditorModel
.
setValue
(
''
);
assert
.
ok
(
model
.
isDirty
());
input
.
dispose
();
model
.
dispose
();
});
test
(
'
Untitled with initial content is dirty
'
,
async
()
=>
{
...
...
@@ -211,6 +217,7 @@ suite('Workbench untitled text editors', () => {
untitled
.
dispose
();
listener
.
dispose
();
model
.
dispose
();
});
test
(
'
Untitled created with files.defaultLanguage setting
'
,
()
=>
{
...
...
@@ -281,6 +288,7 @@ suite('Workbench untitled text editors', () => {
assert
.
equal
(
input
.
getMode
(),
PLAINTEXT_MODE_ID
);
input
.
dispose
();
model
.
dispose
();
});
test
(
'
encoding change event
'
,
async
()
=>
{
...
...
@@ -299,6 +307,7 @@ suite('Workbench untitled text editors', () => {
model
.
setEncoding
(
'
utf16
'
);
assert
.
equal
(
counter
,
1
);
input
.
dispose
();
model
.
dispose
();
});
test
(
'
onDidChangeContent event
'
,
async
function
()
{
...
...
@@ -324,6 +333,7 @@ suite('Workbench untitled text editors', () => {
assert
.
equal
(
counter
,
4
,
'
Dirty model should trigger event
'
);
input
.
dispose
();
model
.
dispose
();
});
test
(
'
onDidChangeDirty event
'
,
async
function
()
{
...
...
@@ -343,6 +353,7 @@ suite('Workbench untitled text editors', () => {
assert
.
equal
(
counter
,
1
,
'
Another change does not fire event
'
);
input
.
dispose
();
model
.
dispose
();
});
test
(
'
onDidDisposeModel event
'
,
async
()
=>
{
...
...
@@ -356,9 +367,10 @@ suite('Workbench untitled text editors', () => {
assert
.
equal
(
r
.
toString
(),
input
.
getResource
().
toString
());
});
await
input
.
resolve
();
const
model
=
await
input
.
resolve
();
assert
.
equal
(
counter
,
0
);
input
.
dispose
();
assert
.
equal
(
counter
,
1
);
model
.
dispose
();
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录