Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1d921de3
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,发现更多精彩内容 >>
提交
1d921de3
编写于
12月 21, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[html] catch exceptions in handlers
上级
1cf80327
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
179 addition
and
111 deletion
+179
-111
extensions/html/server/src/htmlServerMain.ts
extensions/html/server/src/htmlServerMain.ts
+146
-111
extensions/html/server/src/utils/errors.ts
extensions/html/server/src/utils/errors.ts
+33
-0
未找到文件。
extensions/html/server/src/htmlServerMain.ts
浏览文件 @
1d921de3
...
...
@@ -16,6 +16,7 @@ import { format } from './modes/formatting';
import
{
pushAll
}
from
'
./utils/arrays
'
;
import
{
getDocumentContext
}
from
'
./utils/documentContext
'
;
import
uri
from
'
vscode-uri
'
;
import
{
formatError
,
runSafe
}
from
'
./utils/errors
'
;
import
*
as
nls
from
'
vscode-nls
'
;
...
...
@@ -31,6 +32,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
();
...
...
@@ -208,165 +213,195 @@ function isValidationEnabled(languageId: string, settings: Settings = globalSett
}
async
function
validateTextDocument
(
textDocument
:
TextDocument
)
{
let
diagnostics
:
Diagnostic
[]
=
[];
if
(
textDocument
.
languageId
===
'
html
'
)
{
let
modes
=
languageModes
.
getAllModesInDocument
(
textDocument
);
let
settings
=
await
getDocumentSettings
(
textDocument
,
()
=>
modes
.
some
(
m
=>
!!
m
.
doValidation
));
modes
.
forEach
(
mode
=>
{
if
(
mode
.
doValidation
&&
isValidationEnabled
(
mode
.
getId
(),
settings
))
{
pushAll
(
diagnostics
,
mode
.
doValidation
(
textDocument
,
settings
));
}
});
try
{
let
diagnostics
:
Diagnostic
[]
=
[];
if
(
textDocument
.
languageId
===
'
html
'
)
{
let
modes
=
languageModes
.
getAllModesInDocument
(
textDocument
);
let
settings
=
await
getDocumentSettings
(
textDocument
,
()
=>
modes
.
some
(
m
=>
!!
m
.
doValidation
));
modes
.
forEach
(
mode
=>
{
if
(
mode
.
doValidation
&&
isValidationEnabled
(
mode
.
getId
(),
settings
))
{
pushAll
(
diagnostics
,
mode
.
doValidation
(
textDocument
,
settings
));
}
});
}
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
}
catch
(
e
)
{
connection
.
console
.
error
(
formatError
(
`Error while validating
${
textDocument
.
uri
}
`
,
e
));
}
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
}
connection
.
onCompletion
(
async
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
textDocumentPosition
.
position
);
if
(
mode
&&
mode
.
doComplete
)
{
let
doComplete
=
mode
.
doComplete
;
if
(
mode
.
getId
()
!==
'
html
'
)
{
connection
.
telemetry
.
logEvent
({
key
:
'
html.embbedded.complete
'
,
value
:
{
languageId
:
mode
.
getId
()
}
});
return
runSafe
(
async
()
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
textDocumentPosition
.
position
);
if
(
mode
&&
mode
.
doComplete
)
{
let
doComplete
=
mode
.
doComplete
;
if
(
mode
.
getId
()
!==
'
html
'
)
{
connection
.
telemetry
.
logEvent
({
key
:
'
html.embbedded.complete
'
,
value
:
{
languageId
:
mode
.
getId
()
}
});
}
let
settings
=
await
getDocumentSettings
(
document
,
()
=>
doComplete
.
length
>
2
);
return
doComplete
(
document
,
textDocumentPosition
.
position
,
settings
);
}
let
settings
=
await
getDocumentSettings
(
document
,
()
=>
doComplete
.
length
>
2
);
return
doComplete
(
document
,
textDocumentPosition
.
position
,
settings
);
}
return
{
isIncomplete
:
true
,
items
:
[]
};
return
{
isIncomplete
:
true
,
items
:
[]
};
},
null
,
`Error while computing completions for
${
textDocumentPosition
.
textDocument
.
uri
}
`
);
});
connection
.
onCompletionResolve
(
item
=>
{
let
data
=
item
.
data
;
if
(
data
&&
data
.
languageId
&&
data
.
uri
)
{
let
mode
=
languageModes
.
getMode
(
data
.
languageId
);
let
document
=
documents
.
get
(
data
.
uri
);
if
(
mode
&&
mode
.
doResolve
&&
document
)
{
return
mode
.
doResolve
(
document
,
item
);
return
runSafe
(()
=>
{
let
data
=
item
.
data
;
if
(
data
&&
data
.
languageId
&&
data
.
uri
)
{
let
mode
=
languageModes
.
getMode
(
data
.
languageId
);
let
document
=
documents
.
get
(
data
.
uri
);
if
(
mode
&&
mode
.
doResolve
&&
document
)
{
return
mode
.
doResolve
(
document
,
item
);
}
}
}
return
item
;
return
item
;
},
null
,
`Error while resolving completion proposal`
)
;
});
connection
.
onHover
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
textDocumentPosition
.
position
);
if
(
mode
&&
mode
.
doHover
)
{
return
mode
.
doHover
(
document
,
textDocumentPosition
.
position
);
}
return
null
;
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
textDocumentPosition
.
position
);
if
(
mode
&&
mode
.
doHover
)
{
return
mode
.
doHover
(
document
,
textDocumentPosition
.
position
);
}
return
null
;
},
null
,
`Error while computing hover for
${
textDocumentPosition
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentHighlight
(
documentHighlightParams
=>
{
let
document
=
documents
.
get
(
documentHighlightParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
documentHighlightParams
.
position
);
if
(
mode
&&
mode
.
findDocumentHighlight
)
{
return
mode
.
findDocumentHighlight
(
document
,
documentHighlightParams
.
position
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentHighlightParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
documentHighlightParams
.
position
);
if
(
mode
&&
mode
.
findDocumentHighlight
)
{
return
mode
.
findDocumentHighlight
(
document
,
documentHighlightParams
.
position
);
}
return
[];
},
[],
`Error while computing document highlights for
${
documentHighlightParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDefinition
(
definitionParams
=>
{
let
document
=
documents
.
get
(
definitionParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
definitionParams
.
position
);
if
(
mode
&&
mode
.
findDefinition
)
{
return
mode
.
findDefinition
(
document
,
definitionParams
.
position
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
definitionParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
definitionParams
.
position
);
if
(
mode
&&
mode
.
findDefinition
)
{
return
mode
.
findDefinition
(
document
,
definitionParams
.
position
);
}
return
[];
},
null
,
`Error while computing definitions for
${
definitionParams
.
textDocument
.
uri
}
`
);
});
connection
.
onReferences
(
referenceParams
=>
{
let
document
=
documents
.
get
(
referenceParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
referenceParams
.
position
);
if
(
mode
&&
mode
.
findReferences
)
{
return
mode
.
findReferences
(
document
,
referenceParams
.
position
);
}
return
[];
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
referenceParams
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
referenceParams
.
position
);
if
(
mode
&&
mode
.
findReferences
)
{
return
mode
.
findReferences
(
document
,
referenceParams
.
position
);
}
return
[];
},
[],
`Error while computing references for
${
referenceParams
.
textDocument
.
uri
}
`
);
});
connection
.
onSignatureHelp
(
signatureHelpParms
=>
{
let
document
=
documents
.
get
(
signatureHelpParms
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
signatureHelpParms
.
position
);
if
(
mode
&&
mode
.
doSignatureHelp
)
{
return
mode
.
doSignatureHelp
(
document
,
signatureHelpParms
.
position
);
}
return
null
;
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
signatureHelpParms
.
textDocument
.
uri
);
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
signatureHelpParms
.
position
);
if
(
mode
&&
mode
.
doSignatureHelp
)
{
return
mode
.
doSignatureHelp
(
document
,
signatureHelpParms
.
position
);
}
return
null
;
},
null
,
`Error while computing signature help for
${
signatureHelpParms
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentRangeFormatting
(
async
formatParams
=>
{
let
document
=
documents
.
get
(
formatParams
.
textDocument
.
uri
);
let
settings
=
await
getDocumentSettings
(
document
,
()
=>
true
);
if
(
!
settings
)
{
settings
=
globalSettings
;
}
let
unformattedTags
:
string
=
settings
&&
settings
.
html
&&
settings
.
html
.
format
&&
settings
.
html
.
format
.
unformatted
||
''
;
let
enabledModes
=
{
css
:
!
unformattedTags
.
match
(
/
\b
style
\b
/
),
javascript
:
!
unformattedTags
.
match
(
/
\b
script
\b
/
)
};
return
runSafe
(
async
()
=>
{
let
document
=
documents
.
get
(
formatParams
.
textDocument
.
uri
);
let
settings
=
await
getDocumentSettings
(
document
,
()
=>
true
);
if
(
!
settings
)
{
settings
=
globalSettings
;
}
let
unformattedTags
:
string
=
settings
&&
settings
.
html
&&
settings
.
html
.
format
&&
settings
.
html
.
format
.
unformatted
||
''
;
let
enabledModes
=
{
css
:
!
unformattedTags
.
match
(
/
\b
style
\b
/
),
javascript
:
!
unformattedTags
.
match
(
/
\b
script
\b
/
)
};
return
format
(
languageModes
,
document
,
formatParams
.
range
,
formatParams
.
options
,
settings
,
enabledModes
);
return
format
(
languageModes
,
document
,
formatParams
.
range
,
formatParams
.
options
,
settings
,
enabledModes
);
},
[],
`Error while formatting range for
${
formatParams
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentLinks
(
documentLinkParam
=>
{
let
document
=
documents
.
get
(
documentLinkParam
.
textDocument
.
uri
);
let
links
:
DocumentLink
[]
=
[];
if
(
document
)
{
let
documentContext
=
getDocumentContext
(
document
.
uri
,
workspaceFolders
);
languageModes
.
getAllModesInDocument
(
document
).
forEach
(
m
=>
{
if
(
m
.
findDocumentLinks
)
{
pushAll
(
links
,
m
.
findDocumentLinks
(
document
,
documentContext
));
}
});
}
return
links
;
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentLinkParam
.
textDocument
.
uri
);
let
links
:
DocumentLink
[]
=
[];
if
(
document
)
{
let
documentContext
=
getDocumentContext
(
document
.
uri
,
workspaceFolders
);
languageModes
.
getAllModesInDocument
(
document
).
forEach
(
m
=>
{
if
(
m
.
findDocumentLinks
)
{
pushAll
(
links
,
m
.
findDocumentLinks
(
document
,
documentContext
));
}
});
}
return
links
;
},
[],
`Error while document links for
${
documentLinkParam
.
textDocument
.
uri
}
`
);
});
connection
.
onDocumentSymbol
(
documentSymbolParms
=>
{
let
document
=
documents
.
get
(
documentSymbolParms
.
textDocument
.
uri
);
let
symbols
:
SymbolInformation
[]
=
[];
languageModes
.
getAllModesInDocument
(
document
).
forEach
(
m
=>
{
if
(
m
.
findDocumentSymbols
)
{
pushAll
(
symbols
,
m
.
findDocumentSymbols
(
document
));
}
});
return
symbols
;
});
connection
.
onRequest
(
DocumentColorRequest
.
type
,
params
=>
{
let
infos
:
ColorInformation
[]
=
[];
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
documentSymbolParms
.
textDocument
.
uri
);
let
symbols
:
SymbolInformation
[]
=
[];
languageModes
.
getAllModesInDocument
(
document
).
forEach
(
m
=>
{
if
(
m
.
findDocument
Color
s
)
{
pushAll
(
infos
,
m
.
findDocumentColor
s
(
document
));
if
(
m
.
findDocument
Symbol
s
)
{
pushAll
(
symbols
,
m
.
findDocumentSymbol
s
(
document
));
}
});
}
return
infos
;
return
symbols
;
},
[],
`Error while computing document symbols for
${
documentSymbolParms
.
textDocument
.
uri
}
`
);
});
connection
.
onRequest
(
DocumentColorRequest
.
type
,
params
=>
{
return
runSafe
(()
=>
{
let
infos
:
ColorInformation
[]
=
[];
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
languageModes
.
getAllModesInDocument
(
document
).
forEach
(
m
=>
{
if
(
m
.
findDocumentColors
)
{
pushAll
(
infos
,
m
.
findDocumentColors
(
document
));
}
});
}
return
infos
;
},
[],
`Error while computing document colors for
${
params
.
textDocument
.
uri
}
`
);
});
connection
.
onRequest
(
ColorPresentationRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
params
.
range
.
start
);
if
(
mode
&&
mode
.
getColorPresentations
)
{
return
mode
.
getColorPresentations
(
document
,
params
.
color
,
params
.
range
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
params
.
range
.
start
);
if
(
mode
&&
mode
.
getColorPresentations
)
{
return
mode
.
getColorPresentations
(
document
,
params
.
color
,
params
.
range
);
}
}
}
return
[]
;
return
[];
},
[],
`Error while computing color presentations for
${
params
.
textDocument
.
uri
}
`
)
;
});
connection
.
onRequest
(
TagCloseRequest
.
type
,
params
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
pos
=
params
.
position
;
if
(
pos
.
character
>
0
)
{
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
Position
.
create
(
pos
.
line
,
pos
.
character
-
1
));
if
(
mode
&&
mode
.
doAutoClose
)
{
return
mode
.
doAutoClose
(
document
,
pos
);
return
runSafe
(()
=>
{
let
document
=
documents
.
get
(
params
.
textDocument
.
uri
);
if
(
document
)
{
let
pos
=
params
.
position
;
if
(
pos
.
character
>
0
)
{
let
mode
=
languageModes
.
getModeAtPosition
(
document
,
Position
.
create
(
pos
.
line
,
pos
.
character
-
1
));
if
(
mode
&&
mode
.
doAutoClose
)
{
return
mode
.
doAutoClose
(
document
,
pos
);
}
}
}
}
return
null
;
return
null
;
},
null
,
`Error while computing tag close actions for
${
params
.
textDocument
.
uri
}
`
)
;
});
...
...
extensions/html/server/src/utils/errors.ts
0 → 100644
浏览文件 @
1d921de3
/*---------------------------------------------------------------------------------------------
* 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录