Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
2a61f8d4
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,发现更多精彩内容 >>
提交
2a61f8d4
编写于
12月 07, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Strict null check format action
上级
70a73a95
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
20 deletion
+48
-20
src/tsconfig.strictNullChecks.json
src/tsconfig.strictNullChecks.json
+1
-0
src/vs/editor/common/services/editorWorkerService.ts
src/vs/editor/common/services/editorWorkerService.ts
+1
-1
src/vs/editor/common/services/editorWorkerServiceImpl.ts
src/vs/editor/common/services/editorWorkerServiceImpl.ts
+1
-1
src/vs/editor/contrib/format/formatActions.ts
src/vs/editor/contrib/format/formatActions.ts
+45
-18
未找到文件。
src/tsconfig.strictNullChecks.json
浏览文件 @
2a61f8d4
...
...
@@ -313,6 +313,7 @@
"./vs/editor/contrib/folding/test/syntaxFold.test.ts"
,
"./vs/editor/contrib/fontZoom/fontZoom.ts"
,
"./vs/editor/contrib/format/format.ts"
,
"./vs/editor/contrib/format/formatActions.ts"
,
"./vs/editor/contrib/format/formattingEdit.ts"
,
"./vs/editor/contrib/goToDefinition/clickLinkGesture.ts"
,
"./vs/editor/contrib/goToDefinition/goToDefinition.ts"
,
...
...
src/vs/editor/common/services/editorWorkerService.ts
浏览文件 @
2a61f8d4
...
...
@@ -26,7 +26,7 @@ export interface IEditorWorkerService {
canComputeDirtyDiff
(
original
:
URI
,
modified
:
URI
):
boolean
;
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
IChange
[]
|
null
>
;
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
TextEdit
[]
):
Promise
<
TextEdit
[]
>
;
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
TextEdit
[]
|
null
|
undefined
):
Promise
<
TextEdit
[]
|
null
|
undefined
>
;
canComputeWordRanges
(
resource
:
URI
):
boolean
;
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
Promise
<
{
[
word
:
string
]:
IRange
[]
}
|
null
>
;
...
...
src/vs/editor/common/services/editorWorkerServiceImpl.ts
浏览文件 @
2a61f8d4
...
...
@@ -87,7 +87,7 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeDirtyDiff
(
original
,
modified
,
ignoreTrimWhitespace
));
}
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]
):
Promise
<
modes
.
TextEdit
[]
>
{
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]
|
null
|
undefined
):
Promise
<
modes
.
TextEdit
[]
|
null
|
undefined
>
{
if
(
!
Array
.
isArray
(
edits
)
||
edits
.
length
===
0
)
{
return
Promise
.
resolve
(
edits
);
}
else
{
...
...
src/vs/editor/contrib/format/formatActions.ts
浏览文件 @
2a61f8d4
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
nls
from
'
vs/nls
'
;
import
{
is
FalsyOrEmpt
y
}
from
'
vs/base/common/arrays
'
;
import
{
is
NonEmptyArra
y
}
from
'
vs/base/common/arrays
'
;
import
{
KeyCode
,
KeyMod
,
KeyChord
}
from
'
vs/base/common/keyCodes
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -87,7 +87,7 @@ class FormatOnType implements editorCommon.IEditorContribution {
}
// no model
if
(
!
this
.
editor
.
get
Model
())
{
if
(
!
this
.
editor
.
has
Model
())
{
return
;
}
...
...
@@ -113,6 +113,9 @@ class FormatOnType implements editorCommon.IEditorContribution {
}
private
trigger
(
ch
:
string
):
void
{
if
(
!
this
.
editor
.
hasModel
())
{
return
;
}
if
(
this
.
editor
.
getSelections
().
length
>
1
)
{
return
;
...
...
@@ -157,12 +160,14 @@ class FormatOnType implements editorCommon.IEditorContribution {
unbind
.
dispose
();
if
(
canceled
||
isFalsyOrEmpty
(
edits
)
)
{
if
(
canceled
)
{
return
;
}
FormattingEdit
.
execute
(
this
.
editor
,
edits
);
alertFormattingEdits
(
edits
);
if
(
isNonEmptyArray
(
edits
))
{
FormattingEdit
.
execute
(
this
.
editor
,
edits
);
alertFormattingEdits
(
edits
);
}
},
(
err
)
=>
{
unbind
.
dispose
();
...
...
@@ -212,7 +217,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
}
// no model
if
(
!
this
.
editor
.
get
Model
())
{
if
(
!
this
.
editor
.
has
Model
())
{
return
;
}
...
...
@@ -230,6 +235,10 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
}
private
trigger
(
range
:
Range
):
void
{
if
(
!
this
.
editor
.
hasModel
())
{
return
;
}
if
(
this
.
editor
.
getSelections
().
length
>
1
)
{
return
;
}
...
...
@@ -241,11 +250,13 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
getDocumentRangeFormattingEdits
(
model
,
range
,
{
tabSize
,
insertSpaces
},
CancellationToken
.
None
).
then
(
edits
=>
{
return
this
.
workerService
.
computeMoreMinimalEdits
(
model
.
uri
,
edits
);
}).
then
(
edits
=>
{
if
(
!
state
.
validate
(
this
.
editor
)
||
isFalsyOrEmpty
(
edits
)
)
{
if
(
!
state
.
validate
(
this
.
editor
))
{
return
;
}
FormattingEdit
.
execute
(
this
.
editor
,
edits
);
alertFormattingEdits
(
edits
);
if
(
isNonEmptyArray
(
edits
))
{
FormattingEdit
.
execute
(
this
.
editor
,
edits
);
alertFormattingEdits
(
edits
);
}
});
}
...
...
@@ -262,6 +273,9 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
export
abstract
class
AbstractFormatAction
extends
EditorAction
{
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
if
(
!
editor
.
hasModel
())
{
return
Promise
.
resolve
(
void
0
);
}
const
workerService
=
accessor
.
get
(
IEditorWorkerService
);
const
notificationService
=
accessor
.
get
(
INotificationService
);
...
...
@@ -276,14 +290,16 @@ export abstract class AbstractFormatAction extends EditorAction {
// Receive formatted value from worker
return
formattingPromise
.
then
(
edits
=>
workerService
.
computeMoreMinimalEdits
(
editor
.
getModel
().
uri
,
edits
)).
then
(
edits
=>
{
if
(
!
state
.
validate
(
editor
)
||
isFalsyOrEmpty
(
edits
)
)
{
if
(
!
state
.
validate
(
editor
))
{
return
;
}
FormattingEdit
.
execute
(
editor
,
edits
);
alertFormattingEdits
(
edits
);
editor
.
focus
();
editor
.
revealPositionInCenterIfOutsideViewport
(
editor
.
getPosition
(),
editorCommon
.
ScrollType
.
Immediate
);
if
(
isNonEmptyArray
(
edits
))
{
FormattingEdit
.
execute
(
editor
,
edits
);
alertFormattingEdits
(
edits
);
editor
.
focus
();
editor
.
revealPositionInCenterIfOutsideViewport
(
editor
.
getPosition
(),
editorCommon
.
ScrollType
.
Immediate
);
}
},
err
=>
{
if
(
err
instanceof
Error
&&
err
.
name
===
NoProviderError
.
Name
)
{
this
.
_notifyNoProviderError
(
notificationService
,
editor
.
getModel
().
getLanguageIdentifier
().
language
);
...
...
@@ -293,7 +309,7 @@ export abstract class AbstractFormatAction extends EditorAction {
});
}
protected
abstract
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
>
;
protected
abstract
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
|
null
|
undefined
>
|
undefined
;
protected
_notifyNoProviderError
(
notificationService
:
INotificationService
,
language
:
string
):
void
{
notificationService
.
info
(
nls
.
localize
(
'
no.provider
'
,
"
There is no formatter for '{0}'-files installed.
"
,
language
));
...
...
@@ -323,7 +339,10 @@ export class FormatDocumentAction extends AbstractFormatAction {
});
}
protected
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
>
{
protected
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
|
null
|
undefined
>
|
undefined
{
if
(
!
editor
.
hasModel
())
{
return
undefined
;
}
const
model
=
editor
.
getModel
();
const
{
tabSize
,
insertSpaces
}
=
model
.
getOptions
();
return
getDocumentFormattingEdits
(
model
,
{
tabSize
,
insertSpaces
},
token
);
...
...
@@ -355,7 +374,11 @@ export class FormatSelectionAction extends AbstractFormatAction {
});
}
protected
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
>
{
protected
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
|
null
|
undefined
>
|
undefined
{
if
(
!
editor
.
hasModel
())
{
return
undefined
;
}
const
model
=
editor
.
getModel
();
let
selection
=
editor
.
getSelection
();
if
(
selection
.
isEmpty
())
{
...
...
@@ -386,7 +409,11 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => {
constructor
()
{
super
({}
as
IActionOptions
);
}
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
>
{
_getFormattingEdits
(
editor
:
ICodeEditor
,
token
:
CancellationToken
):
Promise
<
ISingleEditOperation
[]
|
null
|
undefined
>
|
undefined
{
if
(
!
editor
.
hasModel
())
{
return
undefined
;
}
const
model
=
editor
.
getModel
();
const
editorSelection
=
editor
.
getSelection
();
const
{
tabSize
,
insertSpaces
}
=
model
.
getOptions
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录