Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
ac0e3c61
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,发现更多精彩内容 >>
提交
ac0e3c61
编写于
3月 09, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow bulk edit to change EOL sequences
上级
f52053a7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
52 addition
and
32 deletion
+52
-32
src/vs/editor/common/services/bulkEdit.ts
src/vs/editor/common/services/bulkEdit.ts
+33
-13
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-2
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
+5
-5
src/vs/workbench/api/node/extHostWorkspace.ts
src/vs/workbench/api/node/extHostWorkspace.ts
+2
-2
src/vs/workbench/api/node/mainThreadWorkspace.ts
src/vs/workbench/api/node/mainThreadWorkspace.ts
+2
-2
src/vs/workbench/parts/search/browser/replaceService.ts
src/vs/workbench/parts/search/browser/replaceService.ts
+4
-4
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
...ench/test/node/api/extHostDocumentSaveParticipant.test.ts
+4
-4
未找到文件。
src/vs/editor/common/services/bulkEdit.ts
浏览文件 @
ac0e3c61
...
...
@@ -15,15 +15,26 @@ import { IFileService, IFileChange } from 'vs/platform/files/common/files';
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IIdentifiedSingleEditOperation
,
IModel
,
IRange
,
ISelection
,
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IIdentifiedSingleEditOperation
,
IModel
,
IRange
,
ISelection
,
EndOfLineSequence
,
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IProgressRunner
}
from
'
vs/platform/progress/common/progress
'
;
export
interface
IResourceEdit
{
export
interface
IResource
Text
Edit
{
resource
:
URI
;
range
?:
IRange
;
newText
:
string
;
}
export
interface
IResourceEOLEdit
{
resource
:
URI
;
eol
:
EndOfLineSequence
;
}
export
type
IResourceEdit
=
IResourceTextEdit
|
IResourceEOLEdit
;
function
isIEndOfLineSequenceEdit
(
thing
:
any
):
thing
is
IResourceEOLEdit
{
return
thing
&&
URI
.
isUri
((
<
IResourceEOLEdit
>
thing
).
resource
)
&&
typeof
(
<
IResourceEOLEdit
>
thing
).
eol
===
'
number
'
;
}
interface
IRecording
{
stop
():
void
;
hasChanged
(
resource
:
URI
):
boolean
;
...
...
@@ -74,6 +85,7 @@ class EditTask implements IDisposable {
private
get
_model
():
IModel
{
return
this
.
_modelReference
.
object
.
textEditorModel
;
}
private
_modelReference
:
IReference
<
ITextEditorModel
>
;
private
_edits
:
IIdentifiedSingleEditOperation
[];
private
_newEol
:
EndOfLineSequence
;
constructor
(
modelReference
:
IReference
<
ITextEditorModel
>
)
{
this
.
_endCursorSelection
=
null
;
...
...
@@ -82,23 +94,31 @@ class EditTask implements IDisposable {
}
public
addEdit
(
edit
:
IResourceEdit
):
void
{
let
range
:
IRange
;
if
(
!
edit
.
range
)
{
range
=
this
.
_model
.
getFullModelRange
();
if
(
isIEndOfLineSequenceEdit
(
edit
))
{
// store new EOL-sequence, last wins
this
.
_newEol
=
edit
.
eol
;
}
else
{
range
=
edit
.
range
;
// create edit operation
let
range
:
IRange
;
if
(
!
edit
.
range
)
{
range
=
this
.
_model
.
getFullModelRange
();
}
else
{
range
=
edit
.
range
;
}
this
.
_edits
.
push
(
EditOperation
.
replaceMove
(
Range
.
lift
(
range
),
edit
.
newText
));
}
this
.
_edits
.
push
(
EditOperation
.
replaceMove
(
Range
.
lift
(
range
),
edit
.
newText
));
}
public
apply
():
void
{
if
(
this
.
_edits
.
length
===
0
)
{
return
;
if
(
this
.
_edits
.
length
>
0
)
{
this
.
_edits
.
sort
(
EditTask
.
_editCompare
);
this
.
_initialSelections
=
this
.
_getInitialSelections
();
this
.
_model
.
pushEditOperations
(
this
.
_initialSelections
,
this
.
_edits
,
(
edits
)
=>
this
.
_getEndCursorSelections
(
edits
));
}
if
(
this
.
_newEol
!==
undefined
)
{
this
.
_model
.
setEOL
(
this
.
_newEol
);
}
this
.
_edits
.
sort
(
EditTask
.
_editCompare
);
this
.
_initialSelections
=
this
.
_getInitialSelections
();
this
.
_model
.
pushEditOperations
(
this
.
_initialSelections
,
this
.
_edits
,
(
edits
)
=>
this
.
_getEndCursorSelections
(
edits
));
}
protected
_getInitialSelections
():
Selection
[]
{
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
ac0e3c61
...
...
@@ -26,7 +26,7 @@ import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
IResource
Text
Edit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ITextSource
}
from
'
vs/editor/common/model/textSource
'
;
import
{
ConfigurationTarget
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
...
...
@@ -234,7 +234,7 @@ export abstract class MainThreadWorkspaceShape {
$startSearch
(
include
:
string
,
exclude
:
string
,
maxResults
:
number
,
requestId
:
number
):
Thenable
<
URI
[]
>
{
throw
ni
();
}
$cancelSearch
(
requestId
:
number
):
Thenable
<
boolean
>
{
throw
ni
();
}
$saveAll
(
includeUntitled
?:
boolean
):
Thenable
<
boolean
>
{
throw
ni
();
}
$applyWorkspaceEdit
(
edits
:
IResourceEdit
[]):
TPromise
<
boolean
>
{
throw
ni
();
}
$applyWorkspaceEdit
(
edits
:
IResource
Text
Edit
[]):
TPromise
<
boolean
>
{
throw
ni
();
}
}
export
abstract
class
MainProcessExtensionServiceShape
{
...
...
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
浏览文件 @
ac0e3c61
...
...
@@ -13,7 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
MainThreadWorkspaceShape
,
ExtHostDocumentSaveParticipantShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
TextEdit
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
fromRange
,
TextDocumentSaveReason
}
from
'
vs/workbench/api/node/extHostTypeConverters
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
IResource
Text
Edit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/node/extHostDocuments
'
;
import
{
SaveReason
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
*
as
vscode
from
'
vscode
'
;
...
...
@@ -103,8 +103,8 @@ export class ExtHostDocumentSaveParticipant extends ExtHostDocumentSaveParticipa
const
promises
:
TPromise
<
any
|
vscode
.
TextEdit
[]
>
[]
=
[];
const
{
document
,
reason
}
=
stubEvent
;
const
{
version
}
=
document
;
const
{
document
,
reason
}
=
stubEvent
;
const
{
version
}
=
document
;
const
event
=
Object
.
freeze
(
<
vscode
.
TextDocumentWillSaveEvent
>
{
document
,
...
...
@@ -134,10 +134,10 @@ export class ExtHostDocumentSaveParticipant extends ExtHostDocumentSaveParticipa
}).
then
(
values
=>
{
const
edits
:
IResourceEdit
[]
=
[];
const
edits
:
IResource
Text
Edit
[]
=
[];
for
(
const
value
of
values
)
{
if
(
Array
.
isArray
(
value
)
&&
(
<
vscode
.
TextEdit
[]
>
value
).
every
(
e
=>
e
instanceof
TextEdit
))
{
for
(
const
{
newText
,
range
}
of
value
)
{
for
(
const
{
newText
,
range
}
of
value
)
{
edits
.
push
({
resource
:
<
URI
>
document
.
uri
,
range
:
fromRange
(
range
),
...
...
src/vs/workbench/api/node/extHostWorkspace.ts
浏览文件 @
ac0e3c61
...
...
@@ -8,7 +8,7 @@ import URI from 'vs/base/common/uri';
import
{
normalize
}
from
'
vs/base/common/paths
'
;
import
{
relative
}
from
'
path
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
IResource
Text
Edit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
fromRange
}
from
'
vs/workbench/api/node/extHostTypeConverters
'
;
import
{
MainContext
,
MainThreadWorkspaceShape
}
from
'
./extHost.protocol
'
;
...
...
@@ -70,7 +70,7 @@ export class ExtHostWorkspace {
appyEdit
(
edit
:
vscode
.
WorkspaceEdit
):
TPromise
<
boolean
>
{
let
resourceEdits
:
IResourceEdit
[]
=
[];
let
resourceEdits
:
IResource
Text
Edit
[]
=
[];
let
entries
=
edit
.
entries
();
for
(
let
entry
of
entries
)
{
...
...
src/vs/workbench/api/node/mainThreadWorkspace.ts
浏览文件 @
ac0e3c61
...
...
@@ -10,7 +10,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
bulkEdit
,
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
bulkEdit
,
IResource
Text
Edit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Uri
}
from
'
vscode
'
;
import
{
MainThreadWorkspaceShape
}
from
'
./extHost.protocol
'
;
...
...
@@ -89,7 +89,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
});
}
$applyWorkspaceEdit
(
edits
:
IResourceEdit
[]):
TPromise
<
boolean
>
{
$applyWorkspaceEdit
(
edits
:
IResource
Text
Edit
[]):
TPromise
<
boolean
>
{
let
codeEditor
:
ICommonCodeEditor
;
let
editor
=
this
.
_editorService
.
getActiveEditor
();
...
...
src/vs/workbench/parts/search/browser/replaceService.ts
浏览文件 @
ac0e3c61
...
...
@@ -15,7 +15,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
Match
,
FileMatch
,
FileMatchOrMatch
,
ISearchWorkbenchService
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
BulkEdit
,
IResourceEdit
,
createBulkEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
BulkEdit
,
IResource
Text
Edit
,
createBulkEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
IProgressRunner
}
from
'
vs/platform/progress/common/progress
'
;
import
{
IDiffEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
...
...
@@ -182,13 +182,13 @@ export class ReplaceService implements IReplaceService {
});
}
private
createEdit
(
match
:
Match
,
text
:
string
,
resource
:
URI
=
null
):
IResourceEdit
{
private
createEdit
(
match
:
Match
,
text
:
string
,
resource
:
URI
=
null
):
IResource
Text
Edit
{
let
fileMatch
:
FileMatch
=
match
.
parent
();
let
resourceEdit
:
IResourceEdit
=
{
let
resourceEdit
:
IResource
Text
Edit
=
{
resource
:
resource
!==
null
?
resource
:
fileMatch
.
resource
(),
range
:
match
.
range
(),
newText
:
text
};
return
resourceEdit
;
}
}
\ No newline at end of file
}
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
浏览文件 @
ac0e3c61
...
...
@@ -13,7 +13,7 @@ import { TextDocumentSaveReason, TextEdit, Position } from 'vs/workbench/api/nod
import
{
MainThreadWorkspaceShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
ExtHostDocumentSaveParticipant
}
from
'
vs/workbench/api/node/extHostDocumentSaveParticipant
'
;
import
{
OneGetThreadService
}
from
'
./testThreadService
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
IResource
Text
Edit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
SaveReason
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
*
as
vscode
from
'
vscode
'
;
...
...
@@ -252,7 +252,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test
(
'
event delivery, pushEdits sync
'
,
()
=>
{
let
edits
:
IResourceEdit
[];
let
edits
:
IResource
Text
Edit
[];
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
new
class
extends
MainThreadWorkspaceShape
{
$applyWorkspaceEdit
(
_edits
)
{
edits
=
_edits
;
...
...
@@ -273,7 +273,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test
(
'
event delivery, concurrent change
'
,
()
=>
{
let
edits
:
IResourceEdit
[];
let
edits
:
IResource
Text
Edit
[];
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
new
class
extends
MainThreadWorkspaceShape
{
$applyWorkspaceEdit
(
_edits
)
{
edits
=
_edits
;
...
...
@@ -306,7 +306,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test
(
'
event delivery, two listeners -> two document states
'
,
()
=>
{
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
new
class
extends
MainThreadWorkspaceShape
{
$applyWorkspaceEdit
(
_edits
:
IResourceEdit
[])
{
$applyWorkspaceEdit
(
_edits
:
IResource
Text
Edit
[])
{
for
(
const
{
resource
,
newText
,
range
}
of
_edits
)
{
documents
.
$acceptModelChanged
(
resource
.
toString
(),
[{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录