Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
1cf80327
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1cf80327
编写于
12月 21, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[css] catch exceptions in handlers
上级
42f27420
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
97 addition
and
38 deletion
+97
-38
extensions/css/server/src/cssServerMain.ts
extensions/css/server/src/cssServerMain.ts
+63
-36
extensions/css/server/src/utils/errors.ts
extensions/css/server/src/utils/errors.ts
+33
-0
extensions/css/server/tsconfig.json
extensions/css/server/tsconfig.json
+1
-2
未找到文件。
extensions/css/server/src/cssServerMain.ts
浏览文件 @
1cf80327
...
...
@@ -15,6 +15,7 @@ import { DocumentColorRequest, ServerCapabilities as CPServerCapabilities, Color
import
{
getCSSLanguageService
,
getSCSSLanguageService
,
getLESSLanguageService
,
LanguageSettings
,
LanguageService
,
Stylesheet
}
from
'
vscode-css-languageservice
'
;
import
{
getLanguageModelCache
}
from
'
./languageModelCache
'
;
import
{
formatError
,
runSafe
}
from
'
./utils/errors
'
;
export
interface
Settings
{
css
:
LanguageSettings
;
...
...
@@ -28,6 +29,10 @@ let connection: IConnection = createConnection();
console
.
log
=
connection
.
console
.
log
.
bind
(
connection
.
console
);
console
.
error
=
connection
.
console
.
error
.
bind
(
connection
.
console
);
process
.
on
(
'
unhandledRejection
'
,
(
e
:
any
)
=>
{
connection
.
console
.
error
(
formatError
(
`Unhandled exception`
,
e
));
});
// Create a simple text document manager. The text document manager
// supports full document sync only
let
documents
:
TextDocuments
=
new
TextDocuments
();
...
...
@@ -159,73 +164,95 @@ function validateTextDocument(textDocument: TextDocument): void {
let
diagnostics
=
getLanguageService
(
textDocument
).
doValidation
(
textDocument
,
stylesheet
,
settings
);
// Send the computed diagnostics to VSCode.
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
},
e
=>
{
connection
.
console
.
error
(
formatError
(
`Error while validating
${
textDocument
.
uri
}
`
,
e
));
});
}
connection
.
onCompletion
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doComplete
(
document
,
textDocumentPosition
.
position
,
stylesheet
)
!
;
/* TODO: remove ! once LS has null annotations */
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doComplete
(
document
,
textDocumentPosition
.
position
,
stylesheet
)
!
;
/* TODO: remove ! once LS has null annotations */
},
null
,
`Error while computing completions for
${
textDocumentPosition
.
textDocument
.
uri
}
`
);
});
connection
.
onHover
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
styleSheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doHover
(
document
,
textDocumentPosition
.
position
,
styleSheet
)
!
;
/* TODO: remove ! once LS has null annotations */
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
styleSheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doHover
(
document
,
textDocumentPosition
.
position
,
styleSheet
)
!
;
/* TODO: remove ! once LS has null annotations */
},
null
,
`Error while computing hover for
${
textDocumentPosition
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentSymbol
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentSymbols
(
document
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentSymbols
(
document
,
stylesheet
);
},
[],
`Error while computing document symbols for
${
documentSymbolParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDefinition
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDefinition
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDefinition
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
},
null
,
`Error while computing definitions for
${
documentSymbolParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentHighlight
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentHighlights
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentHighlights
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
},
[],
`Error while computing document highlights for
${
documentSymbolParams
.
textDocument
.
uri
}
`
);
});
connection
.
onReferences
(
referenceParams
=>
{
let
document
=
documents
.
get
(
referenceParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findReferences
(
document
,
referenceParams
.
position
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
referenceParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findReferences
(
document
,
referenceParams
.
position
,
stylesheet
);
},
[],
`Error while computing references for
${
referenceParams
.
textDocument
.
uri
}
`
);
});
connection
.
onCodeAction
(
codeActionParams
=>
{
let
document
=
documents
.
get
(
codeActionParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doCodeActions
(
document
,
codeActionParams
.
range
,
codeActionParams
.
context
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
codeActionParams
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doCodeActions
(
document
,
codeActionParams
.
range
,
codeActionParams
.
context
,
stylesheet
);
},
[],
`Error while computing code actions for
${
codeActionParams
.
textDocument
.
uri
}
`
);
});
connection
.
onRequest
(
DocumentColorRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentColors
(
document
,
stylesheet
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
findDocumentColors
(
document
,
stylesheet
);
}
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
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
getColorPresentations
(
document
,
stylesheet
,
params
.
color
,
params
.
range
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
getColorPresentations
(
document
,
stylesheet
,
params
.
color
,
params
.
range
);
}
return
[];
},
[],
`Error while computing color presentations for
${
params
.
textDocument
.
uri
}
`
);
});
connection
.
onRenameRequest
(
renameParameters
=>
{
let
document
=
documents
.
get
(
renameParameters
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doRename
(
document
,
renameParameters
.
position
,
renameParameters
.
newName
,
stylesheet
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
renameParameters
.
textDocument
.
uri
);
let
stylesheet
=
stylesheets
.
get
(
document
);
return
getLanguageService
(
document
).
doRename
(
document
,
renameParameters
.
position
,
renameParameters
.
newName
,
stylesheet
);
},
null
,
`Error while computing renames for
${
renameParameters
.
textDocument
.
uri
}
`
);
});
// Listen on the connection
...
...
extensions/css/server/src/utils/errors.ts
0 → 100644
浏览文件 @
1cf80327
/*---------------------------------------------------------------------------------------------
* 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
extensions/css/server/tsconfig.json
浏览文件 @
1cf80327
...
...
@@ -6,8 +6,7 @@
"noUnusedLocals"
:
true
,
"lib"
:
[
"es5"
,
"es2015.promise"
],
"strict"
:
true
]
},
"include"
:
[
"src/**/*"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录