Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e25312d0
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,发现更多精彩内容 >>
提交
e25312d0
编写于
4月 01, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ordering
上级
5723a2d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
40 deletion
+41
-40
src/vs/editor/common/services/modelServiceImpl.ts
src/vs/editor/common/services/modelServiceImpl.ts
+41
-40
未找到文件。
src/vs/editor/common/services/modelServiceImpl.ts
浏览文件 @
e25312d0
...
...
@@ -30,13 +30,13 @@ import {DEFAULT_INDENTATION} from 'vs/editor/common/config/defaultConfig';
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
export
interface
IRawModelData
{
url
:
URI
;
versionId
:
number
;
value
:
editorCommon
.
IRawText
;
modeId
:
string
;
url
:
URI
;
versionId
:
number
;
value
:
editorCommon
.
IRawText
;
modeId
:
string
;
}
function
MODEL_ID
(
resource
:
URI
):
string
{
function
MODEL_ID
(
resource
:
URI
):
string
{
return
resource
.
toString
();
}
...
...
@@ -47,7 +47,7 @@ class ModelData implements IDisposable {
private
_markerDecorations
:
string
[];
private
_modelEventsListener
:
IDisposable
;
constructor
(
model
:
editorCommon
.
IModel
,
eventsHandler
:
(
modelData
:
ModelData
,
events
:
IEmitterEvent
[])
=>
void
)
{
constructor
(
model
:
editorCommon
.
IModel
,
eventsHandler
:
(
modelData
:
ModelData
,
events
:
IEmitterEvent
[])
=>
void
)
{
this
.
model
=
model
;
this
.
isSyncedToWorkers
=
false
;
...
...
@@ -66,19 +66,19 @@ class ModelData implements IDisposable {
return
MODEL_ID
(
this
.
model
.
getAssociatedResource
());
}
public
acceptMarkerDecorations
(
newDecorations
:
editorCommon
.
IModelDeltaDecoration
[]):
void
{
public
acceptMarkerDecorations
(
newDecorations
:
editorCommon
.
IModelDeltaDecoration
[]):
void
{
this
.
_markerDecorations
=
this
.
model
.
deltaDecorations
(
this
.
_markerDecorations
,
newDecorations
);
}
}
class
ModelMarkerHandler
{
public
static
setMarkers
(
modelData
:
ModelData
,
markers
:
IMarker
[]):
void
{
public
static
setMarkers
(
modelData
:
ModelData
,
markers
:
IMarker
[]):
void
{
// Limit to the first 500 errors/warnings
markers
=
markers
.
slice
(
0
,
500
);
let
newModelDecorations
:
editorCommon
.
IModelDeltaDecoration
[]
=
markers
.
map
((
marker
)
=>
{
let
newModelDecorations
:
editorCommon
.
IModelDeltaDecoration
[]
=
markers
.
map
((
marker
)
=>
{
return
{
range
:
this
.
_createDecorationRange
(
modelData
.
model
,
marker
),
options
:
this
.
_createDecorationOption
(
marker
)
...
...
@@ -88,7 +88,7 @@ class ModelMarkerHandler {
modelData
.
acceptMarkerDecorations
(
newModelDecorations
);
}
private
static
_createDecorationRange
(
model
:
editorCommon
.
IModel
,
rawMarker
:
IMarker
):
editorCommon
.
IRange
{
private
static
_createDecorationRange
(
model
:
editorCommon
.
IModel
,
rawMarker
:
IMarker
):
editorCommon
.
IRange
{
let
marker
=
model
.
validateRange
(
new
Range
(
rawMarker
.
startLineNumber
,
rawMarker
.
startColumn
,
rawMarker
.
endLineNumber
,
rawMarker
.
endColumn
));
let
ret
:
editorCommon
.
IEditorRange
=
new
Range
(
marker
.
startLineNumber
,
marker
.
startColumn
,
marker
.
endLineNumber
,
marker
.
endColumn
);
if
(
ret
.
isEmpty
())
{
...
...
@@ -102,7 +102,7 @@ class ModelMarkerHandler {
if
(
maxColumn
===
1
)
{
// empty line
// console.warn('marker on empty line:', marker);
// console.warn('marker on empty line:', marker);
}
else
if
(
ret
.
endColumn
>=
maxColumn
)
{
// behind eol
ret
.
endColumn
=
maxColumn
;
...
...
@@ -122,7 +122,7 @@ class ModelMarkerHandler {
return
ret
;
}
private
static
_createDecorationOption
(
marker
:
IMarker
):
editorCommon
.
IModelDecorationOptions
{
private
static
_createDecorationOption
(
marker
:
IMarker
):
editorCommon
.
IModelDecorationOptions
{
let
className
:
string
;
let
color
:
string
;
...
...
@@ -206,7 +206,7 @@ export class ModelServiceImpl implements IModelService {
/**
* All the models known in the system.
*/
private
_models
:
{
[
modelId
:
string
]:
ModelData
;
};
private
_models
:
{
[
modelId
:
string
]:
ModelData
;
};
constructor
(
threadService
:
IThreadService
,
...
...
@@ -228,8 +228,18 @@ export class ModelServiceImpl implements IModelService {
this
.
_configurationService
=
configurationService
;
this
.
_messageService
=
messageService
;
this
.
_hasShownMigrationMessage
=
false
;
this
.
_models
=
{};
this
.
_onModelAdded
=
new
Emitter
<
editorCommon
.
IModel
>
();
this
.
_onModelRemoved
=
new
Emitter
<
editorCommon
.
IModel
>
();
this
.
_onModelModeChanged
=
new
Emitter
<
{
model
:
editorCommon
.
IModel
;
oldModeId
:
string
;
}
>
();
if
(
this
.
_markerService
)
{
this
.
_markerServiceSubscription
=
this
.
_markerService
.
onMarkerChanged
(
this
.
_handleMarkerChange
,
this
);
}
let
readConfig
=
(
config
:
IRawConfig
)
=>
{
let
readConfig
=
(
config
:
IRawConfig
)
=>
{
const
eol
=
config
.
files
&&
config
.
files
.
eol
;
let
shouldShowMigrationMessage
=
false
;
...
...
@@ -274,20 +284,11 @@ export class ModelServiceImpl implements IModelService {
this
.
_messageService
.
show
(
Severity
.
Info
,
nls
.
localize
(
'
indentAutoMigrate
'
,
"
Please update your settings: `editor.detectIndentation` replaces `editor.tabSize`:
\"
auto
\"
or `editor.insertSpaces`:
\"
auto
\"
"
));
}
};
this
.
_configurationServiceSubscription
=
this
.
_configurationService
.
addListener2
(
ConfigurationServiceEventTypes
.
UPDATED
,
(
e
:
IConfigurationServiceEvent
)
=>
{
readConfig
(
e
.
config
);
});
readConfig
(
this
.
_configurationService
.
getConfiguration
());
this
.
_models
=
{};
this
.
_onModelAdded
=
new
Emitter
<
editorCommon
.
IModel
>
();
this
.
_onModelRemoved
=
new
Emitter
<
editorCommon
.
IModel
>
();
this
.
_onModelModeChanged
=
new
Emitter
<
{
model
:
editorCommon
.
IModel
;
oldModeId
:
string
;
}
>
();
if
(
this
.
_markerService
)
{
this
.
_markerServiceSubscription
=
this
.
_markerService
.
onMarkerChanged
(
this
.
_handleMarkerChange
,
this
);
}
}
public
getCreationOptions
():
editorCommon
.
ITextModelCreationOptions
{
...
...
@@ -317,14 +318,14 @@ export class ModelServiceImpl implements IModelService {
}
else
{
modelData
.
model
.
updateOptions
({
insertSpaces
:
this
.
_modelCreationOptions
.
insertSpaces
,
tabSize
:
this
.
_modelCreationOptions
.
tabSize
tabSize
:
this
.
_modelCreationOptions
.
tabSize
});
}
}
}
public
dispose
():
void
{
if
(
this
.
_markerServiceSubscription
)
{
if
(
this
.
_markerServiceSubscription
)
{
this
.
_markerServiceSubscription
.
dispose
();
}
this
.
_configurationServiceSubscription
.
dispose
();
...
...
@@ -343,7 +344,7 @@ export class ModelServiceImpl implements IModelService {
// --- begin IModelService
private
_shouldSyncModelToWorkers
(
model
:
editorCommon
.
IModel
):
boolean
{
private
_shouldSyncModelToWorkers
(
model
:
editorCommon
.
IModel
):
boolean
{
if
(
model
.
isTooLargeForHavingARichMode
())
{
return
false
;
}
...
...
@@ -351,7 +352,7 @@ export class ModelServiceImpl implements IModelService {
return
this
.
_modeService
.
isCompatMode
(
model
.
getMode
().
getId
());
}
private
_createModelData
(
value
:
string
,
modeOrPromise
:
TPromise
<
IMode
>|
IMode
,
resource
:
URI
):
ModelData
{
private
_createModelData
(
value
:
string
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
ModelData
{
// create & save the model
let
model
=
new
Model
(
value
,
this
.
_modelCreationOptions
,
modeOrPromise
,
resource
);
let
modelId
=
MODEL_ID
(
model
.
getAssociatedResource
());
...
...
@@ -367,7 +368,7 @@ export class ModelServiceImpl implements IModelService {
return
modelData
;
}
public
createModel
(
value
:
string
,
modeOrPromise
:
TPromise
<
IMode
>|
IMode
,
resource
:
URI
):
editorCommon
.
IModel
{
public
createModel
(
value
:
string
,
modeOrPromise
:
TPromise
<
IMode
>
|
IMode
,
resource
:
URI
):
editorCommon
.
IModel
{
let
modelData
=
this
.
_createModelData
(
value
,
modeOrPromise
,
resource
);
// handle markers (marker service => model)
...
...
@@ -429,7 +430,7 @@ export class ModelServiceImpl implements IModelService {
// --- end IModelService
private
_beginWorkerSync
(
modelData
:
ModelData
):
void
{
private
_beginWorkerSync
(
modelData
:
ModelData
):
void
{
if
(
modelData
.
isSyncedToWorkers
)
{
throw
new
Error
(
'
Model is already being synced to workers!
'
);
}
...
...
@@ -438,7 +439,7 @@ export class ModelServiceImpl implements IModelService {
this
.
_workerHelper
.
$_acceptNewModel
(
ModelServiceImpl
.
_getBoundModelData
(
modelData
.
model
));
}
private
_stopWorkerSync
(
modelData
:
ModelData
):
void
{
private
_stopWorkerSync
(
modelData
:
ModelData
):
void
{
if
(
!
modelData
.
isSyncedToWorkers
)
{
throw
new
Error
(
'
Model is already not being synced to workers!
'
);
}
...
...
@@ -446,7 +447,7 @@ export class ModelServiceImpl implements IModelService {
this
.
_workerHelper
.
$_acceptDidDisposeModel
(
modelData
.
model
.
getAssociatedResource
());
}
private
_onModelDisposing
(
model
:
editorCommon
.
IModel
):
void
{
private
_onModelDisposing
(
model
:
editorCommon
.
IModel
):
void
{
let
modelId
=
MODEL_ID
(
model
.
getAssociatedResource
());
let
modelData
=
this
.
_models
[
modelId
];
...
...
@@ -470,7 +471,7 @@ export class ModelServiceImpl implements IModelService {
this
.
_onModelRemoved
.
fire
(
model
);
}
private
static
_getBoundModelData
(
model
:
editorCommon
.
IModel
):
IRawModelData
{
private
static
_getBoundModelData
(
model
:
editorCommon
.
IModel
):
IRawModelData
{
return
{
url
:
model
.
getAssociatedResource
(),
versionId
:
model
.
getVersionId
(),
...
...
@@ -479,7 +480,7 @@ export class ModelServiceImpl implements IModelService {
};
}
private
_onModelEvents
(
modelData
:
ModelData
,
events
:
IEmitterEvent
[]):
void
{
private
_onModelEvents
(
modelData
:
ModelData
,
events
:
IEmitterEvent
[]):
void
{
// First look for dispose
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
...
...
@@ -555,8 +556,8 @@ export class ModelServiceImpl implements IModelService {
@
Remotable
.
WorkerContext
(
'
ModelServiceWorkerHelper
'
,
ThreadAffinity
.
All
)
export
class
ModelServiceWorkerHelper
{
private
_resourceService
:
IResourceService
;
private
_modeService
:
IModeService
;
private
_resourceService
:
IResourceService
;
private
_modeService
:
IModeService
;
constructor
(
@
IResourceService
resourceService
:
IResourceService
,
...
...
@@ -566,7 +567,7 @@ export class ModelServiceWorkerHelper {
this
.
_modeService
=
modeService
;
}
public
$_acceptNewModel
(
data
:
IRawModelData
):
TPromise
<
void
>
{
public
$_acceptNewModel
(
data
:
IRawModelData
):
TPromise
<
void
>
{
// Create & insert the mirror model eagerly in the resource service
let
mirrorModel
=
new
MirrorModel
(
this
.
_resourceService
,
data
.
versionId
,
data
.
value
,
null
,
data
.
url
);
this
.
_resourceService
.
insert
(
mirrorModel
.
getAssociatedResource
(),
mirrorModel
);
...
...
@@ -586,7 +587,7 @@ export class ModelServiceWorkerHelper {
});
}
public
$_acceptDidChangeModelMode
(
modelId
:
string
,
newModeId
:
string
):
TPromise
<
void
>
{
public
$_acceptDidChangeModelMode
(
modelId
:
string
,
newModeId
:
string
):
TPromise
<
void
>
{
let
mirrorModel
=
this
.
_resourceService
.
get
(
URI
.
parse
(
modelId
));
// Block worker execution until the mode is instantiated
...
...
@@ -604,7 +605,7 @@ export class ModelServiceWorkerHelper {
});
}
public
$_acceptDidDisposeModel
(
url
:
URI
):
void
{
public
$_acceptDidDisposeModel
(
url
:
URI
):
void
{
let
model
=
<
MirrorModel
>
this
.
_resourceService
.
get
(
url
);
this
.
_resourceService
.
remove
(
url
);
if
(
model
)
{
...
...
@@ -612,7 +613,7 @@ export class ModelServiceWorkerHelper {
}
}
public
$_acceptModelEvents
(
modelId
:
string
,
events
:
IMirrorModelEvents
):
void
{
public
$_acceptModelEvents
(
modelId
:
string
,
events
:
IMirrorModelEvents
):
void
{
let
model
=
<
MirrorModel
>
this
.
_resourceService
.
get
(
URI
.
parse
(
modelId
));
if
(
!
model
)
{
throw
new
Error
(
'
Received model events for missing model
'
+
anonymize
(
modelId
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录