Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3c817c7f
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,发现更多精彩内容 >>
提交
3c817c7f
编写于
1月 17, 2017
作者:
J
Joel Day
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Insert snippet API changes.
上级
f7587b3e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
63 addition
and
62 deletion
+63
-62
extensions/vscode-api-tests/src/editor.test.ts
extensions/vscode-api-tests/src/editor.test.ts
+8
-3
src/vs/editor/contrib/snippet/common/snippetController.ts
src/vs/editor/contrib/snippet/common/snippetController.ts
+0
-5
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+5
-7
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+5
-7
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-2
src/vs/workbench/api/node/extHostEditors.ts
src/vs/workbench/api/node/extHostEditors.ts
+13
-22
src/vs/workbench/api/node/extHostTypes.ts
src/vs/workbench/api/node/extHostTypes.ts
+10
-0
src/vs/workbench/api/node/mainThreadEditors.ts
src/vs/workbench/api/node/mainThreadEditors.ts
+4
-4
src/vs/workbench/api/node/mainThreadEditorsTracker.ts
src/vs/workbench/api/node/mainThreadEditorsTracker.ts
+16
-12
未找到文件。
extensions/vscode-api-tests/src/editor.test.ts
浏览文件 @
3c817c7f
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
workspace
,
window
,
Position
,
Range
,
commands
,
TextEditor
,
TextDocument
,
TextEditorCursorStyle
,
TextEditorLineNumbersStyle
,
SnippetString
}
from
'
vscode
'
;
import
{
workspace
,
window
,
Position
,
Range
,
commands
,
TextEditor
,
TextDocument
,
TextEditorCursorStyle
,
TextEditorLineNumbersStyle
,
SnippetString
,
Selection
}
from
'
vscode
'
;
import
{
createRandomFile
,
deleteFile
,
cleanUp
}
from
'
./utils
'
;
suite
(
'
editor tests
'
,
()
=>
{
...
...
@@ -41,7 +41,7 @@ suite('editor tests', () => {
.
appendText
(
'
snippet
'
);
return
withRandomFileEditor
(
''
,
(
editor
,
doc
)
=>
{
return
editor
.
insertSnippet
(
snippetString
.
value
,
new
Position
(
0
,
0
)
).
then
(
inserted
=>
{
return
editor
.
edit
(
snippetString
).
then
(
inserted
=>
{
assert
.
ok
(
inserted
);
assert
.
equal
(
doc
.
getText
(),
'
This is a placeholder snippet
'
);
assert
.
ok
(
doc
.
isDirty
);
...
...
@@ -54,7 +54,12 @@ suite('editor tests', () => {
.
appendText
(
'
has been
'
);
return
withRandomFileEditor
(
'
This will be replaced
'
,
(
editor
,
doc
)
=>
{
return
editor
.
insertSnippet
(
snippetString
.
value
,
new
Range
(
0
,
5
,
0
,
12
)).
then
(
inserted
=>
{
editor
.
selection
=
new
Selection
(
new
Position
(
0
,
4
),
new
Position
(
0
,
12
)
);
return
editor
.
edit
(
snippetString
).
then
(
inserted
=>
{
assert
.
ok
(
inserted
);
assert
.
equal
(
doc
.
getText
(),
'
This has been replaced
'
);
assert
.
ok
(
doc
.
isDirty
);
...
...
src/vs/editor/contrib/snippet/common/snippetController.ts
浏览文件 @
3c817c7f
...
...
@@ -476,11 +476,6 @@ export class SnippetController {
this
.
run
(
snippet
,
overwriteBefore
,
overwriteAfter
);
}
public
insertSnippetWithReplaceRange
(
template
:
string
,
replaceRange
:
Range
):
void
{
const
snippet
=
CodeSnippet
.
fromTextmate
(
template
,
this
.
_variableResolver
);
this
.
runWithReplaceRange
(
snippet
,
replaceRange
);
}
public
run
(
snippet
:
CodeSnippet
,
overwriteBefore
:
number
,
overwriteAfter
:
number
,
stripPrefix
?:
boolean
):
void
{
this
.
_runAndRestoreController
(()
=>
{
if
(
snippet
.
isInsertOnly
||
snippet
.
isSingleTabstopOnly
)
{
...
...
src/vs/vscode.d.ts
浏览文件 @
3c817c7f
...
...
@@ -937,15 +937,13 @@ declare module 'vscode' {
edit
(
callback
:
(
editBuilder
:
TextEditorEdit
)
=>
void
,
options
?:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}):
Thenable
<
boolean
>
;
/**
*
Inserts the given snippet template and enters snippet mode
.
*
Enters snippet mode in the editor with the specified snippet
.
*
* If the editor is already in snippet mode, insertion fails and the returned promise resolves to false.
*
* @param template The snippet template to insert
* @param posOrRange The position or replacement range representing the location of the insertion.
* @return A promise that resolves with a value indicating if the snippet could be inserted.
* @param snippet The snippet to insert
* @param options The undo/redo behaviour around this edit. By default, undo stops will be created before and after this edit.
* @return A promise that resolves with a value indicating if the editor entered snippet mode.
*/
insertSnippet
(
template
:
string
,
posOrRange
:
Position
|
Range
):
Thenable
<
boolean
>
;
edit
(
snippet
:
SnippetString
,
options
?:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
):
Thenable
<
boolean
>
;
/**
* Adds a set of decorations to the text editor. If a set of decorations already exists with
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
3c817c7f
...
...
@@ -110,15 +110,13 @@ declare module 'vscode' {
export
interface
TextEditor
{
/**
*
Inserts the given snippet template and enters snippet mode
.
*
Enters snippet mode in the editor with the specified snippet
.
*
* If the editor is already in snippet mode, insertion fails and the returned promise resolves to false.
*
* @param template The snippet template to insert
* @param posOrRange The position or replacement range representing the location of the insertion.
* @return A promise that resolves with a value indicating if the snippet could be inserted.
* @param snippet The snippet to insert
* @param options The undo/redo behaviour around this edit. By default, undo stops will be created before and after this edit.
* @return A promise that resolves with a value indicating if the editor entered snippet mode.
*/
insertSnippet
(
template
:
string
,
posOrRange
:
Position
|
Range
):
Thenable
<
boolean
>
;
edit
(
snippet
:
SnippetString
,
options
?:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
):
Thenable
<
boolean
>
;
}
export
interface
SCMResourceThemableDecorations
{
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
3c817c7f
...
...
@@ -34,7 +34,7 @@ import { IWorkspaceConfigurationValues } from 'vs/workbench/services/configurati
import
{
IPickOpenEntry
,
IPickOptions
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
SaveReason
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
IWorkspaceSymbol
}
from
'
vs/workbench/parts/search/common/search
'
;
import
{
IApplyEditsOptions
,
TextEditorRevealType
,
ITextEditorConfigurationUpdate
,
IResolvedTextEditorConfiguration
,
ISelectionChangeEvent
}
from
'
./mainThreadEditorsTracker
'
;
import
{
IApplyEditsOptions
,
IInsertSnippetOptions
,
TextEditorRevealType
,
ITextEditorConfigurationUpdate
,
IResolvedTextEditorConfiguration
,
ISelectionChangeEvent
}
from
'
./mainThreadEditorsTracker
'
;
import
{
InternalTreeExplorerNodeContent
}
from
'
vs/workbench/parts/explorers/common/treeExplorerViewModel
'
;
...
...
@@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape {
$tryRevealRange
(
id
:
string
,
range
:
editorCommon
.
IRange
,
revealType
:
TextEditorRevealType
):
TPromise
<
any
>
{
throw
ni
();
}
$trySetSelections
(
id
:
string
,
selections
:
editorCommon
.
ISelection
[]):
TPromise
<
any
>
{
throw
ni
();
}
$tryApplyEdits
(
id
:
string
,
modelVersionId
:
number
,
edits
:
editorCommon
.
ISingleEditOperation
[],
opts
:
IApplyEditsOptions
):
TPromise
<
boolean
>
{
throw
ni
();
}
$tryInsertSnippet
(
id
:
string
,
template
:
string
,
posOrRange
:
editorCommon
.
IPosition
|
editorCommon
.
IRange
):
TPromise
<
boolean
>
{
throw
ni
();
}
$tryInsertSnippet
(
id
:
string
,
template
:
string
,
opts
:
IInsertSnippetOptions
):
TPromise
<
boolean
>
{
throw
ni
();
}
}
export
abstract
class
MainThreadTreeExplorersShape
{
...
...
src/vs/workbench/api/node/extHostEditors.ts
浏览文件 @
3c817c7f
...
...
@@ -12,8 +12,8 @@ import Event, { Emitter } from 'vs/base/common/event';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
ExtHostDocuments
,
ExtHostDocumentData
}
from
'
vs/workbench/api/node/extHostDocuments
'
;
import
{
Selection
,
Range
,
Position
,
EndOfLine
,
TextEditorRevealType
,
TextEditorSelectionChangeKind
,
TextEditorLineNumbersStyle
}
from
'
./extHostTypes
'
;
import
{
ISingleEditOperation
,
TextEditorCursorStyle
,
IPosition
,
IRange
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Selection
,
Range
,
Position
,
EndOfLine
,
TextEditorRevealType
,
TextEditorSelectionChangeKind
,
TextEditorLineNumbersStyle
,
SnippetString
}
from
'
./extHostTypes
'
;
import
{
ISingleEditOperation
,
TextEditorCursorStyle
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IResolvedTextEditorConfiguration
,
ISelectionChangeEvent
,
ITextEditorConfigurationUpdate
}
from
'
vs/workbench/api/node/mainThreadEditorsTracker
'
;
import
*
as
TypeConverters
from
'
./extHostTypeConverters
'
;
import
{
MainContext
,
MainThreadEditorsShape
,
ExtHostEditorsShape
,
ITextEditorAddData
,
ITextEditorPositionData
}
from
'
./extHost.protocol
'
;
...
...
@@ -595,10 +595,17 @@ class ExtHostTextEditor implements vscode.TextEditor {
// ---- editing
edit
(
callback
:
(
edit
:
TextEditorEdit
)
=>
void
,
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
=
{
undoStopBefore
:
true
,
undoStopAfter
:
true
}):
Thenable
<
boolean
>
{
let
edit
=
new
TextEditorEdit
(
this
.
_documentData
.
document
,
options
);
callback
(
edit
);
return
this
.
_applyEdit
(
edit
);
edit
(
callback
:
(
edit
:
TextEditorEdit
)
=>
void
,
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}):
Thenable
<
boolean
>
;
edit
(
snippet
:
SnippetString
,
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}):
Thenable
<
boolean
>
;
edit
(
callbackOrSnippet
:
((
edit
:
TextEditorEdit
)
=>
void
)
|
SnippetString
,
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
=
{
undoStopBefore
:
true
,
undoStopAfter
:
true
}):
Thenable
<
boolean
>
{
if
(
SnippetString
.
isSnippetString
(
callbackOrSnippet
))
{
return
this
.
_proxy
.
$tryInsertSnippet
(
this
.
_id
,
callbackOrSnippet
.
value
,
options
);
}
else
{
let
edit
=
new
TextEditorEdit
(
this
.
_documentData
.
document
,
options
);
callbackOrSnippet
(
edit
);
return
this
.
_applyEdit
(
edit
);
}
}
_applyEdit
(
editBuilder
:
TextEditorEdit
):
TPromise
<
boolean
>
{
...
...
@@ -620,22 +627,6 @@ class ExtHostTextEditor implements vscode.TextEditor {
});
}
insertSnippet
(
template
:
string
,
posOrRange
:
Position
|
Range
)
{
let
convertedPosOrRange
:
IPosition
|
IRange
;
if
(
Position
.
isPosition
(
posOrRange
))
{
convertedPosOrRange
=
TypeConverters
.
fromPosition
(
posOrRange
);
}
else
if
(
Range
.
isRange
(
posOrRange
))
{
convertedPosOrRange
=
TypeConverters
.
fromRange
(
posOrRange
);
}
else
{
return
TPromise
.
wrapError
(
new
Error
(
'
Unrecognized value for posOrRange
'
));
}
return
this
.
_proxy
.
$tryInsertSnippet
(
this
.
_id
,
template
,
convertedPosOrRange
);
}
// ---- util
private
_runOnProxy
(
callback
:
()
=>
TPromise
<
any
>
,
silent
:
boolean
):
TPromise
<
ExtHostTextEditor
>
{
...
...
src/vs/workbench/api/node/extHostTypes.ts
浏览文件 @
3c817c7f
...
...
@@ -519,6 +519,16 @@ export class WorkspaceEdit {
export
class
SnippetString
{
static
isSnippetString
(
thing
:
any
):
thing
is
SnippetString
{
if
(
thing
instanceof
SnippetString
)
{
return
true
;
}
if
(
!
thing
)
{
return
false
;
}
return
typeof
(
<
SnippetString
>
thing
).
value
===
'
string
'
;
}
private
static
_escape
(
value
:
string
):
string
{
return
value
.
replace
(
/
\$
|}|
\\
/g
,
'
\\
$&
'
);
}
...
...
src/vs/workbench/api/node/mainThreadEditors.ts
浏览文件 @
3c817c7f
...
...
@@ -8,13 +8,13 @@ import URI from 'vs/base/common/uri';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
ISingleEditOperation
,
ISelection
,
I
Position
,
I
Range
,
IEditor
,
EditorType
,
ICommonCodeEditor
,
ICommonDiffEditor
,
IDecorationRenderOptions
,
IDecorationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ISingleEditOperation
,
ISelection
,
IRange
,
IEditor
,
EditorType
,
ICommonCodeEditor
,
ICommonDiffEditor
,
IDecorationRenderOptions
,
IDecorationOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
Position
as
EditorPosition
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
MainThreadEditorsTracker
,
TextEditorRevealType
,
MainThreadTextEditor
,
IApplyEditsOptions
,
ITextEditorConfigurationUpdate
}
from
'
vs/workbench/api/node/mainThreadEditorsTracker
'
;
import
{
MainThreadEditorsTracker
,
TextEditorRevealType
,
MainThreadTextEditor
,
IApplyEditsOptions
,
I
InsertSnippetOptions
,
I
TextEditorConfigurationUpdate
}
from
'
vs/workbench/api/node/mainThreadEditorsTracker
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
equals
as
arrayEquals
}
from
'
vs/base/common/arrays
'
;
import
{
equals
as
objectEquals
}
from
'
vs/base/common/objects
'
;
...
...
@@ -293,11 +293,11 @@ export class MainThreadEditors extends MainThreadEditorsShape {
return
TPromise
.
as
(
this
.
_textEditorsMap
[
id
].
applyEdits
(
modelVersionId
,
edits
,
opts
));
}
$tryInsertSnippet
(
id
:
string
,
template
:
string
,
posOrRange
:
IPosition
|
IRange
):
TPromise
<
boolean
>
{
$tryInsertSnippet
(
id
:
string
,
template
:
string
,
opts
:
IInsertSnippetOptions
):
TPromise
<
boolean
>
{
if
(
!
this
.
_textEditorsMap
[
id
])
{
return
TPromise
.
wrapError
(
'
TextEditor disposed
'
);
}
return
TPromise
.
as
(
this
.
_textEditorsMap
[
id
].
insertSnippet
(
template
,
posOrRange
));
return
TPromise
.
as
(
this
.
_textEditorsMap
[
id
].
insertSnippet
(
template
,
opts
));
}
$registerTextEditorDecorationType
(
key
:
string
,
options
:
IDecorationRenderOptions
):
void
{
...
...
src/vs/workbench/api/node/mainThreadEditorsTracker.ts
浏览文件 @
3c817c7f
...
...
@@ -12,7 +12,6 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
IdGenerator
}
from
'
vs/base/common/idGenerator
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
SnippetController
}
from
'
vs/editor/contrib/snippet/common/snippetController
'
;
...
...
@@ -60,12 +59,19 @@ export enum TextEditorRevealType {
InCenterIfOutsideViewport
=
2
}
export
interface
I
ApplyEdits
Options
{
export
interface
I
UndoStop
Options
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
export
interface
IApplyEditsOptions
extends
IUndoStopOptions
{
setEndOfLine
:
EndOfLine
;
}
export
interface
IInsertSnippetOptions
extends
IUndoStopOptions
{
}
/**
* Text Editor that is permanently bound to the same model.
* It can be bound or not to a CodeEditor.
...
...
@@ -386,24 +392,22 @@ export class MainThreadTextEditor {
return
false
;
}
insertSnippet
(
template
:
string
,
posOrRange
:
EditorCommon
.
IPosition
|
EditorCommon
.
IRange
)
{
insertSnippet
(
template
:
string
,
opts
:
IInsertSnippetOptions
)
{
const
snippetController
=
SnippetController
.
get
(
this
.
_codeEditor
);
if
(
snippetController
.
inSnippetMode
)
{
return
false
;
}
const
range
=
Range
.
isIRange
(
posOrRange
)
?
Range
.
lift
(
posOrRange
)
:
null
;
const
position
=
Position
.
isIPosition
(
posOrRange
)
?
Position
.
lift
(
posOrRange
)
:
range
.
getStartPosition
();
this
.
_codeEditor
.
setPosition
(
position
);
this
.
_codeEditor
.
revealLine
(
position
.
lineNumber
);
this
.
_codeEditor
.
focus
();
if
(
rang
e
)
{
snippetController
.
insertSnippetWithReplaceRange
(
template
,
range
);
if
(
opts
.
undoStopBefor
e
)
{
this
.
_codeEditor
.
pushUndoStop
(
);
}
else
{
snippetController
.
insertSnippet
(
template
,
0
,
0
);
snippetController
.
insertSnippet
(
template
,
0
,
0
);
if
(
opts
.
undoStopAfter
)
{
this
.
_codeEditor
.
pushUndoStop
();
}
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录