Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9a9c8c7a
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,发现更多精彩内容 >>
提交
9a9c8c7a
编写于
10月 16, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
show message when no formatter is installed, #36303
上级
10a0e425
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
31 addition
and
6 deletion
+31
-6
src/vs/editor/common/editorCommonExtensions.ts
src/vs/editor/common/editorCommonExtensions.ts
+2
-1
src/vs/editor/contrib/format/browser/formatActions.ts
src/vs/editor/contrib/format/browser/formatActions.ts
+16
-3
src/vs/editor/contrib/format/common/format.ts
src/vs/editor/contrib/format/common/format.ts
+13
-2
未找到文件。
src/vs/editor/common/editorCommonExtensions.ts
浏览文件 @
9a9c8c7a
...
...
@@ -153,6 +153,7 @@ export abstract class EditorCommand extends Command {
export
interface
IEditorCommandMenuOptions
{
group
?:
string
;
order
?:
number
;
when
?:
ContextKeyExpr
;
}
export
interface
IActionOptions
extends
ICommandOptions
{
label
:
string
;
...
...
@@ -182,7 +183,7 @@ export abstract class EditorAction extends EditorCommand {
id
:
this
.
id
,
title
:
this
.
label
},
when
:
this
.
precondition
,
when
:
ContextKeyExpr
.
and
(
this
.
precondition
,
this
.
menuOpts
.
when
)
,
group
:
this
.
menuOpts
.
group
,
order
:
this
.
menuOpts
.
order
};
...
...
src/vs/editor/contrib/format/browser/formatActions.ts
浏览文件 @
9a9c8c7a
...
...
@@ -13,7 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
editorAction
,
ServicesAccessor
,
EditorAction
,
commonEditorContribution
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
OnTypeFormattingEditProviderRegistry
,
DocumentRangeFormattingEditProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
getOnTypeFormattingEdits
,
getDocumentFormattingEdits
,
getDocumentRangeFormattingEdits
}
from
'
../common/format
'
;
import
{
getOnTypeFormattingEdits
,
getDocumentFormattingEdits
,
getDocumentRangeFormattingEdits
,
NoProviderError
}
from
'
../common/format
'
;
import
{
EditOperationsCommand
}
from
'
../common/formatCommand
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
...
...
@@ -23,6 +23,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
alert
}
from
'
vs/base/browser/ui/aria/aria
'
;
import
{
EditorState
,
CodeEditorStateFlag
}
from
'
vs/editor/common/core/editorState
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
IMessageService
,
Severity
}
from
'
vs/platform/message/common/message
'
;
function
alertFormattingEdits
(
edits
:
editorCommon
.
ISingleEditOperation
[]):
void
{
...
...
@@ -263,6 +264,7 @@ export abstract class AbstractFormatAction extends EditorAction {
public
run
(
accessor
:
ServicesAccessor
,
editor
:
editorCommon
.
ICommonCodeEditor
):
TPromise
<
void
>
{
const
workerService
=
accessor
.
get
(
IEditorWorkerService
);
const
messageService
=
accessor
.
get
(
IMessageService
);
const
formattingPromise
=
this
.
_getFormattingEdits
(
editor
);
if
(
!
formattingPromise
)
{
...
...
@@ -281,6 +283,15 @@ export abstract class AbstractFormatAction extends EditorAction {
EditOperationsCommand
.
execute
(
editor
,
edits
);
alertFormattingEdits
(
edits
);
editor
.
focus
();
},
err
=>
{
if
(
err
instanceof
Error
&&
err
.
name
===
NoProviderError
.
Name
)
{
messageService
.
show
(
Severity
.
Info
,
nls
.
localize
(
'
no.provider
'
,
"
Sorry, but there is no formatter for '{0}'-files installed.
"
,
editor
.
getModel
().
getLanguageIdentifier
().
language
),
);
}
else
{
throw
err
;
}
});
}
...
...
@@ -296,7 +307,7 @@ export class FormatDocumentAction extends AbstractFormatAction {
id
:
'
editor.action.formatDocument
'
,
label
:
nls
.
localize
(
'
formatDocument.label
'
,
"
Format Document
"
),
alias
:
'
Format Document
'
,
precondition
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
writable
,
EditorContextKeys
.
hasDocumentFormattingProvider
)
,
precondition
:
EditorContextKeys
.
writable
,
kbOpts
:
{
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyMod
.
Shift
|
KeyMod
.
Alt
|
KeyCode
.
KEY_F
,
...
...
@@ -304,6 +315,7 @@ export class FormatDocumentAction extends AbstractFormatAction {
linux
:
{
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Shift
|
KeyCode
.
KEY_I
}
},
menuOpts
:
{
when
:
EditorContextKeys
.
hasDocumentFormattingProvider
,
group
:
'
1_modification
'
,
order
:
1.3
}
...
...
@@ -325,12 +337,13 @@ export class FormatSelectionAction extends AbstractFormatAction {
id
:
'
editor.action.formatSelection
'
,
label
:
nls
.
localize
(
'
formatSelection.label
'
,
"
Format Selection
"
),
alias
:
'
Format Code
'
,
precondition
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
writable
,
EditorContextKeys
.
has
DocumentSelectionFormattingProvider
,
EditorContextKeys
.
has
NonEmptySelection
),
precondition
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
writable
,
EditorContextKeys
.
hasNonEmptySelection
),
kbOpts
:
{
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_F
)
},
menuOpts
:
{
when
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
hasDocumentSelectionFormattingProvider
,
EditorContextKeys
.
hasNonEmptySelection
),
group
:
'
1_modification
'
,
order
:
1.31
}
...
...
src/vs/editor/contrib/format/common/format.ts
浏览文件 @
9a9c8c7a
...
...
@@ -17,12 +17,23 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import
{
asWinJsPromise
,
sequence
}
from
'
vs/base/common/async
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
export
function
getDocumentRangeFormattingEdits
(
model
:
IReadOnlyModel
,
range
:
Range
,
options
:
FormattingOptions
):
TPromise
<
TextEdit
[]
>
{
export
class
NoProviderError
extends
Error
{
static
readonly
Name
=
'
NOPRO
'
;
constructor
(
message
?:
string
)
{
super
();
this
.
name
=
NoProviderError
.
Name
;
this
.
message
=
message
;
}
}
export
function
getDocumentRangeFormattingEdits
(
model
:
IReadOnlyModel
,
range
:
Range
,
options
:
FormattingOptions
):
TPromise
<
TextEdit
[],
NoProviderError
>
{
const
providers
=
DocumentRangeFormattingEditProviderRegistry
.
ordered
(
model
);
if
(
providers
.
length
===
0
)
{
return
TPromise
.
as
(
undefined
);
return
TPromise
.
wrapError
(
new
NoProviderError
()
);
}
let
result
:
TextEdit
[];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录