Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6079bc6d
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,发现更多精彩内容 >>
提交
6079bc6d
编写于
2月 19, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notifications - better error handling
上级
3891d2bb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
41 deletion
+40
-41
src/vs/base/common/errors.ts
src/vs/base/common/errors.ts
+4
-0
src/vs/workbench/browser/parts/editor/editorPart.ts
src/vs/workbench/browser/parts/editor/editorPart.ts
+6
-6
src/vs/workbench/common/notifications.ts
src/vs/workbench/common/notifications.ts
+9
-2
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
...s/workbench/parts/files/browser/editors/textFileEditor.ts
+6
-10
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
+10
-23
src/vs/workbench/test/common/notifications.test.ts
src/vs/workbench/test/common/notifications.test.ts
+5
-0
未找到文件。
src/vs/base/common/errors.ts
浏览文件 @
6079bc6d
...
...
@@ -242,6 +242,10 @@ export interface IErrorWithActions {
actions
?:
IAction
[];
}
export
function
isErrorWithActions
(
obj
:
any
):
obj
is
IErrorWithActions
{
return
obj
instanceof
Error
&&
Array
.
isArray
((
obj
as
IErrorWithActions
).
actions
);
}
export
function
create
(
message
:
string
,
options
:
IErrorOptions
=
Object
.
create
(
null
)):
Error
&
IErrorWithActions
{
const
result
=
new
Error
(
message
);
...
...
src/vs/workbench/browser/parts/editor/editorPart.ts
浏览文件 @
6079bc6d
...
...
@@ -48,7 +48,7 @@ import { ThrottledEmitter } from 'vs/base/common/async';
import
{
isCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
import
{
INotificationService
,
Severity
,
INotificationActions
}
from
'
vs/platform/notification/common/notification
'
;
import
{
I
ErrorWithActions
}
from
'
vs/base/common/errors
'
;
import
{
is
ErrorWithActions
}
from
'
vs/base/common/errors
'
;
class
ProgressMonitor
{
...
...
@@ -541,22 +541,22 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
});
}
private
doHandleSetInputError
(
e
:
Error
,
group
:
EditorGroup
,
editor
:
BaseEditor
,
input
:
EditorInput
,
options
:
EditorOptions
,
monitor
:
ProgressMonitor
):
void
{
private
doHandleSetInputError
(
e
rror
:
Error
,
group
:
EditorGroup
,
editor
:
BaseEditor
,
input
:
EditorInput
,
options
:
EditorOptions
,
monitor
:
ProgressMonitor
):
void
{
const
position
=
this
.
stacks
.
positionOfGroup
(
group
);
// Stop loading promise if any
monitor
.
cancel
();
// Report error only if this was not us restoring previous error state
if
(
this
.
partService
.
isCreated
()
&&
!
errors
.
isPromiseCanceledError
(
e
))
{
if
(
this
.
partService
.
isCreated
()
&&
!
errors
.
isPromiseCanceledError
(
e
rror
))
{
const
actions
:
INotificationActions
=
{
primary
:
[]
};
if
(
e
&&
Array
.
isArray
((
<
IErrorWithActions
>
e
).
actions
))
{
actions
.
primary
=
(
<
IErrorWithActions
>
e
)
.
actions
;
if
(
isErrorWithActions
(
error
))
{
actions
.
primary
=
error
.
actions
;
}
this
.
notificationService
.
notify
({
severity
:
Severity
.
Error
,
message
:
nls
.
localize
(
'
editorOpenError
'
,
"
Unable to open '{0}': {1}.
"
,
input
.
getName
(),
toErrorMessage
(
e
)),
message
:
nls
.
localize
(
'
editorOpenError
'
,
"
Unable to open '{0}': {1}.
"
,
input
.
getName
(),
toErrorMessage
(
e
rror
)),
actions
});
}
...
...
src/vs/workbench/common/notifications.ts
浏览文件 @
6079bc6d
...
...
@@ -10,7 +10,7 @@ import { INotification, INotificationHandle, INotificationActions, INotification
import
{
toErrorMessage
}
from
'
vs/base/common/errorMessage
'
;
import
Event
,
{
Emitter
,
once
}
from
'
vs/base/common/event
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
isPromiseCanceledError
,
isErrorWithActions
}
from
'
vs/base/common/errors
'
;
export
interface
INotificationsModel
{
...
...
@@ -355,7 +355,14 @@ export class NotificationViewItem implements INotificationViewItem {
message
.
value
=
`
${
message
.
value
.
substr
(
0
,
NotificationViewItem
.
MAX_MESSAGE_LENGTH
)}
...`
;
}
return
new
NotificationViewItem
(
severity
,
message
,
notification
.
source
,
notification
.
actions
);
let
actions
:
INotificationActions
;
if
(
notification
.
actions
)
{
actions
=
notification
.
actions
;
}
else
if
(
isErrorWithActions
(
notification
.
message
))
{
actions
=
{
primary
:
notification
.
message
.
actions
};
}
return
new
NotificationViewItem
(
severity
,
message
,
notification
.
source
,
actions
);
}
private
static
toMarkdownString
(
input
:
string
|
IMarkdownString
|
Error
):
IMarkdownString
{
...
...
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
浏览文件 @
6079bc6d
...
...
@@ -154,16 +154,12 @@ export class TextFileEditor extends BaseTextEditor {
return
TPromise
.
wrapError
<
void
>
(
errors
.
create
(
toErrorMessage
(
error
),
{
actions
:
[
new
Action
(
'
workbench.files.action.createMissingFile
'
,
nls
.
localize
(
'
createFile
'
,
"
Create File
"
),
null
,
true
,
()
=>
{
return
this
.
fileService
.
updateContent
(
input
.
getResource
(),
''
).
then
(()
=>
{
// Open
return
this
.
editorService
.
openEditor
({
resource
:
input
.
getResource
(),
options
:
{
pinned
:
true
// new file gets pinned by default
}
});
});
return
this
.
fileService
.
updateContent
(
input
.
getResource
(),
''
).
then
(()
=>
this
.
editorService
.
openEditor
({
resource
:
input
.
getResource
(),
options
:
{
pinned
:
true
// new file gets pinned by default
}
}));
})
]
}));
...
...
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
浏览文件 @
6079bc6d
...
...
@@ -11,7 +11,6 @@ import arrays = require('vs/base/common/arrays');
import
types
=
require
(
'
vs/base/common/types
'
);
import
{
language
,
LANGUAGE_DEFAULT
}
from
'
vs/base/common/platform
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
toErrorMessage
}
from
'
vs/base/common/errorMessage
'
;
import
{
Mode
,
IEntryRunContext
,
IAutoFocus
,
IModel
,
IQuickNavigateConfiguration
}
from
'
vs/base/parts/quickopen/common/quickOpen
'
;
import
{
QuickOpenEntryGroup
,
IHighlight
,
QuickOpenModel
,
QuickOpenEntry
}
from
'
vs/base/parts/quickopen/browser/quickOpenModel
'
;
import
{
IMenuService
,
MenuId
,
MenuItemAction
}
from
'
vs/platform/actions/common/actions
'
;
...
...
@@ -32,9 +31,9 @@ import { LRUCache } from 'vs/base/common/map';
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ResolvedKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
isPromiseCanceledError
,
IErrorWithActions
}
from
'
vs/base/common/errors
'
;
import
{
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
INotificationService
,
INotificationActions
,
Severity
}
from
'
vs/platform/notification/common/notification
'
;
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
export
const
ALL_COMMANDS_PREFIX
=
'
>
'
;
...
...
@@ -275,26 +274,6 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
return
nls
.
localize
(
'
entryAriaLabel
'
,
"
{0}, commands
"
,
this
.
getLabel
());
}
private
onError
(
error
?:
Error
|
IErrorWithActions
):
void
{
if
(
isPromiseCanceledError
(
error
))
{
return
;
}
let
message
:
string
;
if
(
error
)
{
message
=
toErrorMessage
(
error
);
}
else
{
message
=
nls
.
localize
(
'
canNotRun
'
,
"
Command '{0}' can not be run from here.
"
,
this
.
label
);
}
const
actions
:
INotificationActions
=
{
primary
:
[]
};
if
(
error
&&
Array
.
isArray
((
<
IErrorWithActions
>
error
).
actions
))
{
actions
.
primary
=
(
<
IErrorWithActions
>
error
).
actions
;
}
this
.
notificationService
.
notify
({
severity
:
Severity
.
Error
,
message
,
actions
});
}
public
run
(
mode
:
Mode
,
context
:
IEntryRunContext
):
boolean
{
if
(
mode
===
Mode
.
OPEN
)
{
this
.
runAction
(
this
.
getAction
());
...
...
@@ -336,6 +315,14 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
}
},
err
=>
this
.
onError
(
err
));
}
private
onError
(
error
?:
Error
):
void
{
if
(
isPromiseCanceledError
(
error
))
{
return
;
}
this
.
notificationService
.
error
(
error
||
nls
.
localize
(
'
canNotRun
'
,
"
Command '{0}' can not be run from here.
"
,
this
.
label
));
}
}
class
EditorActionCommandEntry
extends
BaseCommandEntry
{
...
...
src/vs/workbench/test/common/notifications.test.ts
浏览文件 @
6079bc6d
...
...
@@ -9,6 +9,7 @@ import * as assert from 'assert';
import
{
NotificationsModel
,
NotificationViewItem
,
INotificationChangeEvent
,
NotificationChangeType
,
NotificationViewItemLabelKind
}
from
'
vs/workbench/common/notifications
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
INotification
,
Severity
}
from
'
vs/platform/notification/common/notification
'
;
import
{
create
}
from
'
vs/base/common/errors
'
;
suite
(
'
Notifications
'
,
()
=>
{
...
...
@@ -102,6 +103,10 @@ suite('Notifications', () => {
item1
.
dispose
();
assert
.
equal
(
called
,
1
);
// Error with Action
let
item6
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
create
(
'
Hello Error
'
,
{
actions
:
[
new
Action
(
'
id
'
,
'
label
'
)]
})
});
assert
.
equal
(
item6
.
actions
.
primary
.
length
,
1
);
});
test
(
'
Model
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录