Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4b6df2f8
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
4b6df2f8
编写于
11月 08, 2017
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Encapsulate TS/JS diagnostics in class
上级
284779f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
35 deletion
+89
-35
extensions/typescript/src/features/diagnostics.ts
extensions/typescript/src/features/diagnostics.ts
+72
-0
extensions/typescript/src/typescriptMain.ts
extensions/typescript/src/typescriptMain.ts
+12
-30
extensions/typescript/src/utils/commandManager.ts
extensions/typescript/src/utils/commandManager.ts
+5
-5
未找到文件。
extensions/typescript/src/features/diagnostics.ts
0 → 100644
浏览文件 @
4b6df2f8
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Diagnostic
,
DiagnosticCollection
,
languages
}
from
'
vscode
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
export
default
class
DiagnosticsManager
{
private
syntaxDiagnostics
:
ObjectMap
<
Diagnostic
[]
>
;
private
semanticDiagnostics
:
ObjectMap
<
Diagnostic
[]
>
;
private
readonly
currentDiagnostics
:
DiagnosticCollection
;
private
_validate
:
boolean
=
true
;
constructor
(
language
:
string
,
private
readonly
client
:
ITypeScriptServiceClient
)
{
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
this
.
currentDiagnostics
=
languages
.
createDiagnosticCollection
(
language
);
}
public
dispose
()
{
this
.
currentDiagnostics
.
dispose
();
}
public
reInitialize
():
void
{
this
.
currentDiagnostics
.
clear
();
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
}
public
updateValidate
(
value
:
boolean
)
{
if
(
this
.
_validate
===
value
)
{
return
;
}
this
.
_validate
=
value
;
if
(
!
value
)
{
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
this
.
currentDiagnostics
.
clear
();
}
}
public
syntaxDiagnosticsReceived
(
file
:
string
,
syntaxDiagnostics
:
Diagnostic
[]):
void
{
if
(
!
this
.
_validate
)
{
return
;
}
this
.
syntaxDiagnostics
[
file
]
=
syntaxDiagnostics
;
const
semanticDianostics
=
this
.
semanticDiagnostics
[
file
]
||
[];
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
),
semanticDianostics
.
concat
(
syntaxDiagnostics
));
}
public
semanticDiagnosticsReceived
(
file
:
string
,
semanticDiagnostics
:
Diagnostic
[]):
void
{
if
(
!
this
.
_validate
)
{
return
;
}
this
.
semanticDiagnostics
[
file
]
=
semanticDiagnostics
;
const
syntaxDiagnostics
=
this
.
syntaxDiagnostics
[
file
]
||
[];
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
),
semanticDiagnostics
.
concat
(
syntaxDiagnostics
));
}
public
configFileDiagnosticsReceived
(
file
:
string
,
diagnostics
:
Diagnostic
[]):
void
{
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
),
diagnostics
);
}
public
delete
(
file
:
string
)
{
this
.
currentDiagnostics
.
delete
(
this
.
client
.
asUrl
(
file
));
}
}
\ No newline at end of file
extensions/typescript/src/typescriptMain.ts
浏览文件 @
4b6df2f8
...
...
@@ -8,7 +8,7 @@
* https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences
* ------------------------------------------------------------------------------------------ */
import
{
env
,
languages
,
commands
,
workspace
,
window
,
ExtensionContext
,
Memento
,
IndentAction
,
Diagnostic
,
DiagnosticCollection
,
Range
,
Disposable
,
Uri
,
MessageItem
,
DiagnosticSeverity
,
TextDocument
}
from
'
vscode
'
;
import
{
env
,
languages
,
commands
,
workspace
,
window
,
ExtensionContext
,
Memento
,
IndentAction
,
Diagnostic
,
Range
,
Disposable
,
Uri
,
MessageItem
,
DiagnosticSeverity
,
TextDocument
}
from
'
vscode
'
;
// This must be the first statement otherwise modules might got loaded with
// the wrong locale.
...
...
@@ -36,6 +36,7 @@ import { tsLocationToVsPosition } from './utils/convert';
import
FormattingConfigurationManager
from
'
./features/formattingConfigurationManager
'
;
import
*
as
languageModeIds
from
'
./utils/languageModeIds
'
;
import
{
CommandManager
,
Command
}
from
'
./utils/commandManager
'
;
import
DiagnosticsManager
from
'
./features/diagnostics
'
;
interface
LanguageDescription
{
id
:
string
;
...
...
@@ -224,11 +225,8 @@ export function activate(context: ExtensionContext): void {
const
validateSetting
=
'
validate.enable
'
;
class
LanguageProvider
{
private
diagnosticsManager
:
DiagnosticsManager
;
private
syntaxDiagnostics
:
ObjectMap
<
Diagnostic
[]
>
;
private
semanticDiagnostics
:
ObjectMap
<
Diagnostic
[]
>
;
private
readonly
currentDiagnostics
:
DiagnosticCollection
;
private
readonly
bufferSyncSupport
:
BufferSyncSupport
;
private
readonly
formattingOptionsManager
:
FormattingConfigurationManager
;
...
...
@@ -250,12 +248,11 @@ class LanguageProvider {
this
.
formattingOptionsManager
=
new
FormattingConfigurationManager
(
client
);
this
.
bufferSyncSupport
=
new
BufferSyncSupport
(
client
,
description
.
modeIds
,
{
delete
:
(
file
:
string
)
=>
{
this
.
currentDiagnostics
.
delete
(
client
.
asUrl
(
file
)
);
this
.
diagnosticsManager
.
delete
(
file
);
}
},
this
.
_validate
);
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
this
.
currentDiagnostics
=
languages
.
createDiagnosticCollection
(
description
.
id
);
this
.
diagnosticsManager
=
new
DiagnosticsManager
(
description
.
id
,
this
.
client
);
this
.
typingsStatus
=
new
TypingsStatus
(
client
);
this
.
ataProgressReporter
=
new
AtaProgressReporter
(
client
);
...
...
@@ -288,7 +285,7 @@ class LanguageProvider {
this
.
typingsStatus
.
dispose
();
this
.
ataProgressReporter
.
dispose
();
this
.
currentDiagnostics
.
dispose
();
this
.
diagnosticsManager
.
dispose
();
this
.
bufferSyncSupport
.
dispose
();
}
...
...
@@ -412,19 +409,14 @@ class LanguageProvider {
}
this
.
_validate
=
value
;
this
.
bufferSyncSupport
.
validate
=
value
;
this
.
diagnosticsManager
.
updateValidate
(
value
);
if
(
value
)
{
this
.
triggerAllDiagnostics
();
}
else
{
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
this
.
currentDiagnostics
.
clear
();
}
}
public
reInitialize
():
void
{
this
.
currentDiagnostics
.
clear
();
this
.
syntaxDiagnostics
=
Object
.
create
(
null
);
this
.
semanticDiagnostics
=
Object
.
create
(
null
);
this
.
diagnosticsManager
.
reInitialize
();
this
.
bufferSyncSupport
.
reOpenDocuments
();
this
.
bufferSyncSupport
.
requestAllDiagnostics
();
this
.
formattingOptionsManager
.
reset
();
...
...
@@ -459,25 +451,15 @@ class LanguageProvider {
}
public
syntaxDiagnosticsReceived
(
file
:
string
,
syntaxDiagnostics
:
Diagnostic
[]):
void
{
if
(
!
this
.
_validate
)
{
return
;
}
this
.
syntaxDiagnostics
[
file
]
=
syntaxDiagnostics
;
const
semanticDianostics
=
this
.
semanticDiagnostics
[
file
]
||
[];
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
),
semanticDianostics
.
concat
(
syntaxDiagnostics
));
this
.
diagnosticsManager
.
syntaxDiagnosticsReceived
(
file
,
syntaxDiagnostics
);
}
public
semanticDiagnosticsReceived
(
file
:
string
,
semanticDiagnostics
:
Diagnostic
[]):
void
{
if
(
!
this
.
_validate
)
{
return
;
}
this
.
semanticDiagnostics
[
file
]
=
semanticDiagnostics
;
const
syntaxDiagnostics
=
this
.
syntaxDiagnostics
[
file
]
||
[];
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
),
semanticDiagnostics
.
concat
(
syntaxDiagnostics
));
this
.
diagnosticsManager
.
semanticDiagnosticsReceived
(
file
,
semanticDiagnostics
);
}
public
configFileDiagnosticsReceived
(
file
:
string
,
diagnostics
:
Diagnostic
[]):
void
{
this
.
currentDiagnostics
.
set
(
this
.
client
.
asUrl
(
file
)
,
diagnostics
);
this
.
diagnosticsManager
.
configFileDiagnosticsReceived
(
file
,
diagnostics
);
}
}
...
...
extensions/typescript/src/utils/commandManager.ts
浏览文件 @
4b6df2f8
...
...
@@ -21,6 +21,11 @@ export class CommandManager {
this
.
commands
.
clear
();
}
public
register
<
T
extends
Command
>
(
command
:
T
):
T
{
this
.
registerCommand
(
command
.
id
,
command
.
execute
,
command
);
return
command
;
}
private
registerCommand
(
id
:
string
,
impl
:
(...
args
:
any
[])
=>
void
,
thisArg
?:
any
)
{
if
(
this
.
commands
.
has
(
id
))
{
return
;
...
...
@@ -28,9 +33,4 @@ export class CommandManager {
this
.
commands
.
set
(
id
,
vscode
.
commands
.
registerCommand
(
id
,
impl
,
thisArg
));
}
public
register
<
T
extends
Command
>
(
command
:
T
):
T
{
this
.
registerCommand
(
command
.
id
,
command
.
execute
,
command
);
return
command
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录