Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
827e94ed
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,发现更多精彩内容 >>
提交
827e94ed
编写于
11月 20, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Hook up basic alert of why a code action could not be applied
For #85160
上级
4cc8710a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
16 deletion
+71
-16
extensions/typescript-language-features/src/features/refactor.ts
...ons/typescript-language-features/src/features/refactor.ts
+16
-1
src/vs/editor/contrib/codeAction/codeActionUi.ts
src/vs/editor/contrib/codeAction/codeActionUi.ts
+53
-13
src/vs/editor/contrib/codeAction/codeActionWidget.ts
src/vs/editor/contrib/codeAction/codeActionWidget.ts
+2
-2
未找到文件。
extensions/typescript-language-features/src/features/refactor.ts
浏览文件 @
827e94ed
...
...
@@ -238,9 +238,14 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
return
undefined
;
}
return
this
.
convertApplicableRefactors
(
response
.
body
,
document
,
rangeOrSelection
);
const
actions
=
this
.
convertApplicableRefactors
(
response
.
body
,
document
,
rangeOrSelection
);
if
(
!
context
.
only
)
{
return
actions
;
}
return
this
.
appendInvalidActions
(
actions
);
}
private
convertApplicableRefactors
(
body
:
Proto
.
ApplicableRefactorInfo
[],
document
:
vscode
.
TextDocument
,
...
...
@@ -305,6 +310,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
}
return
false
;
}
private
appendInvalidActions
(
actions
:
vscode
.
CodeAction
[]):
vscode
.
CodeAction
[]
{
if
(
!
actions
.
some
(
action
=>
action
.
kind
&&
Extract_Constant
.
kind
.
contains
(
action
.
kind
)))
{
const
disabledAction
=
new
vscode
.
CodeAction
(
'
Extract to constant
'
,
Extract_Constant
.
kind
);
disabledAction
.
disabled
=
localize
(
'
extract.disabled
'
,
"
The current selection cannot be extracted
"
);
disabledAction
.
isPreferred
=
true
;
actions
.
push
(
disabledAction
);
}
return
actions
;
}
}
export
function
register
(
...
...
src/vs/editor/contrib/codeAction/codeActionUi.ts
浏览文件 @
827e94ed
...
...
@@ -3,21 +3,22 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IAnchor
}
from
'
vs/base/browser/ui/contextview/contextview
'
;
import
{
find
}
from
'
vs/base/common/arrays
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Lazy
}
from
'
vs/base/common/lazy
'
;
import
{
Disposable
,
MutableDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
CodeAction
}
from
'
vs/editor/common/modes
'
;
import
{
CodeActionSet
}
from
'
vs/editor/contrib/codeAction/codeAction
'
;
import
{
MessageController
}
from
'
vs/editor/contrib/message/messageController
'
;
import
{
IContextMenuService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
CodeActionsState
}
from
'
./codeActionModel
'
;
import
{
CodeActionAutoApply
}
from
'
./types
'
;
import
{
CodeActionWidget
}
from
'
./codeActionWidget
'
;
import
{
LightBulbWidget
}
from
'
./lightBulbWidget
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
IAnchor
}
from
'
vs/base/browser/ui/contextview/contextview
'
;
import
{
Lazy
}
from
'
vs/base/common/lazy
'
;
import
{
CodeActionAutoApply
,
CodeActionTrigger
}
from
'
./types
'
;
export
class
CodeActionUi
extends
Disposable
{
...
...
@@ -68,7 +69,7 @@ export class CodeActionUi extends Disposable {
this
.
_lightBulbWidget
.
getValue
().
update
(
actions
,
newState
.
position
);
if
(
!
actions
.
valid
Actions
.
length
&&
newState
.
trigger
.
context
)
{
if
(
!
actions
.
all
Actions
.
length
&&
newState
.
trigger
.
context
)
{
MessageController
.
get
(
this
.
_editor
).
showMessage
(
newState
.
trigger
.
context
.
notAvailableMessage
,
newState
.
trigger
.
context
.
position
);
this
.
_activeCodeActions
.
value
=
actions
;
return
;
...
...
@@ -76,18 +77,29 @@ export class CodeActionUi extends Disposable {
if
(
newState
.
trigger
.
type
===
'
manual
'
)
{
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
.
validActions
.
length
===
1
))
{
try
{
await
this
.
delegate
.
applyCodeAction
(
actions
.
validActions
[
0
],
false
);
}
finally
{
actions
.
dispose
();
}
// Check to see if we want to auto apply.
const
validActionToApply
=
this
.
tryGetValidActionToApply
(
newState
.
trigger
,
actions
);
if
(
validActionToApply
)
{
try
{
await
this
.
delegate
.
applyCodeAction
(
validActionToApply
,
false
);
}
finally
{
actions
.
dispose
();
}
return
;
}
// Check to see if there is an action that we would have applied were it not invalid
if
(
newState
.
trigger
.
context
)
{
const
invalidAction
=
this
.
getInvalidActionThatWouldHaveBeenApplied
(
newState
.
trigger
,
actions
);
if
(
invalidAction
&&
invalidAction
.
disabled
)
{
MessageController
.
get
(
this
.
_editor
).
showMessage
(
invalidAction
.
disabled
,
newState
.
trigger
.
context
.
position
);
actions
.
dispose
();
return
;
}
}
}
this
.
_activeCodeActions
.
value
=
actions
;
this
.
_codeActionWidget
.
getValue
().
show
(
actions
,
newState
.
position
);
}
else
{
...
...
@@ -101,6 +113,34 @@ export class CodeActionUi extends Disposable {
}
}
private
getInvalidActionThatWouldHaveBeenApplied
(
trigger
:
CodeActionTrigger
,
actions
:
CodeActionSet
):
CodeAction
|
undefined
{
if
(
!
actions
.
allActions
.
length
)
{
return
undefined
;
}
if
((
trigger
.
autoApply
===
CodeActionAutoApply
.
First
&&
actions
.
validActions
.
length
===
0
)
||
(
trigger
.
autoApply
===
CodeActionAutoApply
.
IfSingle
&&
actions
.
allActions
.
length
===
1
)
)
{
return
find
(
actions
.
allActions
,
action
=>
action
.
disabled
);
}
return
undefined
;
}
private
tryGetValidActionToApply
(
trigger
:
CodeActionTrigger
,
actions
:
CodeActionSet
):
CodeAction
|
undefined
{
if
(
!
actions
.
validActions
.
length
)
{
return
undefined
;
}
if
((
trigger
.
autoApply
===
CodeActionAutoApply
.
First
&&
actions
.
validActions
.
length
>
0
)
||
(
trigger
.
autoApply
===
CodeActionAutoApply
.
IfSingle
&&
actions
.
validActions
.
length
===
1
)
)
{
return
actions
.
validActions
[
0
];
}
return
undefined
;
}
public
async
showCodeActionList
(
actions
:
CodeActionSet
,
at
:
IAnchor
|
IPosition
):
Promise
<
void
>
{
this
.
_codeActionWidget
.
getValue
().
show
(
actions
,
at
);
}
...
...
src/vs/editor/contrib/codeAction/codeActionWidget.ts
浏览文件 @
827e94ed
...
...
@@ -64,7 +64,7 @@ export class CodeActionWidget extends Disposable {
}
public
async
show
(
codeActions
:
CodeActionSet
,
at
:
IAnchor
|
IPosition
):
Promise
<
void
>
{
if
(
!
codeActions
.
valid
Actions
.
length
)
{
if
(
!
codeActions
.
all
Actions
.
length
)
{
this
.
_visible
=
false
;
return
;
}
...
...
@@ -78,7 +78,7 @@ export class CodeActionWidget extends Disposable {
this
.
_visible
=
true
;
this
.
_showingActions
.
value
=
codeActions
;
const
actions
=
codeActions
.
valid
Actions
.
map
(
action
=>
const
actions
=
codeActions
.
all
Actions
.
map
(
action
=>
new
CodeActionAction
(
action
,
()
=>
this
.
_delegate
.
onSelectCodeAction
(
action
)));
const
anchor
=
Position
.
isIPosition
(
at
)
?
this
.
_toCoords
(
at
)
:
at
||
{
x
:
0
,
y
:
0
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录