Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
76f27441
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,体验更适合开发者的 AI 搜索 >>
提交
76f27441
编写于
12月 07, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[json] catch and log exceptions
上级
0a06597b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
31 deletion
+86
-31
extensions/json/server/src/jsonServerMain.ts
extensions/json/server/src/jsonServerMain.ts
+53
-31
extensions/json/server/src/utils/errors.ts
extensions/json/server/src/utils/errors.ts
+33
-0
未找到文件。
extensions/json/server/src/jsonServerMain.ts
浏览文件 @
76f27441
...
...
@@ -17,6 +17,7 @@ import fs = require('fs');
import
URI
from
'
vscode-uri
'
;
import
*
as
URL
from
'
url
'
;
import
Strings
=
require
(
'
./utils/strings
'
);
import
{
formatError
,
runSafe
}
from
'
./utils/errors
'
;
import
{
JSONDocument
,
JSONSchema
,
LanguageSettings
,
getLanguageService
,
DocumentLanguageSettings
}
from
'
vscode-json-languageservice
'
;
import
{
getLanguageModelCache
}
from
'
./languageModelCache
'
;
...
...
@@ -42,6 +43,10 @@ namespace SchemaContentChangeNotification {
// Create a connection for the server
let
connection
:
IConnection
=
createConnection
();
process
.
on
(
'
unhandledRejection
'
,
e
=>
{
connection
.
console
.
error
(
formatError
(
`Unhandled exception`
,
e
));
});
console
.
log
=
connection
.
console
.
log
.
bind
(
connection
.
console
);
console
.
error
=
connection
.
console
.
error
.
bind
(
connection
.
console
);
...
...
@@ -251,14 +256,17 @@ function validateTextDocument(textDocument: TextDocument): void {
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
:
[]
});
return
;
}
try
{
let
jsonDocument
=
getJSONDocument
(
textDocument
);
let
jsonDocument
=
getJSONDocument
(
textDocument
);
let
documentSettings
:
DocumentLanguageSettings
=
textDocument
.
languageId
===
'
jsonc
'
?
{
comments
:
'
ignore
'
,
trailingCommas
:
'
ignore
'
}
:
{
comments
:
'
error
'
,
trailingCommas
:
'
error
'
};
languageService
.
doValidation
(
textDocument
,
jsonDocument
,
documentSettings
).
then
(
diagnostics
=>
{
// Send the computed diagnostics to VSCode.
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
});
let
documentSettings
:
DocumentLanguageSettings
=
textDocument
.
languageId
===
'
jsonc
'
?
{
comments
:
'
ignore
'
,
trailingCommas
:
'
ignore
'
}
:
{
comments
:
'
error
'
,
trailingCommas
:
'
error
'
};
languageService
.
doValidation
(
textDocument
,
jsonDocument
,
documentSettings
).
then
(
diagnostics
=>
{
// Send the computed diagnostics to VSCode.
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
});
}
catch
(
e
)
{
connection
.
console
.
error
(
formatError
(
`Error while validating
${
textDocument
.
uri
}
`
,
e
));
}
}
connection
.
onDidChangeWatchedFiles
((
change
)
=>
{
...
...
@@ -287,48 +295,62 @@ function getJSONDocument(document: TextDocument): JSONDocument {
}
connection
.
onCompletion
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
doComplete
(
document
,
textDocumentPosition
.
position
,
jsonDocument
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
doComplete
(
document
,
textDocumentPosition
.
position
,
jsonDocument
);
},
null
,
`Error while computing completions for
${
textDocumentPosition
.
textDocument
.
uri
}
`
);
});
connection
.
onCompletionResolve
(
completionItem
=>
{
return
languageService
.
doResolve
(
completionItem
);
return
runSafe
(()
=>
{
return
languageService
.
doResolve
(
completionItem
);
},
null
,
`Error while resolving completion proposal`
);
});
connection
.
onHover
(
textDocumentPositionParams
=>
{
let
document
=
documents
.
get
(
textDocumentPositionParams
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
doHover
(
document
,
textDocumentPositionParams
.
position
,
jsonDocument
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
textDocumentPositionParams
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
doHover
(
document
,
textDocumentPositionParams
.
position
,
jsonDocument
);
},
null
,
`Error while computing hover for
${
textDocumentPositionParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentSymbol
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
findDocumentSymbols
(
document
,
jsonDocument
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
findDocumentSymbols
(
document
,
jsonDocument
);
},
[],
`Error while computing document symbols for
${
documentSymbolParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentRangeFormatting
(
formatParams
=>
{
let
document
=
documents
.
get
(
formatParams
.
textDocument
.
uri
);
return
languageService
.
format
(
document
,
formatParams
.
range
,
formatParams
.
options
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
formatParams
.
textDocument
.
uri
);
return
languageService
.
format
(
document
,
formatParams
.
range
,
formatParams
.
options
);
},
[],
`Error while formatting range for
${
formatParams
.
textDocument
.
uri
}
`
);
});
connection
.
onRequest
(
DocumentColorRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
findDocumentColors
(
document
,
jsonDocument
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
findDocumentColors
(
document
,
jsonDocument
);
}
return
[];
},
[],
`Error while computing document colors for
${
params
.
textDocument
.
uri
}
`
);
});
connection
.
onRequest
(
ColorPresentationRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
getColorPresentations
(
document
,
jsonDocument
,
params
.
color
,
params
.
range
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
jsonDocument
=
getJSONDocument
(
document
);
return
languageService
.
getColorPresentations
(
document
,
jsonDocument
,
params
.
color
,
params
.
range
);
}
return
[];
},
[],
`Error while computing color presentationsd for
${
params
.
textDocument
.
uri
}
`
);
});
// Listen on the connection
...
...
extensions/json/server/src/utils/errors.ts
0 → 100644
浏览文件 @
76f27441
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
export
function
formatError
(
message
:
string
,
err
:
any
):
string
{
if
(
err
instanceof
Error
)
{
let
error
=
<
Error
>
err
;
return
`
${
message
}
:
${
error
.
message
}
\n
${
error
.
stack
}
`
;
}
else
if
(
typeof
err
===
'
string
'
)
{
return
`
${
message
}
:
${
err
}
`
;
}
else
if
(
err
)
{
return
`
${
message
}
:
${
err
.
toString
()}
`
;
}
return
message
;
}
export
function
runSafe
<
T
>
(
func
:
()
=>
Thenable
<
T
>
|
T
,
errorVal
:
T
,
errorMessage
:
string
):
Thenable
<
T
>
|
T
{
try
{
let
t
=
func
();
if
(
t
instanceof
Promise
)
{
return
t
.
then
(
void
0
,
e
=>
{
console
.
error
(
formatError
(
errorMessage
,
e
));
return
errorVal
;
});
}
return
t
;
}
catch
(
e
)
{
console
.
error
(
formatError
(
errorMessage
,
e
));
return
errorVal
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录