Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0be6912f
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,发现更多精彩内容 >>
提交
0be6912f
编写于
12月 01, 2015
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
command: executeFormatOnTypeProvider
上级
78e11f23
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
30 deletion
+67
-30
src/vs/editor/contrib/format/common/format.ts
src/vs/editor/contrib/format/common/format.ts
+25
-6
src/vs/editor/contrib/format/common/formatActions.ts
src/vs/editor/contrib/format/common/formatActions.ts
+6
-6
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
...vs/workbench/api/common/extHostLanguageFeatureCommands.ts
+15
-17
src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts
...workbench/test/common/api/extHostLanguageFeatures.test.ts
+21
-1
未找到文件。
src/vs/editor/contrib/format/common/format.ts
浏览文件 @
0be6912f
...
...
@@ -22,29 +22,40 @@ export const FormatOnTypeRegistry = new LanguageFeatureRegistry<IFormattingSuppo
export
{
IFormattingSupport
};
export
function
formatRange
(
model
:
IModel
,
range
:
IRange
,
options
:
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
const
support
=
FormatRegistry
.
ordered
(
model
)[
0
]
;
const
[
support
]
=
FormatRegistry
.
ordered
(
model
)
;
if
(
!
support
)
{
return
;
return
TPromise
.
as
(
undefined
)
;
}
return
support
.
formatRange
(
model
.
getAssociatedResource
(),
range
,
options
);
}
export
function
formatDocument
(
model
:
IModel
,
options
:
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
const
support
=
FormatRegistry
.
ordered
(
model
)[
0
]
;
const
[
support
]
=
FormatRegistry
.
ordered
(
model
)
;
if
(
!
support
)
{
return
;
return
TPromise
.
as
(
undefined
)
;
}
if
(
typeof
support
.
formatDocument
!==
'
function
'
)
{
if
(
typeof
support
.
formatRange
===
'
function
'
)
{
return
formatRange
(
model
,
model
.
getFullModelRange
(),
options
);
}
else
{
return
;
return
TPromise
.
as
(
undefined
)
;
}
}
return
support
.
formatDocument
(
model
.
getAssociatedResource
(),
options
);
}
export
function
formatAfterKeystroke
(
model
:
IModel
,
position
:
IPosition
,
ch
:
string
,
options
:
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
const
[
support
]
=
FormatOnTypeRegistry
.
ordered
(
model
);
if
(
!
support
)
{
return
TPromise
.
as
(
undefined
);
}
if
(
support
.
autoFormatTriggerCharacters
.
indexOf
(
ch
)
<
0
)
{
return
TPromise
.
as
(
undefined
);
}
return
support
.
formatAfterKeystroke
(
model
.
getAssociatedResource
(),
position
,
ch
,
options
);
}
CommonEditorRegistry
.
registerLanguageCommand
(
'
_executeFormatRangeProvider
'
,
function
(
accessor
,
args
)
{
const
{
resource
,
range
,
options
}
=
args
;
if
(
!
URI
.
isURI
(
resource
)
||
!
Range
.
isIRange
(
range
))
{
...
...
@@ -68,4 +79,12 @@ CommonEditorRegistry.registerLanguageCommand('_executeFormatDocumentProvider', f
}
return
formatDocument
(
model
,
options
)
});
\ No newline at end of file
});
CommonEditorRegistry
.
registerDefaultLanguageCommand
(
'
_executeFormatOnTypeProvider
'
,
function
(
model
,
position
,
args
)
{
const
{
ch
,
options
}
=
args
;
if
(
typeof
ch
!==
'
string
'
)
{
throw
illegalArgument
(
'
ch
'
);
}
return
formatAfterKeystroke
(
model
,
position
,
ch
,
options
);
});
src/vs/editor/contrib/format/common/formatActions.ts
浏览文件 @
0be6912f
...
...
@@ -15,7 +15,7 @@ import formatCommand = require('./formatCommand');
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
INullService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
KeyMod
,
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
FormatOnTypeRegistry
,
FormatRegistry
,
IFormattingSupport
,
formatRange
,
formatDocument
}
from
'
../common/format
'
;
import
{
FormatOnTypeRegistry
,
FormatRegistry
,
IFormattingSupport
,
formatRange
,
formatDocument
,
formatAfterKeystroke
}
from
'
../common/format
'
;
interface
IFormatOnTypeResult
{
range
:
EditorCommon
.
IEditorRange
;
...
...
@@ -66,7 +66,7 @@ class FormatOnType implements EditorCommon.IEditorContribution {
var
model
=
this
.
editor
.
getModel
();
// no support
var
support
=
FormatOnTypeRegistry
.
ordered
(
model
)[
0
]
;
var
[
support
]
=
FormatOnTypeRegistry
.
ordered
(
model
)
;
if
(
!
support
||
!
support
.
autoFormatTriggerCharacters
)
{
return
;
}
...
...
@@ -75,12 +75,12 @@ class FormatOnType implements EditorCommon.IEditorContribution {
this
.
formattingOptions
=
this
.
editor
.
getIndentationOptions
();
// register typing listeners that will trigger the format
support
.
autoFormatTriggerCharacters
.
forEach
(
ch
ar
=>
{
this
.
callOnModel
.
push
(
this
.
editor
.
addTypingListener
(
ch
ar
,
this
.
trigger
.
bind
(
this
,
support
,
char
)));
support
.
autoFormatTriggerCharacters
.
forEach
(
ch
=>
{
this
.
callOnModel
.
push
(
this
.
editor
.
addTypingListener
(
ch
,
this
.
trigger
.
bind
(
this
,
ch
)));
});
}
private
trigger
(
support
:
IFormattingSupport
,
char
:
string
):
void
{
private
trigger
(
ch
:
string
):
void
{
if
(
this
.
editor
.
getSelections
().
length
>
1
)
{
return
;
...
...
@@ -116,7 +116,7 @@ class FormatOnType implements EditorCommon.IEditorContribution {
}
});
support
.
formatAfterKeystroke
(
model
.
getAssociatedResource
(),
position
,
char
,
this
.
formattingOptions
).
then
((
edits
)
=>
{
formatAfterKeystroke
(
model
,
position
,
ch
,
this
.
formattingOptions
).
then
(
edits
=>
{
unbind
();
...
...
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
浏览文件 @
0be6912f
...
...
@@ -36,23 +36,6 @@ import {RenameRegistry} from 'vs/editor/contrib/rename/common/rename';
import
{
FormatRegistry
,
FormatOnTypeRegistry
}
from
'
vs/editor/contrib/format/common/format
'
;
import
{
ICodeLensData
}
from
'
vs/editor/contrib/codelens/common/codelens
'
;
// vscode.executeWorkspaceSymbolProvider
// vscode.executeDefinitionProvider
// vscode.executeHoverProvider
// vscode.executeDocumentHighlights
// vscode.executeReferenceProvider
// vscode.executeDocumentRenameProvider
// vscode.executeSignatureHelpProvider
// vscode.executeDocumentSymbolProvider
// vscode.executeCompletionItemProvider
// vscode.executeCodeActionProvider
// vscode.executeCodeLensProvider
// vscode.executeFormatDocumentProvider
// vscode.executeFormatRangeProvider
// vscode.executeFormatOnTypeProvider
export
class
ExtHostLanguageFeatureCommands
{
private
_commands
:
PluginHostCommands
;
...
...
@@ -74,6 +57,7 @@ export class ExtHostLanguageFeatureCommands {
this
.
_register
(
'
vscode.executeCodeLensProvider
'
,
this
.
_executeCodeLensProvider
);
this
.
_register
(
'
vscode.executeFormatDocumentProvider
'
,
this
.
_executeFormatDocumentProvider
);
this
.
_register
(
'
vscode.executeFormatRangeProvider
'
,
this
.
_executeFormatRangeProvider
);
this
.
_register
(
'
vscode.executeFormatOnTypeProvider
'
,
this
.
_executeFormatOnTypeProvider
);
}
private
_register
(
id
:
string
,
callback
:
(...
args
:
any
[])
=>
any
):
void
{
...
...
@@ -254,4 +238,18 @@ export class ExtHostLanguageFeatureCommands {
}
});
}
private
_executeFormatOnTypeProvider
(
resource
:
URI
,
position
:
types
.
Position
,
ch
:
string
,
options
:
vscode
.
FormattingOptions
):
Thenable
<
vscode
.
TextEdit
[]
>
{
const
args
=
{
resource
,
position
:
typeConverters
.
fromPosition
(
position
),
ch
,
options
};
return
this
.
_commands
.
executeCommand
<
ISingleEditOperation
[]
>
(
'
_executeFormatOnTypeProvider
'
,
args
).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
edit
=>
new
types
.
TextEdit
(
typeConverters
.
toRange
(
edit
.
range
),
edit
.
text
));
}
});
}
}
\ No newline at end of file
src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts
浏览文件 @
0be6912f
...
...
@@ -37,7 +37,7 @@ import {getNavigateToItems} from 'vs/workbench/parts/search/common/search';
import
{
rename
}
from
'
vs/editor/contrib/rename/common/rename
'
;
import
{
getParameterHints
}
from
'
vs/editor/contrib/parameterHints/common/parameterHints
'
;
import
{
suggest
}
from
'
vs/editor/contrib/suggest/common/suggest
'
;
import
{
formatDocument
,
formatRange
}
from
'
vs/editor/contrib/format/common/format
'
;
import
{
formatDocument
,
formatRange
,
formatAfterKeystroke
}
from
'
vs/editor/contrib/format/common/format
'
;
const
defaultSelector
=
{
scheme
:
'
far
'
};
const
model
:
EditorCommon
.
IModel
=
new
EditorModel
(
...
...
@@ -970,4 +970,24 @@ suite('ExtHostLanguageFeatures', function() {
formatRange
(
model
,
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
},
{
insertSpaces
:
true
,
tabSize
:
4
}).
then
(
undefined
,
err
=>
done
());
});
})
test
(
'
Format on Type, data conversion
'
,
function
(
done
)
{
disposables
.
push
(
extHost
.
registerOnTypeFormattingEditProvider
(
defaultSelector
,
<
vscode
.
OnTypeFormattingEditProvider
>
{
provideOnTypeFormattingEdits
():
any
{
return
[
new
types
.
TextEdit
(
new
types
.
Range
(
0
,
0
,
0
,
0
),
arguments
[
2
])];
}
},
[
'
;
'
]));
threadService
.
sync
().
then
(()
=>
{
formatAfterKeystroke
(
model
,
{
lineNumber
:
1
,
column
:
1
},
'
;
'
,
{
insertSpaces
:
true
,
tabSize
:
2
}).
then
(
value
=>
{
assert
.
equal
(
value
.
length
,
1
);
let
[
first
]
=
value
;
assert
.
equal
(
first
.
text
,
'
;
'
);
assert
.
deepEqual
(
first
.
range
,
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
});
done
();
});
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录