Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4cc8710a
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,发现更多精彩内容 >>
提交
4cc8710a
编写于
11月 20, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CodeAction.disabled
For #85160
上级
37f18e8f
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
53 addition
and
33 deletion
+53
-33
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+1
-0
src/vs/editor/contrib/codeAction/codeAction.ts
src/vs/editor/contrib/codeAction/codeAction.ts
+8
-5
src/vs/editor/contrib/codeAction/codeActionUi.ts
src/vs/editor/contrib/codeAction/codeActionUi.ts
+5
-6
src/vs/editor/contrib/codeAction/codeActionWidget.ts
src/vs/editor/contrib/codeAction/codeActionWidget.ts
+3
-3
src/vs/editor/contrib/codeAction/lightBulbWidget.ts
src/vs/editor/contrib/codeAction/lightBulbWidget.ts
+1
-1
src/vs/editor/contrib/codeAction/test/codeAction.test.ts
src/vs/editor/contrib/codeAction/test/codeAction.test.ts
+9
-9
src/vs/editor/contrib/codeAction/test/codeActionModel.test.ts
...vs/editor/contrib/codeAction/test/codeActionModel.test.ts
+2
-2
src/vs/editor/contrib/hover/modesContentHover.ts
src/vs/editor/contrib/hover/modesContentHover.ts
+1
-1
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+1
-0
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+14
-0
src/vs/workbench/api/browser/mainThreadSaveParticipant.ts
src/vs/workbench/api/browser/mainThreadSaveParticipant.ts
+1
-1
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+1
-0
src/vs/workbench/api/common/extHostLanguageFeatures.ts
src/vs/workbench/api/common/extHostLanguageFeatures.ts
+1
-0
src/vs/workbench/contrib/markers/browser/markersTreeViewer.ts
...vs/workbench/contrib/markers/browser/markersTreeViewer.ts
+1
-1
src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts
...test/electron-browser/api/extHostLanguageFeatures.test.ts
+4
-4
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
4cc8710a
...
...
@@ -548,6 +548,7 @@ export interface CodeAction {
diagnostics
?:
IMarkerData
[];
kind
?:
string
;
isPreferred
?:
boolean
;
disabled
?:
string
;
}
/**
...
...
src/vs/editor/contrib/codeAction/codeAction.ts
浏览文件 @
4cc8710a
...
...
@@ -24,7 +24,8 @@ export const organizeImportsCommandId = 'editor.action.organizeImports';
export
const
fixAllCommandId
=
'
editor.action.fixAll
'
;
export
interface
CodeActionSet
extends
IDisposable
{
readonly
actions
:
readonly
CodeAction
[];
readonly
validActions
:
readonly
CodeAction
[];
readonly
allActions
:
readonly
CodeAction
[];
readonly
hasAutoFix
:
boolean
;
}
...
...
@@ -44,16 +45,18 @@ class ManagedCodeActionSet extends Disposable implements CodeActionSet {
}
}
public
readonly
actions
:
readonly
CodeAction
[];
public
readonly
validActions
:
readonly
CodeAction
[];
public
readonly
allActions
:
readonly
CodeAction
[];
public
constructor
(
actions
:
readonly
CodeAction
[],
disposables
:
DisposableStore
)
{
super
();
this
.
_register
(
disposables
);
this
.
actions
=
mergeSort
([...
actions
],
ManagedCodeActionSet
.
codeActionsComparator
);
this
.
allActions
=
mergeSort
([...
actions
],
ManagedCodeActionSet
.
codeActionsComparator
);
this
.
validActions
=
this
.
allActions
.
filter
(
action
=>
!
action
.
disabled
);
}
public
get
hasAutoFix
()
{
return
this
.
a
ctions
.
some
(
fix
=>
!!
fix
.
kind
&&
CodeActionKind
.
QuickFix
.
contains
(
new
CodeActionKind
(
fix
.
kind
))
&&
!!
fix
.
isPreferred
);
return
this
.
validA
ctions
.
some
(
fix
=>
!!
fix
.
kind
&&
CodeActionKind
.
QuickFix
.
contains
(
new
CodeActionKind
(
fix
.
kind
))
&&
!!
fix
.
isPreferred
);
}
}
...
...
@@ -150,5 +153,5 @@ registerLanguageCommand('_executeCodeActionProvider', async function (accessor,
CancellationToken
.
None
);
setTimeout
(()
=>
codeActionSet
.
dispose
(),
100
);
return
codeActionSet
.
a
ctions
;
return
codeActionSet
.
validA
ctions
;
});
src/vs/editor/contrib/codeAction/codeActionUi.ts
浏览文件 @
4cc8710a
...
...
@@ -68,20 +68,19 @@ export class CodeActionUi extends Disposable {
this
.
_lightBulbWidget
.
getValue
().
update
(
actions
,
newState
.
position
);
if
(
!
actions
.
a
ctions
.
length
&&
newState
.
trigger
.
context
)
{
if
(
!
actions
.
validA
ctions
.
length
&&
newState
.
trigger
.
context
)
{
MessageController
.
get
(
this
.
_editor
).
showMessage
(
newState
.
trigger
.
context
.
notAvailableMessage
,
newState
.
trigger
.
context
.
position
);
this
.
_activeCodeActions
.
value
=
actions
;
return
;
}
if
(
newState
.
trigger
.
type
===
'
manual
'
)
{
if
(
newState
.
trigger
.
filter
&&
newState
.
trigger
.
filter
.
include
)
{
// Triggered for specific scope
if
(
actions
.
actions
.
length
>
0
)
{
if
(
newState
.
trigger
.
filter
?.
include
)
{
// Triggered for specific scope
if
(
actions
.
validActions
.
length
>
0
)
{
// Apply if we only have one action or requested autoApply
if
(
newState
.
trigger
.
autoApply
===
CodeActionAutoApply
.
First
||
(
newState
.
trigger
.
autoApply
===
CodeActionAutoApply
.
IfSingle
&&
actions
.
a
ctions
.
length
===
1
))
{
if
(
newState
.
trigger
.
autoApply
===
CodeActionAutoApply
.
First
||
(
newState
.
trigger
.
autoApply
===
CodeActionAutoApply
.
IfSingle
&&
actions
.
validA
ctions
.
length
===
1
))
{
try
{
await
this
.
delegate
.
applyCodeAction
(
actions
.
a
ctions
[
0
],
false
);
await
this
.
delegate
.
applyCodeAction
(
actions
.
validA
ctions
[
0
],
false
);
}
finally
{
actions
.
dispose
();
}
...
...
src/vs/editor/contrib/codeAction/codeActionWidget.ts
浏览文件 @
4cc8710a
...
...
@@ -35,7 +35,7 @@ class CodeActionAction extends Action {
public
readonly
action
:
CodeAction
,
callback
:
()
=>
Promise
<
void
>
,
)
{
super
(
action
.
command
?
action
.
command
.
id
:
action
.
title
,
action
.
title
,
undefined
,
true
,
callback
);
super
(
action
.
command
?
action
.
command
.
id
:
action
.
title
,
action
.
title
,
undefined
,
!
action
.
disabled
,
callback
);
}
}
...
...
@@ -64,7 +64,7 @@ export class CodeActionWidget extends Disposable {
}
public
async
show
(
codeActions
:
CodeActionSet
,
at
:
IAnchor
|
IPosition
):
Promise
<
void
>
{
if
(
!
codeActions
.
a
ctions
.
length
)
{
if
(
!
codeActions
.
validA
ctions
.
length
)
{
this
.
_visible
=
false
;
return
;
}
...
...
@@ -78,7 +78,7 @@ export class CodeActionWidget extends Disposable {
this
.
_visible
=
true
;
this
.
_showingActions
.
value
=
codeActions
;
const
actions
=
codeActions
.
a
ctions
.
map
(
action
=>
const
actions
=
codeActions
.
validA
ctions
.
map
(
action
=>
new
CodeActionAction
(
action
,
()
=>
this
.
_delegate
.
onSelectCodeAction
(
action
)));
const
anchor
=
Position
.
isIPosition
(
at
)
?
this
.
_toCoords
(
at
)
:
at
||
{
x
:
0
,
y
:
0
};
...
...
src/vs/editor/contrib/codeAction/lightBulbWidget.ts
浏览文件 @
4cc8710a
...
...
@@ -137,7 +137,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
}
public
update
(
actions
:
CodeActionSet
,
atPosition
:
IPosition
)
{
if
(
actions
.
a
ctions
.
length
<=
0
)
{
if
(
actions
.
validA
ctions
.
length
<=
0
)
{
return
this
.
hide
();
}
...
...
src/vs/editor/contrib/codeAction/test/codeAction.test.ts
浏览文件 @
4cc8710a
...
...
@@ -125,7 +125,7 @@ suite('CodeAction', () => {
testData
.
tsLint
.
abc
];
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
6
);
assert
.
deepEqual
(
actions
,
expected
);
});
...
...
@@ -140,20 +140,20 @@ suite('CodeAction', () => {
disposables
.
add
(
modes
.
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a
'
)
}
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a
'
)
}
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
2
);
assert
.
strictEqual
(
actions
[
0
].
title
,
'
a
'
);
assert
.
strictEqual
(
actions
[
1
].
title
,
'
a.b
'
);
}
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a.b
'
)
}
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a.b
'
)
}
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
assert
.
strictEqual
(
actions
[
0
].
title
,
'
a.b
'
);
}
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a.b.c
'
)
}
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a.b.c
'
)
}
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
0
);
}
});
...
...
@@ -172,7 +172,7 @@ suite('CodeAction', () => {
disposables
.
add
(
modes
.
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a
'
)
}
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
new
CodeActionKind
(
'
a
'
)
}
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
assert
.
strictEqual
(
actions
[
0
].
title
,
'
a
'
);
});
...
...
@@ -186,13 +186,13 @@ suite('CodeAction', () => {
disposables
.
add
(
modes
.
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
assert
.
strictEqual
(
actions
[
0
].
title
,
'
b
'
);
}
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
CodeActionKind
.
Source
,
includeSourceActions
:
true
}
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
CodeActionKind
.
Source
,
includeSourceActions
:
true
}
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
assert
.
strictEqual
(
actions
[
0
].
title
,
'
a
'
);
}
...
...
@@ -208,7 +208,7 @@ suite('CodeAction', () => {
disposables
.
add
(
modes
.
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
{
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
CodeActionKind
.
Source
.
append
(
'
test
'
),
excludes
:
[
CodeActionKind
.
Source
],
...
...
@@ -233,7 +233,7 @@ suite('CodeAction', () => {
disposables
.
add
(
modes
.
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
const
{
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
),
{
type
:
'
auto
'
,
filter
:
{
include
:
CodeActionKind
.
QuickFix
...
...
src/vs/editor/contrib/codeAction/test/codeActionModel.test.ts
浏览文件 @
4cc8710a
...
...
@@ -64,7 +64,7 @@ suite('CodeActionModel', () => {
e
.
actions
.
then
(
fixes
=>
{
model
.
dispose
();
assert
.
equal
(
fixes
.
a
ctions
.
length
,
1
);
assert
.
equal
(
fixes
.
validA
ctions
.
length
,
1
);
done
();
},
done
);
}));
...
...
@@ -104,7 +104,7 @@ suite('CodeActionModel', () => {
assert
.
ok
(
e
.
actions
);
e
.
actions
.
then
(
fixes
=>
{
model
.
dispose
();
assert
.
equal
(
fixes
.
a
ctions
.
length
,
1
);
assert
.
equal
(
fixes
.
validA
ctions
.
length
,
1
);
resolve
(
undefined
);
},
reject
);
}));
...
...
src/vs/editor/contrib/hover/modesContentHover.ts
浏览文件 @
4cc8710a
...
...
@@ -548,7 +548,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
quickfixPlaceholderElement
.
style
.
transition
=
''
;
quickfixPlaceholderElement
.
style
.
opacity
=
'
1
'
;
if
(
!
actions
.
a
ctions
.
length
)
{
if
(
!
actions
.
validA
ctions
.
length
)
{
actions
.
dispose
();
quickfixPlaceholderElement
.
textContent
=
nls
.
localize
(
'
noQuickFixes
'
,
"
No quick fixes available
"
);
return
;
...
...
src/vs/monaco.d.ts
浏览文件 @
4cc8710a
...
...
@@ -4977,6 +4977,7 @@ declare namespace monaco.languages {
diagnostics
?:
editor
.
IMarkerData
[];
kind
?:
string
;
isPreferred
?:
boolean
;
disabled
?:
string
;
}
export
interface
CodeActionList
extends
IDisposable
{
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
4cc8710a
...
...
@@ -1326,4 +1326,18 @@ declare module 'vscode' {
}
//#endregion
//#region mjbvz - Surfacing reasons why a code action cannot be applied to users — https://github.com/microsoft/vscode/issues/85160
export
interface
CodeAction
{
/**
* Marks that the code action cannot currently be applied.
*
* This should be a human readable description of why the code action is currently disabled. Disabled code actions
* will be surfaced in the refactor UI but cannot be applied.
*/
disabled
?:
string
;
}
//#endregion
}
src/vs/workbench/api/browser/mainThreadSaveParticipant.ts
浏览文件 @
4cc8710a
...
...
@@ -307,7 +307,7 @@ class CodeActionOnSaveParticipant implements ISaveParticipant {
for
(
const
codeActionKind
of
codeActionsOnSave
)
{
const
actionsToRun
=
await
this
.
getActionsToRun
(
model
,
codeActionKind
,
excludes
,
token
);
try
{
await
this
.
applyCodeActions
(
actionsToRun
.
a
ctions
);
await
this
.
applyCodeActions
(
actionsToRun
.
validA
ctions
);
}
catch
{
// Failure to apply a code action should not block other on save actions
}
finally
{
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
4cc8710a
...
...
@@ -1086,6 +1086,7 @@ export interface ICodeActionDto {
command
?:
ICommandDto
;
kind
?:
string
;
isPreferred
?:
boolean
;
disabled
?:
string
;
}
export
interface
ICodeActionListDto
{
...
...
src/vs/workbench/api/common/extHostLanguageFeatures.ts
浏览文件 @
4cc8710a
...
...
@@ -389,6 +389,7 @@ class CodeActionAdapter {
edit
:
candidate
.
edit
&&
typeConvert
.
WorkspaceEdit
.
from
(
candidate
.
edit
),
kind
:
candidate
.
kind
&&
candidate
.
kind
.
value
,
isPreferred
:
candidate
.
isPreferred
,
disabled
:
candidate
.
disabled
});
}
}
...
...
src/vs/workbench/contrib/markers/browser/markersTreeViewer.ts
浏览文件 @
4cc8710a
...
...
@@ -564,7 +564,7 @@ export class MarkerViewModel extends Disposable {
}
private
toActions
(
codeActions
:
CodeActionSet
):
IAction
[]
{
return
codeActions
.
a
ctions
.
map
(
codeAction
=>
new
Action
(
return
codeActions
.
validA
ctions
.
map
(
codeAction
=>
new
Action
(
codeAction
.
command
?
codeAction
.
command
.
id
:
codeAction
.
title
,
codeAction
.
title
,
undefined
,
...
...
src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts
浏览文件 @
4cc8710a
...
...
@@ -589,7 +589,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await
rpcProtocol
.
sync
();
const
{
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
2
);
const
[
first
,
second
]
=
actions
;
assert
.
equal
(
first
.
title
,
'
Testing1
'
);
...
...
@@ -613,7 +613,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await
rpcProtocol
.
sync
();
const
{
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
const
[
first
]
=
actions
;
assert
.
equal
(
first
.
title
,
'
Testing1
'
);
...
...
@@ -636,7 +636,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await
rpcProtocol
.
sync
();
const
{
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
});
...
...
@@ -654,7 +654,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await
rpcProtocol
.
sync
();
const
{
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
const
{
validActions
:
actions
}
=
await
getCodeActions
(
model
,
model
.
getFullModelRange
(),
{
type
:
'
manual
'
},
CancellationToken
.
None
);
assert
.
equal
(
actions
.
length
,
1
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录