Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
34445c9b
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,发现更多精彩内容 >>
未验证
提交
34445c9b
编写于
12月 13, 2017
作者:
J
Johannes Rieken
提交者:
GitHub
12月 13, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38924 from tsalinger/fix38623
Fix #38623
上级
12bb0294
2a0027e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
103 addition
and
18 deletion
+103
-18
src/vs/editor/contrib/quickFix/quickFix.ts
src/vs/editor/contrib/quickFix/quickFix.ts
+21
-1
src/vs/editor/contrib/quickFix/test/quickFix.test.ts
src/vs/editor/contrib/quickFix/test/quickFix.test.ts
+82
-17
未找到文件。
src/vs/editor/contrib/quickFix/quickFix.ts
浏览文件 @
34445c9b
...
...
@@ -13,6 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
onUnexpectedExternalError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
registerLanguageCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
export
function
getCodeActions
(
model
:
IReadOnlyModel
,
range
:
Range
):
TPromise
<
CodeAction
[]
>
{
...
...
@@ -31,7 +32,26 @@ export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<Co
});
});
return
TPromise
.
join
(
promises
).
then
(()
=>
allResults
);
return
TPromise
.
join
(
promises
).
then
(
()
=>
allResults
.
sort
(
codeActionsComparator
)
);
}
function
codeActionsComparator
(
a
:
CodeAction
,
b
:
CodeAction
):
number
{
const
aHasDiags
=
!
isFalsyOrEmpty
(
a
.
diagnostics
);
const
bHasDiags
=
!
isFalsyOrEmpty
(
b
.
diagnostics
);
if
(
aHasDiags
)
{
if
(
bHasDiags
)
{
return
a
.
diagnostics
[
0
].
message
.
localeCompare
(
b
.
diagnostics
[
0
].
message
);
}
else
{
return
-
1
;
}
}
else
if
(
bHasDiags
)
{
return
1
;
}
else
{
return
0
;
// both have no diagnostics
}
}
registerLanguageCommand
(
'
_executeCodeActionProvider
'
,
function
(
accessor
,
args
)
{
...
...
src/vs/editor/contrib/quickFix/test/quickFix.test.ts
浏览文件 @
34445c9b
...
...
@@ -8,7 +8,7 @@ import * as assert from 'assert';
import
URI
from
'
vs/base/common/uri
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
CodeActionProviderRegistry
,
LanguageIdentifier
,
CodeActionProvider
}
from
'
vs/editor/common/modes
'
;
import
{
CodeActionProviderRegistry
,
LanguageIdentifier
,
CodeActionProvider
,
Command
,
WorkspaceEdit
,
IResourceEdit
}
from
'
vs/editor/common/modes
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
getCodeActions
}
from
'
vs/editor/contrib/quickFix/quickFix
'
;
...
...
@@ -19,6 +19,64 @@ suite('QuickFix', () => {
let
uri
=
URI
.
parse
(
'
untitled:path
'
);
let
model
:
Model
;
let
disposables
:
IDisposable
[]
=
[];
let
testData
=
{
diagnostics
:
{
abc
:
{
title
:
'
bTitle
'
,
diagnostics
:
[{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
,
severity
:
Severity
.
Error
,
message
:
'
abc
'
}]
},
bcd
:
{
title
:
'
aTitle
'
,
diagnostics
:
[{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
,
severity
:
Severity
.
Error
,
message
:
'
bcd
'
}]
}
},
command
:
{
abc
:
{
command
:
new
class
implements
Command
{
id
:
'
1
'
;
title
:
'
abc
'
;
},
title
:
'
Extract to inner function in function "test"
'
}
},
spelling
:
{
bcd
:
{
diagnostics
:
[],
edits
:
new
class
implements
WorkspaceEdit
{
edits
:
IResourceEdit
[];
},
title
:
'
abc
'
}
},
tsLint
:
{
abc
:
{
$ident
:
57
,
arguments
:
[],
id
:
'
_internal_command_delegation
'
,
title
:
'
abc
'
},
bcd
:
{
$ident
:
47
,
arguments
:
[],
id
:
'
_internal_command_delegation
'
,
title
:
'
bcd
'
}
}
};
setup
(
function
()
{
model
=
Model
.
createFromString
(
'
test1
\n
test2
\n
test3
'
,
undefined
,
langId
,
uri
);
...
...
@@ -29,30 +87,37 @@ suite('QuickFix', () => {
dispose
(
disposables
);
});
test
(
'
basics
'
,
async
function
()
{
test
(
'
CodeActions are sorted by type, #38623
'
,
async
function
()
{
const
provider
=
new
class
implements
CodeActionProvider
{
provideCodeActions
()
{
return
[{
title
:
'
Testing1
'
,
diagnostics
:
[{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
,
severity
:
Severity
.
Error
,
message
:
'
some error
'
}]
},
{
title
:
'
Testing2
'
}];
return
[
testData
.
command
.
abc
,
testData
.
diagnostics
.
bcd
,
testData
.
spelling
.
bcd
,
testData
.
tsLint
.
bcd
,
testData
.
tsLint
.
abc
,
testData
.
diagnostics
.
abc
];
}
};
disposables
.
push
(
CodeActionProviderRegistry
.
register
(
'
fooLang
'
,
provider
));
const
expected
=
[
// CodeActions with a diagnostics array are shown first ordered by diagnostics.message
testData
.
diagnostics
.
abc
,
testData
.
diagnostics
.
bcd
,
// CodeActions without diagnostics are shown in the given order without any further sorting
testData
.
command
.
abc
,
testData
.
spelling
.
bcd
,
// empty diagnostics array
testData
.
tsLint
.
bcd
,
testData
.
tsLint
.
abc
];
const
actions
=
await
getCodeActions
(
model
,
new
Range
(
1
,
1
,
2
,
1
));
assert
.
equal
(
actions
.
length
,
2
);
assert
.
equal
(
actions
.
length
,
6
);
assert
.
deepEqual
(
actions
,
expected
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录