Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
0d3b5da0
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,发现更多精彩内容 >>
提交
0d3b5da0
编写于
1月 17, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bulk - refactor much to be prepared for WorkspaceEditMetadata
上级
367c81a3
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
157 addition
and
146 deletion
+157
-146
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+18
-3
src/vs/editor/standalone/browser/simpleServices.ts
src/vs/editor/standalone/browser/simpleServices.ts
+2
-1
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+17
-7
src/vs/workbench/api/browser/mainThreadEditors.ts
src/vs/workbench/api/browser/mainThreadEditors.ts
+1
-1
src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
+1
-1
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+11
-14
src/vs/workbench/api/common/extHostDocumentSaveParticipant.ts
...vs/workbench/api/common/extHostDocumentSaveParticipant.ts
+11
-13
src/vs/workbench/api/common/extHostFileSystemEventService.ts
src/vs/workbench/api/common/extHostFileSystemEventService.ts
+2
-2
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+13
-12
src/vs/workbench/api/common/extHostTypes.ts
src/vs/workbench/api/common/extHostTypes.ts
+3
-3
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
+5
-15
src/vs/workbench/contrib/search/browser/replaceService.ts
src/vs/workbench/contrib/search/browser/replaceService.ts
+6
-6
src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts
...vs/workbench/services/bulkEdit/browser/bulkEditService.ts
+30
-25
src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts
...ectron-browser/api/extHostDocumentSaveParticipant.test.ts
+18
-22
src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts
...test/electron-browser/api/extHostLanguageFeatures.test.ts
+0
-2
src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts
.../workbench/test/electron-browser/api/extHostTypes.test.ts
+9
-8
src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts
...bench/test/electron-browser/api/mainThreadEditors.test.ts
+10
-11
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
0d3b5da0
...
...
@@ -1257,20 +1257,35 @@ export namespace WorkspaceTextEdit {
* @internal
*/
export
function
is
(
thing
:
any
):
thing
is
WorkspaceTextEdit
{
return
isObject
(
thing
)
&&
(
<
WorkspaceTextEdit
>
thing
).
resource
&&
Array
.
isArray
((
<
WorkspaceTextEdit
>
thing
).
edits
);
return
isObject
(
thing
)
&&
URI
.
isUri
((
<
WorkspaceTextEdit
>
thing
).
resource
)
&&
isObject
((
<
WorkspaceTextEdit
>
thing
).
edit
);
}
}
export
interface
WorkspaceEditMetadata
{
needsConfirmation
:
boolean
;
label
:
string
;
description
?:
string
;
}
export
interface
WorkspaceFileEditOptions
{
overwrite
?:
boolean
;
ignoreIfNotExists
?:
boolean
;
ignoreIfExists
?:
boolean
;
recursive
?:
boolean
;
}
export
interface
WorkspaceFileEdit
{
oldUri
?:
URI
;
newUri
?:
URI
;
options
?:
{
overwrite
?:
boolean
,
ignoreIfNotExists
?:
boolean
,
ignoreIfExists
?:
boolean
,
recursive
?:
boolean
};
options
?:
WorkspaceFileEditOptions
;
metadata
?:
WorkspaceEditMetadata
;
}
export
interface
WorkspaceTextEdit
{
resource
:
URI
;
edit
:
TextEdit
;
modelVersionId
?:
number
;
edits
:
TextEdit
[]
;
metadata
?:
WorkspaceEditMetadata
;
}
export
interface
WorkspaceEdit
{
...
...
src/vs/editor/standalone/browser/simpleServices.ts
浏览文件 @
0d3b5da0
...
...
@@ -655,8 +655,9 @@ export class SimpleBulkEditService implements IBulkEditService {
let
array
=
edits
.
get
(
model
);
if
(
!
array
)
{
array
=
[];
edits
.
set
(
model
,
array
);
}
edits
.
set
(
model
,
array
.
concat
(
edit
.
edits
)
);
array
.
push
(
edit
.
edit
);
}
}
...
...
src/vs/monaco.d.ts
浏览文件 @
0d3b5da0
...
...
@@ -5897,21 +5897,31 @@ declare namespace monaco.languages {
constructor
(
value
:
string
);
}
export
interface
WorkspaceEditMetadata
{
needsConfirmation
:
boolean
;
label
:
string
;
description
?:
string
;
}
export
interface
WorkspaceFileEditOptions
{
overwrite
?:
boolean
;
ignoreIfNotExists
?:
boolean
;
ignoreIfExists
?:
boolean
;
recursive
?:
boolean
;
}
export
interface
WorkspaceFileEdit
{
oldUri
?:
Uri
;
newUri
?:
Uri
;
options
?:
{
overwrite
?:
boolean
;
ignoreIfNotExists
?:
boolean
;
ignoreIfExists
?:
boolean
;
recursive
?:
boolean
;
};
options
?:
WorkspaceFileEditOptions
;
metadata
?:
WorkspaceEditMetadata
;
}
export
interface
WorkspaceTextEdit
{
resource
:
Uri
;
edit
:
TextEdit
;
modelVersionId
?:
number
;
edits
:
TextEdit
[]
;
metadata
?:
WorkspaceEditMetadata
;
}
export
interface
WorkspaceEdit
{
...
...
src/vs/workbench/api/browser/mainThreadEditors.ts
浏览文件 @
0d3b5da0
...
...
@@ -216,7 +216,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
}
$tryApplyWorkspaceEdit
(
dto
:
IWorkspaceEditDto
):
Promise
<
boolean
>
{
const
{
edits
}
=
reviveWorkspaceEditDto
(
dto
);
const
{
edits
}
=
reviveWorkspaceEditDto
(
dto
)
!
;
return
this
.
_bulkEditService
.
apply
({
edits
}).
then
(()
=>
true
,
_err
=>
false
);
}
...
...
src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
浏览文件 @
0d3b5da0
...
...
@@ -316,7 +316,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
$registerRenameSupport
(
handle
:
number
,
selector
:
IDocumentFilterDto
[],
supportResolveLocation
:
boolean
):
void
{
this
.
_registrations
.
set
(
handle
,
modes
.
RenameProviderRegistry
.
register
(
selector
,
<
modes
.
RenameProvider
>
{
provideRenameEdits
:
(
model
:
ITextModel
,
position
:
EditorPosition
,
newName
:
string
,
token
:
CancellationToken
)
:
Promise
<
modes
.
WorkspaceEdit
>
=>
{
provideRenameEdits
:
(
model
:
ITextModel
,
position
:
EditorPosition
,
newName
:
string
,
token
:
CancellationToken
)
=>
{
return
this
.
_proxy
.
$provideRenameEdits
(
handle
,
model
.
uri
,
position
,
newName
,
token
).
then
(
reviveWorkspaceEditDto
);
},
resolveRenameLocation
:
supportResolveLocation
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
0d3b5da0
...
...
@@ -1068,25 +1068,22 @@ export interface IWorkspaceSymbolsDto extends IdObject {
symbols
:
IWorkspaceSymbolDto
[];
}
export
interface
I
Resour
ceFileEditDto
{
export
interface
I
Workspa
ceFileEditDto
{
oldUri
?:
UriComponents
;
newUri
?:
UriComponents
;
options
?:
{
overwrite
?:
boolean
;
ignoreIfExists
?:
boolean
;
ignoreIfNotExists
?:
boolean
;
recursive
?:
boolean
;
};
options
?:
modes
.
WorkspaceFileEditOptions
metadata
?:
modes
.
WorkspaceEditMetadata
;
}
export
interface
I
Resour
ceTextEditDto
{
export
interface
I
Workspa
ceTextEditDto
{
resource
:
UriComponents
;
edit
:
modes
.
TextEdit
;
modelVersionId
?:
number
;
edits
:
modes
.
TextEdit
[]
;
metadata
?:
modes
.
WorkspaceEditMetadata
;
}
export
interface
IWorkspaceEditDto
{
edits
:
Array
<
I
ResourceFileEditDto
|
IResour
ceTextEditDto
>
;
edits
:
Array
<
I
WorkspaceFileEditDto
|
IWorkspa
ceTextEditDto
>
;
// todo@joh reject should go into rename
rejectReason
?:
string
;
...
...
@@ -1095,11 +1092,11 @@ export interface IWorkspaceEditDto {
export
function
reviveWorkspaceEditDto
(
data
:
IWorkspaceEditDto
|
undefined
):
modes
.
WorkspaceEdit
{
if
(
data
&&
data
.
edits
)
{
for
(
const
edit
of
data
.
edits
)
{
if
(
typeof
(
<
I
Resour
ceTextEditDto
>
edit
).
resource
===
'
object
'
)
{
(
<
I
ResourceTextEditDto
>
edit
).
resource
=
URI
.
revive
((
<
IResour
ceTextEditDto
>
edit
).
resource
);
if
(
typeof
(
<
I
Workspa
ceTextEditDto
>
edit
).
resource
===
'
object
'
)
{
(
<
I
WorkspaceTextEditDto
>
edit
).
resource
=
URI
.
revive
((
<
IWorkspa
ceTextEditDto
>
edit
).
resource
);
}
else
{
(
<
I
ResourceFileEditDto
>
edit
).
newUri
=
URI
.
revive
((
<
IResour
ceFileEditDto
>
edit
).
newUri
);
(
<
I
ResourceFileEditDto
>
edit
).
oldUri
=
URI
.
revive
((
<
IResour
ceFileEditDto
>
edit
).
oldUri
);
(
<
I
WorkspaceFileEditDto
>
edit
).
newUri
=
URI
.
revive
((
<
IWorkspa
ceFileEditDto
>
edit
).
newUri
);
(
<
I
WorkspaceFileEditDto
>
edit
).
oldUri
=
URI
.
revive
((
<
IWorkspa
ceFileEditDto
>
edit
).
oldUri
);
}
}
}
...
...
src/vs/workbench/api/common/extHostDocumentSaveParticipant.ts
浏览文件 @
0d3b5da0
...
...
@@ -7,7 +7,7 @@ import { Event } from 'vs/base/common/event';
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
import
{
illegalState
}
from
'
vs/base/common/errors
'
;
import
{
ExtHostDocumentSaveParticipantShape
,
MainThreadTextEditorsShape
,
I
ResourceText
EditDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostDocumentSaveParticipantShape
,
MainThreadTextEditorsShape
,
I
Workspace
EditDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
TextEdit
}
from
'
vs/workbench/api/common/extHostTypes
'
;
import
{
Range
,
TextDocumentSaveReason
,
EndOfLine
}
from
'
vs/workbench/api/common/extHostTypeConverters
'
;
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/common/extHostDocuments
'
;
...
...
@@ -141,19 +141,17 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
});
}).
then
(
values
=>
{
const
resourceEdit
:
IResourceTextEditDto
=
{
resource
:
document
.
uri
,
edits
:
[]
};
const
dto
:
IWorkspaceEditDto
=
{
edits
:
[]
};
for
(
const
value
of
values
)
{
if
(
Array
.
isArray
(
value
)
&&
(
<
vscode
.
TextEdit
[]
>
value
).
every
(
e
=>
e
instanceof
TextEdit
))
{
for
(
const
{
newText
,
newEol
,
range
}
of
value
)
{
resourceEdit
.
edits
.
push
({
range
:
range
&&
Range
.
from
(
range
),
text
:
newText
,
eol
:
newEol
&&
EndOfLine
.
from
(
newEol
)
dto
.
edits
.
push
({
resource
:
document
.
uri
,
edit
:
{
range
:
range
&&
Range
.
from
(
range
),
text
:
newText
,
eol
:
newEol
&&
EndOfLine
.
from
(
newEol
)
}
});
}
}
...
...
@@ -161,12 +159,12 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
// apply edits if any and if document
// didn't change somehow in the meantime
if
(
resourceEdit
.
edits
.
length
===
0
)
{
if
(
dto
.
edits
.
length
===
0
)
{
return
undefined
;
}
if
(
version
===
document
.
version
)
{
return
this
.
_mainThreadEditors
.
$tryApplyWorkspaceEdit
(
{
edits
:
[
resourceEdit
]
}
);
return
this
.
_mainThreadEditors
.
$tryApplyWorkspaceEdit
(
dto
);
}
return
Promise
.
reject
(
new
Error
(
'
concurrent_edits
'
));
...
...
src/vs/workbench/api/common/extHostFileSystemEventService.ts
浏览文件 @
0d3b5da0
...
...
@@ -8,7 +8,7 @@ import { IRelativePattern, parse } from 'vs/base/common/glob';
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
type
*
as
vscode
from
'
vscode
'
;
import
{
ExtHostFileSystemEventServiceShape
,
FileSystemEvents
,
IMainContext
,
MainContext
,
MainThreadTextEditorsShape
,
I
ResourceFileEditDto
,
IResour
ceTextEditDto
}
from
'
./extHost.protocol
'
;
import
{
ExtHostFileSystemEventServiceShape
,
FileSystemEvents
,
IMainContext
,
MainContext
,
MainThreadTextEditorsShape
,
I
WorkspaceFileEditDto
,
IWorkspa
ceTextEditDto
}
from
'
./extHost.protocol
'
;
import
*
as
typeConverter
from
'
./extHostTypeConverters
'
;
import
{
Disposable
,
WorkspaceEdit
}
from
'
./extHostTypes
'
;
import
{
IExtensionDescription
}
from
'
vs/platform/extensions/common/extensions
'
;
...
...
@@ -219,7 +219,7 @@ export class ExtHostFileSystemEventService implements ExtHostFileSystemEventServ
if
(
edits
.
length
>
0
)
{
// flatten all WorkspaceEdits collected via waitUntil-call
// and apply them in one go.
const
allEdits
=
new
Array
<
Array
<
I
ResourceFileEditDto
|
IResour
ceTextEditDto
>>
();
const
allEdits
=
new
Array
<
Array
<
I
WorkspaceFileEditDto
|
IWorkspa
ceTextEditDto
>>
();
for
(
let
edit
of
edits
)
{
let
{
edits
}
=
typeConverter
.
WorkspaceEdit
.
from
(
edit
,
this
.
_extHostDocumentsAndEditors
);
allEdits
.
push
(
edits
);
...
...
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
0d3b5da0
...
...
@@ -485,13 +485,13 @@ export namespace WorkspaceEdit {
};
for
(
const
entry
of
(
value
as
types
.
WorkspaceEdit
).
_allEntries
())
{
const
[
uri
,
uriOrEdits
]
=
entry
;
if
(
Array
.
isArray
(
uriOrEdits
))
{
if
(
URI
.
isUri
(
uriOrEdits
)
||
uriOrEdits
===
undefined
)
{
// resource edits
result
.
edits
.
push
(
<
extHostProtocol
.
IWorkspaceFileEditDto
>
{
oldUri
:
uri
,
newUri
:
uriOrEdits
,
options
:
entry
[
2
]
});
}
else
{
// text edits
const
doc
=
documents
&&
uri
?
documents
.
getDocument
(
uri
)
:
undefined
;
result
.
edits
.
push
(
<
extHostProtocol
.
IResourceTextEditDto
>
{
resource
:
uri
,
modelVersionId
:
doc
&&
doc
.
version
,
edits
:
uriOrEdits
.
map
(
TextEdit
.
from
)
});
}
else
{
// resource edits
result
.
edits
.
push
(
<
extHostProtocol
.
IResourceFileEditDto
>
{
oldUri
:
uri
,
newUri
:
uriOrEdits
,
options
:
entry
[
2
]
});
result
.
edits
.
push
(
<
extHostProtocol
.
IWorkspaceTextEditDto
>
{
resource
:
uri
,
modelVersionId
:
doc
&&
doc
.
version
,
edit
:
TextEdit
.
from
(
uriOrEdits
)
});
}
}
return
result
;
...
...
@@ -500,16 +500,17 @@ export namespace WorkspaceEdit {
export
function
to
(
value
:
extHostProtocol
.
IWorkspaceEditDto
)
{
const
result
=
new
types
.
WorkspaceEdit
();
for
(
const
edit
of
value
.
edits
)
{
if
(
Array
.
isArray
((
<
extHostProtocol
.
IResourceTextEditDto
>
edit
).
edits
))
{
result
.
set
(
URI
.
revive
((
<
extHostProtocol
.
IResourceTextEditDto
>
edit
).
resource
),
<
types
.
TextEdit
[]
>
(
<
extHostProtocol
.
IResourceTextEditDto
>
edit
).
edits
.
map
(
TextEdit
.
to
)
if
((
<
extHostProtocol
.
IWorkspaceTextEditDto
>
edit
).
edit
)
{
result
.
replace
(
URI
.
revive
((
<
extHostProtocol
.
IWorkspaceTextEditDto
>
edit
).
resource
),
Range
.
to
((
<
extHostProtocol
.
IWorkspaceTextEditDto
>
edit
).
edit
.
range
),
(
<
extHostProtocol
.
IWorkspaceTextEditDto
>
edit
).
edit
.
text
);
}
else
{
result
.
renameFile
(
URI
.
revive
((
<
extHostProtocol
.
I
Resour
ceFileEditDto
>
edit
).
oldUri
!
),
URI
.
revive
((
<
extHostProtocol
.
I
Resour
ceFileEditDto
>
edit
).
newUri
!
),
(
<
extHostProtocol
.
I
Resour
ceFileEditDto
>
edit
).
options
URI
.
revive
((
<
extHostProtocol
.
I
Workspa
ceFileEditDto
>
edit
).
oldUri
!
),
URI
.
revive
((
<
extHostProtocol
.
I
Workspa
ceFileEditDto
>
edit
).
newUri
!
),
(
<
extHostProtocol
.
I
Workspa
ceFileEditDto
>
edit
).
options
);
}
}
...
...
src/vs/workbench/api/common/extHostTypes.ts
浏览文件 @
0d3b5da0
...
...
@@ -663,13 +663,13 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
return
values
(
textEdits
);
}
_allEntries
():
([
URI
,
TextEdit
[]
]
|
[
URI
?,
URI
?,
IFileOperationOptions
?])[]
{
const
res
:
([
URI
,
TextEdit
[]
]
|
[
URI
?,
URI
?,
IFileOperationOptions
?])[]
=
[];
_allEntries
():
([
URI
,
TextEdit
]
|
[
URI
?,
URI
?,
IFileOperationOptions
?])[]
{
const
res
:
([
URI
,
TextEdit
]
|
[
URI
?,
URI
?,
IFileOperationOptions
?])[]
=
[];
for
(
let
edit
of
this
.
_edits
)
{
if
(
edit
.
_type
===
1
)
{
res
.
push
([
edit
.
from
,
edit
.
to
,
edit
.
options
]);
}
else
{
res
.
push
([
edit
.
uri
,
[
edit
.
edit
]
]);
res
.
push
([
edit
.
uri
,
edit
.
edit
]);
}
}
return
res
;
...
...
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
浏览文件 @
0d3b5da0
...
...
@@ -73,7 +73,7 @@ export class BulkFileOperation extends CheckedObject {
this
.
type
+=
type
;
this
.
originalEdits
.
set
(
index
,
edit
);
if
(
WorkspaceTextEdit
.
is
(
edit
))
{
this
.
textEdits
=
this
.
textEdits
.
concat
(
edit
.
edits
.
map
(
edit
=>
new
BulkTextEdit
(
this
,
edit
,
this
.
_emitter
)
));
this
.
textEdits
.
push
(
new
BulkTextEdit
(
this
,
edit
.
edit
,
this
.
_emitter
));
}
else
if
(
type
===
BulkFileOperationType
.
Rename
)
{
this
.
newUri
=
edit
.
newUri
;
...
...
@@ -194,23 +194,13 @@ export class BulkFileOperations {
file
.
originalEdits
.
forEach
((
value
,
idx
)
=>
{
if
(
WorkspaceTextEdit
.
is
(
value
))
{
let
newValue
:
WorkspaceTextEdit
=
{
...
value
,
edits
:
[]
};
let
allEditsAccepted
=
true
;
for
(
let
edit
of
value
.
edits
)
{
if
(
!
checkedEdits
.
has
(
keyOfEdit
(
edit
)))
{
allEditsAccepted
=
false
;
}
else
{
newValue
.
edits
.
push
(
edit
);
}
}
if
(
!
allEditsAccepted
)
{
value
=
newValue
;
allAccepted
=
false
;
}
if
(
WorkspaceTextEdit
.
is
(
value
)
&&
!
checkedEdits
.
has
(
keyOfEdit
(
value
.
edit
)))
{
allAccepted
=
false
;
return
;
}
result
.
edits
[
idx
]
=
value
;
});
}
if
(
!
allAccepted
)
{
...
...
src/vs/workbench/contrib/search/browser/replaceService.ts
浏览文件 @
0d3b5da0
...
...
@@ -165,10 +165,10 @@ export class ReplaceService implements IReplaceService {
const
resourceEdits
=
this
.
createEdits
(
fileMatch
,
replaceModel
.
uri
);
const
modelEdits
:
IIdentifiedSingleEditOperation
[]
=
[];
for
(
const
resourceEdit
of
resourceEdits
)
{
for
(
const
edit
of
resourceEdit
.
edits
)
{
const
range
=
Range
.
lift
(
edit
.
range
);
modelEdits
.
push
(
EditOperation
.
replaceMove
(
range
,
edit
.
text
));
}
modelEdits
.
push
(
EditOperation
.
replaceMove
(
Range
.
lift
(
resourceEdit
.
edit
.
range
),
resourceEdit
.
edit
.
text
)
);
}
replaceModel
.
pushEditOperations
([],
mergeSort
(
modelEdits
,
(
a
,
b
)
=>
Range
.
compareRangesUsingStarts
(
a
.
range
,
b
.
range
)),
()
=>
[]);
}
...
...
@@ -201,10 +201,10 @@ export class ReplaceService implements IReplaceService {
const
fileMatch
:
FileMatch
=
match
.
parent
();
const
resourceEdit
:
WorkspaceTextEdit
=
{
resource
:
resource
!==
null
?
resource
:
fileMatch
.
resource
,
edit
s
:
[
{
edit
:
{
range
:
match
.
range
(),
text
:
text
}
]
}
};
return
resourceEdit
;
}
...
...
src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts
浏览文件 @
0d3b5da0
...
...
@@ -49,29 +49,29 @@ class ModelEditTask implements IDisposable {
addEdit
(
resourceEdit
:
WorkspaceTextEdit
):
void
{
this
.
_expectedModelVersionId
=
resourceEdit
.
modelVersionId
;
for
(
const
edit
of
resourceEdit
.
edits
)
{
if
(
typeof
edit
.
eol
===
'
number
'
)
{
// honor eol-change
this
.
_newEol
=
edit
.
eol
;
}
if
(
!
edit
.
range
&&
!
edit
.
text
)
{
// lacks both a range and the text
continue
;
}
if
(
Range
.
isEmpty
(
edit
.
range
)
&&
!
edit
.
text
)
{
// no-op edit (replace empty range with empty text)
continue
;
}
const
{
edit
}
=
resourceEdit
;
// create edit operation
let
range
:
Range
;
if
(
!
edit
.
range
)
{
range
=
this
.
_model
.
getFullModelRange
();
}
else
{
range
=
Range
.
lift
(
edit
.
range
);
}
this
.
_edits
.
push
(
EditOperation
.
replaceMove
(
range
,
edit
.
text
));
if
(
typeof
edit
.
eol
===
'
number
'
)
{
// honor eol-change
this
.
_newEol
=
edit
.
eol
;
}
if
(
!
edit
.
range
&&
!
edit
.
text
)
{
// lacks both a range and the text
return
;
}
if
(
Range
.
isEmpty
(
edit
.
range
)
&&
!
edit
.
text
)
{
// no-op edit (replace empty range with empty text)
return
;
}
// create edit operation
let
range
:
Range
;
if
(
!
edit
.
range
)
{
range
=
this
.
_model
.
getFullModelRange
();
}
else
{
range
=
Range
.
lift
(
edit
.
range
);
}
this
.
_edits
.
push
(
EditOperation
.
replaceMove
(
range
,
edit
.
text
));
}
validate
():
ValidationResult
{
...
...
@@ -180,9 +180,14 @@ class BulkEditModel implements IDisposable {
for
(
const
edit
of
value
)
{
if
(
makeMinimal
)
{
const
newEdits
=
await
this
.
_editorWorker
.
computeMoreMinimalEdits
(
edit
.
resource
,
edit
.
edits
);
task
.
addEdit
({
...
edit
,
edits
:
newEdits
??
edit
.
edits
});
const
newEdits
=
await
this
.
_editorWorker
.
computeMoreMinimalEdits
(
edit
.
resource
,
[
edit
.
edit
]);
if
(
!
newEdits
)
{
task
.
addEdit
(
edit
);
}
else
{
for
(
let
moreMinialEdit
of
newEdits
)
{
task
.
addEdit
({
...
edit
,
edit
:
moreMinialEdit
});
}
}
}
else
{
task
.
addEdit
(
edit
);
}
...
...
@@ -243,7 +248,7 @@ class BulkEdit {
}
ariaMessage
():
string
{
const
editCount
=
this
.
_edits
.
reduce
((
prev
,
cur
)
=>
WorkspaceFileEdit
.
is
(
cur
)
?
prev
:
prev
+
cur
.
edits
.
length
,
0
)
;
const
editCount
=
this
.
_edits
.
length
;
const
resourceCount
=
this
.
_edits
.
length
;
if
(
editCount
===
0
)
{
return
localize
(
'
summary.0
'
,
"
Made no edits
"
);
...
...
src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts
浏览文件 @
0d3b5da0
...
...
@@ -7,14 +7,13 @@ import { URI } from 'vs/base/common/uri';
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/common/extHostDocuments
'
;
import
{
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
TextDocumentSaveReason
,
TextEdit
,
Position
,
EndOfLine
}
from
'
vs/workbench/api/common/extHostTypes
'
;
import
{
MainThreadTextEditorsShape
,
IWorkspaceEditDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
MainThreadTextEditorsShape
,
IWorkspaceEditDto
,
IWorkspaceTextEditDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostDocumentSaveParticipant
}
from
'
vs/workbench/api/common/extHostDocumentSaveParticipant
'
;
import
{
SingleProxyRPCProtocol
}
from
'
./testRPCProtocol
'
;
import
{
SaveReason
}
from
'
vs/workbench/common/editor
'
;
import
type
*
as
vscode
from
'
vscode
'
;
import
{
mock
}
from
'
vs/workbench/test/electron-browser/api/mock
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
import
{
WorkspaceTextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
ExtensionIdentifier
,
IExtensionDescription
}
from
'
vs/platform/extensions/common/extensions
'
;
...
...
@@ -278,9 +277,9 @@ suite('ExtHostDocumentSaveParticipant', () => {
return
participant
.
$participateInSave
(
resource
,
SaveReason
.
EXPLICIT
).
then
(()
=>
{
sub
.
dispose
();
assert
.
equal
(
dto
.
edits
.
length
,
1
);
assert
.
ok
(
WorkspaceTextEdit
.
is
(
dto
.
edits
[
0
])
);
assert
.
equal
((
<
WorkspaceTextEdit
>
dto
.
edits
[
0
]).
edits
.
length
,
2
);
assert
.
equal
(
dto
.
edits
.
length
,
2
);
assert
.
ok
(
(
<
IWorkspaceTextEditDto
>
dto
.
edits
[
0
]).
edit
);
assert
.
ok
((
<
IWorkspaceTextEditDto
>
dto
.
edits
[
1
]).
edit
);
});
});
...
...
@@ -326,23 +325,20 @@ suite('ExtHostDocumentSaveParticipant', () => {
$tryApplyWorkspaceEdit
(
dto
:
IWorkspaceEditDto
)
{
for
(
const
edit
of
dto
.
edits
)
{
if
(
!
WorkspaceTextEdit
.
is
(
edit
))
{
continue
;
}
const
{
resource
,
edits
}
=
edit
;
const
uri
=
URI
.
revive
(
resource
);
for
(
const
{
text
,
range
}
of
edits
)
{
documents
.
$acceptModelChanged
(
uri
,
{
changes
:
[{
range
,
text
,
rangeOffset
:
undefined
!
,
rangeLength
:
undefined
!
,
}],
eol
:
undefined
!
,
versionId
:
documents
.
getDocumentData
(
uri
)
!
.
version
+
1
},
true
);
}
const
uri
=
URI
.
revive
((
<
IWorkspaceTextEditDto
>
edit
).
resource
);
const
{
text
,
range
}
=
(
<
IWorkspaceTextEditDto
>
edit
).
edit
;
documents
.
$acceptModelChanged
(
uri
,
{
changes
:
[{
range
,
text
,
rangeOffset
:
undefined
!
,
rangeLength
:
undefined
!
,
}],
eol
:
undefined
!
,
versionId
:
documents
.
getDocumentData
(
uri
)
!
.
version
+
1
},
true
);
// }
}
return
Promise
.
resolve
(
true
);
...
...
src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts
浏览文件 @
0d3b5da0
...
...
@@ -759,8 +759,6 @@ suite('ExtHostLanguageFeatures', function () {
const
value
=
await
rename
(
model
,
new
EditorPosition
(
1
,
1
),
'
newName
'
);
// least relevant rename provider
assert
.
equal
(
value
.
edits
.
length
,
2
);
assert
.
equal
((
<
modes
.
WorkspaceTextEdit
>
value
.
edits
[
0
]).
edits
.
length
,
1
);
assert
.
equal
((
<
modes
.
WorkspaceTextEdit
>
value
.
edits
[
1
]).
edits
.
length
,
1
);
});
// --- parameter hints
...
...
src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts
浏览文件 @
0d3b5da0
...
...
@@ -7,6 +7,7 @@ import * as assert from 'assert';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
*
as
types
from
'
vs/workbench/api/common/extHostTypes
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
isObject
}
from
'
vs/base/common/types
'
;
function
assertToJSON
(
a
:
any
,
expected
:
any
)
{
const
raw
=
JSON
.
stringify
(
a
);
...
...
@@ -386,30 +387,30 @@ suite('ExtHostTypes', function () {
const
all
=
edit
.
_allEntries
();
assert
.
equal
(
all
.
length
,
4
);
function
isFileChange
(
thing
:
[
URI
,
types
.
TextEdit
[]
]
|
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]):
thing
is
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]
{
function
isFileChange
(
thing
:
[
URI
,
types
.
TextEdit
]
|
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]):
thing
is
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]
{
const
[
f
,
s
]
=
thing
;
return
URI
.
isUri
(
f
)
&&
URI
.
isUri
(
s
);
}
function
isTextChange
(
thing
:
[
URI
,
types
.
TextEdit
[]]
|
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]):
thing
is
[
URI
,
types
.
TextEdit
[]
]
{
function
isTextChange
(
thing
:
[
URI
,
types
.
TextEdit
]
|
[
URI
?,
URI
?,
{
overwrite
?:
boolean
}?]):
thing
is
[
URI
,
types
.
TextEdit
]
{
const
[
f
,
s
]
=
thing
;
return
URI
.
isUri
(
f
)
&&
Array
.
isArray
(
s
);
return
URI
.
isUri
(
f
)
&&
isObject
(
s
);
}
const
[
first
,
second
,
third
,
fourth
]
=
all
;
assert
.
equal
(
first
[
0
]
!
.
toString
(),
'
foo:a
'
);
assert
.
ok
(
!
isFileChange
(
first
));
assert
.
ok
(
isTextChange
(
first
)
&&
first
[
1
].
length
===
1
);
assert
.
ok
(
isTextChange
(
first
));
assert
.
equal
(
second
[
0
]
!
.
toString
(),
'
foo:a
'
);
assert
.
ok
(
isFileChange
(
second
));
assert
.
equal
(
third
[
0
]
!
.
toString
(),
'
foo:a
'
);
assert
.
ok
(
isTextChange
(
third
)
&&
third
[
1
].
length
===
1
);
assert
.
ok
(
isTextChange
(
third
));
assert
.
equal
(
fourth
[
0
]
!
.
toString
(),
'
foo:b
'
);
assert
.
ok
(
!
isFileChange
(
fourth
));
assert
.
ok
(
isTextChange
(
fourth
)
&&
fourth
[
1
].
length
===
1
);
assert
.
ok
(
isTextChange
(
fourth
));
});
test
(
'
WorkspaceEdit - two edits for one resource
'
,
function
()
{
...
...
@@ -420,8 +421,8 @@ suite('ExtHostTypes', function () {
assert
.
equal
(
edit
.
_allEntries
().
length
,
2
);
let
[
first
,
second
]
=
edit
.
_allEntries
();
assert
.
equal
((
first
as
[
URI
,
types
.
TextEdit
[]])[
1
][
0
].
newText
,
'
Hello
'
);
assert
.
equal
((
second
as
[
URI
,
types
.
TextEdit
[]])[
1
][
0
].
newText
,
'
Foo
'
);
assert
.
equal
((
first
as
[
URI
,
types
.
TextEdit
])[
1
].
newText
,
'
Hello
'
);
assert
.
equal
((
second
as
[
URI
,
types
.
TextEdit
])[
1
].
newText
,
'
Foo
'
);
});
test
(
'
DocumentLink
'
,
()
=>
{
...
...
src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts
浏览文件 @
0d3b5da0
...
...
@@ -10,7 +10,7 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
import
{
TestCodeEditorService
}
from
'
vs/editor/test/browser/editorTestServices
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
ExtHostDocumentsAndEditorsShape
,
ExtHostContext
,
ExtHostDocumentsShape
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostDocumentsAndEditorsShape
,
ExtHostContext
,
ExtHostDocumentsShape
,
IWorkspaceTextEditDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
mock
}
from
'
vs/workbench/test/electron-browser/api/mock
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
MainThreadTextEditors
}
from
'
vs/workbench/api/browser/mainThreadEditors
'
;
...
...
@@ -20,7 +20,6 @@ import { Position } from 'vs/editor/common/core/position';
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
TestFileService
,
TestEditorService
,
TestEditorGroupsService
,
TestEnvironmentService
,
TestContextService
,
TestTextResourcePropertiesService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
WorkspaceTextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
BulkEditService
}
from
'
vs/workbench/services/bulkEdit/browser/bulkEditService
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
import
{
ITextModelService
,
IResolvedTextEditorModel
}
from
'
vs/editor/common/services/resolverService
'
;
...
...
@@ -141,13 +140,13 @@ suite('MainThreadEditors', () => {
let
model
=
modelService
.
createModel
(
'
something
'
,
null
,
resource
);
let
workspaceResourceEdit
:
WorkspaceTextEdit
=
{
let
workspaceResourceEdit
:
IWorkspaceTextEditDto
=
{
resource
:
resource
,
modelVersionId
:
model
.
getVersionId
(),
edit
s
:
[
{
edit
:
{
text
:
'
asdfg
'
,
range
:
new
Range
(
1
,
1
,
1
,
1
)
}
]
}
};
// Act as if the user edited the model
...
...
@@ -162,21 +161,21 @@ suite('MainThreadEditors', () => {
let
model
=
modelService
.
createModel
(
'
something
'
,
null
,
resource
);
let
workspaceResourceEdit1
:
WorkspaceTextEdit
=
{
let
workspaceResourceEdit1
:
IWorkspaceTextEditDto
=
{
resource
:
resource
,
modelVersionId
:
model
.
getVersionId
(),
edit
s
:
[
{
edit
:
{
text
:
'
asdfg
'
,
range
:
new
Range
(
1
,
1
,
1
,
1
)
}
]
}
};
let
workspaceResourceEdit2
:
WorkspaceTextEdit
=
{
let
workspaceResourceEdit2
:
IWorkspaceTextEditDto
=
{
resource
:
resource
,
modelVersionId
:
model
.
getVersionId
(),
edit
s
:
[
{
edit
:
{
text
:
'
asdfg
'
,
range
:
new
Range
(
1
,
1
,
1
,
1
)
}
]
}
};
let
p1
=
editors
.
$tryApplyWorkspaceEdit
({
edits
:
[
workspaceResourceEdit1
]
}).
then
((
result
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录