Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f0fc4ac3
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,发现更多精彩内容 >>
提交
f0fc4ac3
编写于
11月 04, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
no more IEditorService.resolveEditorModel()
上级
1741f67d
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
50 addition
and
172 deletion
+50
-172
src/vs/editor/browser/standalone/simpleServices.ts
src/vs/editor/browser/standalone/simpleServices.ts
+0
-15
src/vs/platform/editor/common/editor.ts
src/vs/platform/editor/common/editor.ts
+0
-5
src/vs/platform/opener/test/browser/openerService.test.ts
src/vs/platform/opener/test/browser/openerService.test.ts
+1
-5
src/vs/test/utils/servicesTestUtils.ts
src/vs/test/utils/servicesTestUtils.ts
+1
-9
src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts
src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts
+2
-4
src/vs/workbench/browser/parts/editor/binaryEditor.ts
src/vs/workbench/browser/parts/editor/binaryEditor.ts
+7
-10
src/vs/workbench/browser/parts/editor/stringEditor.ts
src/vs/workbench/browser/parts/editor/stringEditor.ts
+1
-1
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
+1
-1
src/vs/workbench/parts/files/browser/editors/binaryFileEditor.ts
...workbench/parts/files/browser/editors/binaryFileEditor.ts
+2
-4
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
...s/workbench/parts/files/browser/editors/textFileEditor.ts
+1
-1
src/vs/workbench/parts/files/common/editors/fileEditorInput.ts
...s/workbench/parts/files/common/editors/fileEditorInput.ts
+3
-2
src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts
...orkbench/parts/files/test/browser/fileEditorInput.test.ts
+13
-12
src/vs/workbench/services/editor/browser/editorService.ts
src/vs/workbench/services/editor/browser/editorService.ts
+1
-13
src/vs/workbench/services/editor/common/editorService.ts
src/vs/workbench/services/editor/common/editorService.ts
+1
-14
src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts
...ices/textmodelResolver/common/textModelResolverService.ts
+9
-63
src/vs/workbench/test/browser/services.test.ts
src/vs/workbench/test/browser/services.test.ts
+2
-8
src/vs/workbench/test/common/editor/stringEditorInput.test.ts
...vs/workbench/test/common/editor/stringEditorInput.test.ts
+5
-5
未找到文件。
src/vs/editor/browser/standalone/simpleServices.ts
浏览文件 @
f0fc4ac3
...
...
@@ -162,21 +162,6 @@ export class SimpleEditorService implements IEditorService {
return
model
;
}
public
resolveEditorModel
(
typedData
:
IResourceInput
,
refresh
?:
boolean
):
TPromise
<
ITextEditorModel
>
{
let
model
:
editorCommon
.
IModel
;
model
=
this
.
editor
.
withTypedEditor
(
(
editor
)
=>
this
.
findModel
(
editor
,
typedData
),
(
diffEditor
)
=>
this
.
findModel
(
diffEditor
.
getOriginalEditor
(),
typedData
)
||
this
.
findModel
(
diffEditor
.
getModifiedEditor
(),
typedData
)
);
if
(
!
model
)
{
return
TPromise
.
as
(
null
);
}
return
TPromise
.
as
(
new
SimpleModel
(
model
));
}
}
export
class
SimpleEditorModelResolverService
implements
ITextModelResolverService
{
...
...
src/vs/platform/editor/common/editor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -20,11 +20,6 @@ export interface IEditorService {
* Specific overload to open an instance of IResourceInput.
*/
openEditor
(
input
:
IResourceInput
,
sideBySide
?:
boolean
):
TPromise
<
IEditor
>
;
/**
* Specific overload to resolve a IResourceInput to an editor model with a text representation.
*/
resolveEditorModel
(
input
:
IResourceInput
,
refresh
?:
boolean
):
TPromise
<
ITextEditorModel
>
;
}
export
interface
IEditorModel
{
...
...
src/vs/platform/opener/test/browser/openerService.test.ts
浏览文件 @
f0fc4ac3
...
...
@@ -7,7 +7,7 @@
import
URI
from
'
vs/base/common/uri
'
;
import
*
as
assert
from
'
assert
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IEditorService
,
I
TextEditorModel
,
I
ResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorService
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
ICommandService
,
NullCommandService
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
OpenerService
}
from
'
vs/platform/opener/browser/openerService
'
;
...
...
@@ -20,12 +20,8 @@ suite('OpenerService', function () {
openEditor
(
input
:
IResourceInput
):
any
{
lastInput
=
input
;
}
resolveEditorModel
():
any
{
return
TPromise
.
as
(
<
ITextEditorModel
>
{});
}
};
let
lastCommand
:
{
id
:
string
,
args
:
any
[]
};
const
commandService
=
new
class
implements
ICommandService
{
...
...
src/vs/test/utils/servicesTestUtils.ts
浏览文件 @
f0fc4ac3
...
...
@@ -24,7 +24,7 @@ import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickO
import
{
IPartService
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
TextModelResolverService
}
from
'
vs/workbench/services/textmodelResolver/common/textModelResolverService
'
;
import
{
ITextModelResolverService
}
from
'
vs/platform/textmodelResolver/common/resolver
'
;
import
{
IEditorInput
,
IEditorOptions
,
IEditorModel
,
Position
,
Direction
,
IEditor
,
IResourceInput
,
ITextEditorModel
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorInput
,
IEditorOptions
,
Position
,
Direction
,
IEditor
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
IUntitledEditorService
,
UntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IMessageService
,
IConfirmation
}
from
'
vs/platform/message/common/message
'
;
...
...
@@ -471,14 +471,6 @@ export class TestEditorService implements IWorkbenchEditorService {
return
TPromise
.
as
(
null
);
}
public
resolveEditorModel
(
input
:
IEditorInput
,
refresh
?:
boolean
):
TPromise
<
IEditorModel
>
;
public
resolveEditorModel
(
input
:
IResourceInput
,
refresh
?:
boolean
):
TPromise
<
ITextEditorModel
>
;
public
resolveEditorModel
(
input
:
any
,
refresh
?:
boolean
):
Promise
{
this
.
callback
(
'
resolveEditorModel
'
);
return
input
.
resolve
(
refresh
);
}
public
closeEditor
(
position
:
Position
,
input
:
IEditorInput
):
TPromise
<
void
>
{
this
.
callback
(
'
closeEditor
'
);
...
...
src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -18,7 +18,6 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import
{
EditorInput
,
EditorOptions
,
BINARY_DIFF_EDITOR_ID
}
from
'
vs/workbench/common/editor
'
;
import
{
BinaryEditorModel
}
from
'
vs/workbench/common/editor/binaryEditorModel
'
;
import
{
DiffEditorModel
}
from
'
vs/workbench/common/editor/diffEditorModel
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
ScrollbarVisibility
}
from
'
vs/base/common/scrollable
'
;
...
...
@@ -45,8 +44,7 @@ export class BinaryResourceDiffEditor extends BaseEditor implements IVerticalSas
private
startLeftContainerWidth
:
number
;
constructor
(
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IWorkbenchEditorService
private
editorService
:
IWorkbenchEditorService
@
ITelemetryService
telemetryService
:
ITelemetryService
)
{
super
(
BinaryResourceDiffEditor
.
ID
,
telemetryService
);
...
...
@@ -106,7 +104,7 @@ export class BinaryResourceDiffEditor extends BaseEditor implements IVerticalSas
}
// Different Input (Reload)
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
((
resolvedModel
:
DiffEditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolvedModel
:
DiffEditorModel
)
=>
{
// Assert model instance
if
(
!
(
resolvedModel
.
originalModel
instanceof
BinaryEditorModel
)
||
!
(
resolvedModel
.
modifiedModel
instanceof
BinaryEditorModel
))
{
...
...
src/vs/workbench/browser/parts/editor/binaryEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -13,7 +13,6 @@ import { ResourceViewer } from 'vs/base/browser/ui/resourceviewer/resourceViewer
import
{
EditorModel
,
EditorInput
,
EditorOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
BaseEditor
}
from
'
vs/workbench/browser/parts/editor/baseEditor
'
;
import
{
BinaryEditorModel
}
from
'
vs/workbench/common/editor/binaryEditorModel
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
DomScrollableElement
}
from
'
vs/base/browser/ui/scrollbar/scrollableElement
'
;
import
{
ScrollbarVisibility
}
from
'
vs/base/common/scrollable
'
;
...
...
@@ -28,7 +27,10 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
private
binaryContainer
:
Builder
;
private
scrollbar
:
DomScrollableElement
;
constructor
(
id
:
string
,
telemetryService
:
ITelemetryService
,
private
_editorService
:
IWorkbenchEditorService
)
{
constructor
(
id
:
string
,
telemetryService
:
ITelemetryService
)
{
super
(
id
,
telemetryService
);
this
.
_onMetadataChanged
=
new
Emitter
<
void
>
();
...
...
@@ -42,10 +44,6 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
return
this
.
getInput
()
?
this
.
getInput
().
getName
()
:
nls
.
localize
(
'
binaryEditor
'
,
"
Binary Viewer
"
);
}
public
get
editorService
()
{
return
this
.
_editorService
;
}
public
createEditor
(
parent
:
Builder
):
void
{
// Container for Binary
...
...
@@ -72,7 +70,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
}
// Different Input (Reload)
return
this
.
_editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
((
resolvedModel
:
EditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolvedModel
:
EditorModel
)
=>
{
// Assert Model instance
if
(
!
(
resolvedModel
instanceof
BinaryEditorModel
))
{
...
...
@@ -141,9 +139,8 @@ export class BinaryResourceEditor extends BaseBinaryResourceEditor {
public
static
ID
=
'
workbench.editors.binaryResourceEditor
'
;
constructor
(
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IWorkbenchEditorService
editorService
:
IWorkbenchEditorService
@
ITelemetryService
telemetryService
:
ITelemetryService
)
{
super
(
BinaryResourceEditor
.
ID
,
telemetryService
,
editorService
);
super
(
BinaryResourceEditor
.
ID
,
telemetryService
);
}
}
src/vs/workbench/browser/parts/editor/stringEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -93,7 +93,7 @@ export class StringEditor extends BaseTextEditor {
}
// Different Input (Reload)
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
((
resolvedModel
:
EditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolvedModel
:
EditorModel
)
=>
{
// Assert Model instance
if
(
!
(
resolvedModel
instanceof
BaseTextEditorModel
))
{
...
...
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -142,7 +142,7 @@ export class TextDiffEditor extends BaseTextEditor {
}
// Different Input (Reload)
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
((
resolvedModel
:
EditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolvedModel
:
EditorModel
)
=>
{
// Assert Model Instance
if
(
!
(
resolvedModel
instanceof
TextDiffEditorModel
)
&&
this
.
openAsBinary
(
input
,
options
))
{
...
...
src/vs/workbench/parts/files/browser/editors/binaryFileEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -8,7 +8,6 @@ import nls = require('vs/nls');
import
{
BaseBinaryResourceEditor
}
from
'
vs/workbench/browser/parts/editor/binaryEditor
'
;
import
{
BINARY_FILE_EDITOR_ID
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
/**
* An implementation of editor for binary files like images.
...
...
@@ -18,10 +17,9 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
public
static
ID
=
BINARY_FILE_EDITOR_ID
;
constructor
(
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IWorkbenchEditorService
editorService
:
IWorkbenchEditorService
@
ITelemetryService
telemetryService
:
ITelemetryService
)
{
super
(
BinaryFileEditor
.
ID
,
telemetryService
,
editorService
);
super
(
BinaryFileEditor
.
ID
,
telemetryService
);
}
public
getTitle
():
string
{
...
...
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
浏览文件 @
f0fc4ac3
...
...
@@ -118,7 +118,7 @@ export class TextFileEditor extends BaseTextEditor {
}
// Different Input (Reload)
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
(
resolvedModel
=>
{
return
input
.
resolve
(
true
).
then
(
resolvedModel
=>
{
// There is a special case where the text editor has to handle binary file editor input: if a binary file
// has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text
...
...
src/vs/workbench/parts/files/common/editors/fileEditorInput.ts
浏览文件 @
f0fc4ac3
...
...
@@ -8,7 +8,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
labels
=
require
(
'
vs/base/common/labels
'
);
import
URI
from
'
vs/base/common/uri
'
;
import
{
EditorModel
,
EncodingMode
,
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
EncodingMode
,
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/services/textfile/common/textFileEditorModel
'
;
import
{
BinaryEditorModel
}
from
'
vs/workbench/common/editor/binaryEditorModel
'
;
import
{
IFileOperationResult
,
FileOperationResult
}
from
'
vs/platform/files/common/files
'
;
import
{
BINARY_FILE_EDITOR_ID
,
TEXT_FILE_EDITOR_ID
,
FILE_EDITOR_INPUT_ID
,
FileEditorInput
as
CommonFileEditorInput
}
from
'
vs/workbench/parts/files/common/files
'
;
...
...
@@ -177,7 +178,7 @@ export class FileEditorInput extends CommonFileEditorInput {
return
this
.
forceOpenAsBinary
?
BINARY_FILE_EDITOR_ID
:
TEXT_FILE_EDITOR_ID
;
}
public
resolve
(
refresh
?:
boolean
):
TPromise
<
EditorModel
>
{
public
resolve
(
refresh
?:
boolean
):
TPromise
<
TextFile
EditorModel
>
{
return
this
.
textFileService
.
models
.
loadOrCreate
(
this
.
resource
,
this
.
preferredEncoding
,
refresh
).
then
(
null
,
error
=>
{
// In case of an error that indicates that the file is binary or too large, just return with the binary editor model
...
...
src/vs/workbench/parts/files/test/browser/fileEditorInput.test.ts
浏览文件 @
f0fc4ac3
...
...
@@ -13,8 +13,9 @@ import { workbenchInstantiationService, TestTextFileService } from 'vs/test/util
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
EncodingMode
}
from
'
vs/workbench/common/editor
'
;
import
{
IEventService
}
from
'
vs/platform/event/common/event
'
;
import
{
ITextFile
EditorModel
,
ITextFileService
,
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
ITextFile
Service
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
FileOperationResult
,
IFileOperationResult
}
from
'
vs/platform/files/common/files
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/services/textfile/common/textFileEditorModel
'
;
function
toResource
(
path
)
{
return
URI
.
file
(
join
(
'
C:
\\
'
,
new
Buffer
(
this
.
test
.
fullTitle
()).
toString
(
'
base64
'
),
path
));
...
...
@@ -62,17 +63,17 @@ suite('Files - FileEditorInput', () => {
const
inputToResolve
:
any
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
void
0
);
const
sameOtherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
void
0
);
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
true
).
then
(
resolved
=>
{
const
resolvedModelA
=
resolved
;
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
===
resolved
);
// OK: Resolved Model cached globally per input
return
accessor
.
editorService
.
resolveEditorModel
(
sameOtherInput
,
true
).
then
(
otherResolved
=>
{
return
sameOtherInput
.
resolve
(
true
).
then
(
otherResolved
=>
{
assert
(
otherResolved
===
resolvedModelA
);
// OK: Resolved Model cached globally per input
inputToResolve
.
dispose
(
false
);
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
===
resolved
);
// Model is still the same because we had 2 clients
inputToResolve
.
dispose
();
...
...
@@ -80,15 +81,15 @@ suite('Files - FileEditorInput', () => {
resolvedModelA
.
dispose
();
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
!==
resolved
);
// Different instance, because input got disposed
let
stat
=
(
<
any
>
resolved
).
versionOnDiskStat
;
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
true
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
stat
!==
(
<
any
>
resolved
).
versionOnDiskStat
);
// Different stat, because resolve always goes to the server for refresh
stat
=
(
<
any
>
resolved
).
versionOnDiskStat
;
return
accessor
.
editorService
.
resolveEditorModel
(
inputToResolve
,
false
).
then
(
resolved
=>
{
return
inputToResolve
.
resolve
(
false
).
then
(
resolved
=>
{
assert
(
stat
===
(
<
any
>
resolved
).
versionOnDiskStat
);
// Same stat, because not refreshed
done
();
...
...
@@ -116,7 +117,7 @@ suite('Files - FileEditorInput', () => {
input
.
setEncoding
(
'
utf16
'
,
EncodingMode
.
Encode
);
assert
.
equal
(
input
.
getEncoding
(),
'
utf16
'
);
return
accessor
.
editorService
.
resolveEditorModel
(
input
,
true
).
then
((
resolved
:
I
TextFileEditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolved
:
TextFileEditorModel
)
=>
{
assert
.
equal
(
input
.
getEncoding
(),
resolved
.
getEncoding
());
resolved
.
dispose
();
...
...
@@ -128,7 +129,7 @@ suite('Files - FileEditorInput', () => {
test
(
'
save
'
,
function
(
done
)
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
void
0
);
return
accessor
.
editorService
.
resolveEditorModel
(
input
,
true
).
then
((
resolved
:
I
TextFileEditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolved
:
TextFileEditorModel
)
=>
{
resolved
.
textEditorModel
.
setValue
(
'
changed
'
);
assert
.
ok
(
input
.
isDirty
());
...
...
@@ -145,7 +146,7 @@ suite('Files - FileEditorInput', () => {
test
(
'
revert
'
,
function
(
done
)
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
void
0
);
return
accessor
.
editorService
.
resolveEditorModel
(
input
,
true
).
then
((
resolved
:
I
TextFileEditorModel
)
=>
{
return
input
.
resolve
(
true
).
then
((
resolved
:
TextFileEditorModel
)
=>
{
resolved
.
textEditorModel
.
setValue
(
'
changed
'
);
assert
.
ok
(
input
.
isDirty
());
...
...
@@ -167,7 +168,7 @@ suite('Files - FileEditorInput', () => {
fileOperationResult
:
FileOperationResult
.
FILE_IS_BINARY
});
return
accessor
.
editorService
.
resolveEditorModel
(
input
,
true
).
then
(
resolved
=>
{
return
input
.
resolve
(
true
).
then
(
resolved
=>
{
assert
.
ok
(
resolved
);
resolved
.
dispose
();
...
...
src/vs/workbench/services/editor/browser/editorService.ts
浏览文件 @
f0fc4ac3
...
...
@@ -19,7 +19,7 @@ import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorIn
import
{
DiffEditorInput
}
from
'
vs/workbench/common/editor/diffEditorInput
'
;
import
{
IUntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditorInput
,
IEditor
Model
,
IEditorOptions
,
ITextEditorOptions
,
Position
,
Direction
,
IEditor
,
IResourceInput
,
ITextEditorModel
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorInput
,
IEditor
Options
,
ITextEditorOptions
,
Position
,
Direction
,
IEditor
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
AsyncDescriptor0
}
from
'
vs/platform/instantiation/common/descriptors
'
;
...
...
@@ -195,18 +195,6 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return
this
.
editorPart
.
closeAllEditors
(
except
);
}
public
resolveEditorModel
(
input
:
IEditorInput
,
refresh
?:
boolean
):
TPromise
<
IEditorModel
>
;
public
resolveEditorModel
(
input
:
IResourceInput
,
refresh
?:
boolean
):
TPromise
<
ITextEditorModel
>
;
public
resolveEditorModel
(
input
:
any
,
refresh
?:
boolean
):
TPromise
<
IEditorModel
>
{
return
this
.
createInput
(
input
).
then
(
typedInput
=>
{
if
(
typedInput
instanceof
EditorInput
)
{
return
typedInput
.
resolve
(
!!
refresh
);
}
return
TPromise
.
as
<
IEditorModel
>
(
null
);
});
}
public
createInput
(
input
:
EditorInput
):
TPromise
<
EditorInput
>
;
public
createInput
(
input
:
IResourceInput
):
TPromise
<
EditorInput
>
;
public
createInput
(
input
:
any
):
TPromise
<
IEditorInput
>
{
...
...
src/vs/workbench/services/editor/common/editorService.ts
浏览文件 @
f0fc4ac3
...
...
@@ -7,8 +7,7 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
createDecorator
,
ServiceIdentifier
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IEditorService
,
IEditor
,
IEditorInput
,
IEditorOptions
,
ITextEditorOptions
,
Position
,
Direction
,
IResourceInput
,
IEditorModel
}
from
'
vs/platform/editor/common/editor
'
;
import
{
ITextEditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorService
,
IEditor
,
IEditorInput
,
IEditorOptions
,
ITextEditorOptions
,
Position
,
Direction
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
export
const
IWorkbenchEditorService
=
createDecorator
<
IWorkbenchEditorService
>
(
'
editorService
'
);
...
...
@@ -86,18 +85,6 @@ export interface IWorkbenchEditorService extends IEditorService {
*/
closeAllEditors
(
except
?:
Position
):
TPromise
<
void
>
;
/**
* Resolves an input to its model representation. The optional parameter refresh allows to specify
* if a cached model should be returned (false) or a new version (true). The default is returning a
* cached version.
*/
resolveEditorModel
(
input
:
IEditorInput
,
refresh
?:
boolean
):
TPromise
<
IEditorModel
>
;
/**
* Specific overload to resolve a IResourceInput to an editor model with a text representation.
*/
resolveEditorModel
(
input
:
IResourceInput
,
refresh
?:
boolean
):
TPromise
<
ITextEditorModel
>
;
/**
* Allows to resolve an untyped input to a workbench typed instanceof editor input
*/
...
...
src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts
浏览文件 @
f0fc4ac3
...
...
@@ -7,9 +7,8 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ICommonCodeEditor
,
IModel
,
EditorType
,
IEditor
as
ICommonEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IDiffEditor
,
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ITextEditorModel
,
IEditorInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ITextEditorModel
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
...
...
@@ -20,8 +19,6 @@ import { ITextModelResolverService, ITextModelContentProvider, IResolveOptions }
import
{
IUntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
UntitledEditorInput
}
from
'
vs/workbench/common/editor/untitledEditorInput
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
types
=
require
(
'
vs/base/common/types
'
);
import
{
DiffEditorInput
}
from
'
vs/workbench/common/editor/diffEditorInput
'
;
import
{
EditorInput
}
from
'
vs/workbench/common/editor
'
;
export
class
TextModelResolverService
implements
ITextModelResolverService
{
...
...
@@ -54,68 +51,17 @@ export class TextModelResolverService implements ITextModelResolverService {
// In Memory: only works on the active editor
if
(
resource
.
scheme
===
network
.
Schemas
.
inMemory
)
{
return
this
.
resolveInMemory
(
resource
);
}
// Any other resource: use registry
return
this
.
resolveTextModelContent
(
this
.
modelService
,
resource
).
then
(()
=>
this
.
instantiationService
.
createInstance
(
ResourceEditorModel
,
resource
));
}
private
resolveInMemory
(
resource
:
URI
):
TPromise
<
ITextEditorModel
>
{
// For in-memory resources we only support to resolve the input from the current active editor
// because the workbench does not track editor models by in memory URL. This concept is only
// being used in the code editor.
const
activeEditor
=
this
.
editorService
.
getActiveEditor
();
if
(
activeEditor
)
{
const
control
=
<
ICommonEditor
>
activeEditor
.
getControl
();
if
(
types
.
isFunction
(
control
.
getEditorType
))
{
// Single Editor: If code editor model matches, return input from editor
if
(
control
.
getEditorType
()
===
EditorType
.
ICodeEditor
)
{
const
codeEditor
=
<
ICodeEditor
>
control
;
const
model
=
this
.
findModel
(
codeEditor
,
resource
);
if
(
model
)
{
return
this
.
resolveFromInput
(
activeEditor
.
input
);
}
}
// Diff Editor: If left or right code editor model matches, return associated input
else
if
(
control
.
getEditorType
()
===
EditorType
.
IDiffEditor
)
{
const
diffInput
=
<
DiffEditorInput
>
activeEditor
.
input
;
const
diffCodeEditor
=
<
IDiffEditor
>
control
;
const
originalModel
=
this
.
findModel
(
diffCodeEditor
.
getOriginalEditor
(),
resource
);
if
(
originalModel
)
{
return
this
.
resolveFromInput
(
diffInput
.
originalInput
);
}
const
modifiedModel
=
this
.
findModel
(
diffCodeEditor
.
getModifiedEditor
(),
resource
);
if
(
modifiedModel
)
{
return
this
.
resolveFromInput
(
diffInput
.
modifiedInput
);
}
return
this
.
editorService
.
createInput
({
resource
}).
then
(
input
=>
{
if
(
input
instanceof
EditorInput
)
{
return
input
.
resolve
();
}
}
}
return
TPromise
.
as
(
null
);
}
private
resolveFromInput
(
input
:
IEditorInput
):
TPromise
<
ITextEditorModel
>
{
if
(
input
instanceof
EditorInput
)
{
return
input
.
resolve
();
}
return
TPromise
.
as
(
null
);
}
private
findModel
(
editor
:
ICommonCodeEditor
,
resource
:
URI
):
IModel
{
const
model
=
editor
.
getModel
();
if
(
!
model
)
{
return
null
;
return
null
;
});
}
return
model
.
uri
.
toString
()
===
resource
.
toString
()
?
model
:
null
;
// Any other resource: use registry
return
this
.
resolveTextModelContent
(
this
.
modelService
,
resource
).
then
(()
=>
this
.
instantiationService
.
createInstance
(
ResourceEditorModel
,
resource
));
}
public
registerTextModelContentProvider
(
scheme
:
string
,
provider
:
ITextModelContentProvider
):
IDisposable
{
...
...
src/vs/workbench/test/browser/services.test.ts
浏览文件 @
f0fc4ac3
...
...
@@ -16,7 +16,6 @@ import { EditorInput, EditorOptions, TextEditorOptions } from 'vs/workbench/comm
import
{
StringEditorInput
}
from
'
vs/workbench/common/editor/stringEditorInput
'
;
import
{
StringEditorModel
}
from
'
vs/workbench/common/editor/stringEditorModel
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/services/textfile/common/textFileEditorModel
'
;
import
{
workbenchInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
Viewlet
}
from
'
vs/workbench/browser/viewlet
'
;
import
{
IPanel
}
from
'
vs/workbench/common/panel
'
;
...
...
@@ -313,22 +312,17 @@ suite('Workbench UI Services', () => {
// Resolve Editor Model (Typed EditorInput)
let
input
=
instantiationService
.
createInstance
(
StringEditorInput
,
'
name
'
,
'
description
'
,
'
hello world
'
,
'
text/plain
'
,
false
);
service
.
resolveEditorModel
(
input
,
true
).
then
((
model
:
StringEditorModel
)
=>
{
input
.
resolve
(
true
).
then
((
model
:
StringEditorModel
)
=>
{
assert
(
model
instanceof
StringEditorModel
);
assert
(
model
.
isResolved
());
service
.
resolveEditorModel
(
input
,
false
).
then
((
otherModel
)
=>
{
input
.
resolve
(
).
then
((
otherModel
)
=>
{
assert
(
model
===
otherModel
);
input
.
dispose
();
});
});
// Resolve Editor Model (Untyped Input)
service
.
resolveEditorModel
({
resource
:
toResource
.
call
(
this
,
'
/index.html
'
)
},
true
).
then
((
model
)
=>
{
assert
(
model
instanceof
TextFileEditorModel
);
});
});
test
(
'
DelegatingWorkbenchEditorService
'
,
function
()
{
...
...
src/vs/workbench/test/common/editor/stringEditorInput.test.ts
浏览文件 @
f0fc4ac3
...
...
@@ -50,22 +50,22 @@ suite('Workbench - StringEditorInput', () => {
input
=
instantiationService
.
createInstance
(
StringEditorInput
,
'
name
'
,
'
description
'
,
'
value
'
,
'
mode
'
,
false
);
input
=
instantiationService
.
createInstance
(
StringEditorInput
,
'
name
'
,
'
description
'
,
'
value
'
,
'
mode
'
,
false
);
editorService
.
resolveEditorModel
(
input
,
true
).
then
(
resolved
=>
{
input
.
resolve
(
true
).
then
(
resolved
=>
{
let
resolvedModelA
=
resolved
;
return
editorService
.
resolveEditorModel
(
input
,
true
).
then
(
resolved
=>
{
return
input
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
===
resolved
);
// assert: Resolved Model cached per instance
let
otherInput
=
instantiationService
.
createInstance
(
StringEditorInput
,
'
name
'
,
'
description
'
,
'
value
'
,
'
mode
'
,
false
);
return
editorService
.
resolveEditorModel
(
otherInput
,
true
).
then
(
resolved
=>
{
return
otherInput
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
!==
resolved
);
// NOT assert: Different instance, different model
input
.
dispose
();
return
editorService
.
resolveEditorModel
(
input
,
true
).
then
(
resolved
=>
{
return
input
.
resolve
(
true
).
then
(
resolved
=>
{
assert
(
resolvedModelA
!==
resolved
);
// Different instance, because input got disposed
let
model
=
(
<
any
>
resolved
).
textEditorModel
;
return
editorService
.
resolveEditorModel
(
input
,
true
).
then
(
againResolved
=>
{
return
input
.
resolve
(
true
).
then
(
againResolved
=>
{
assert
(
model
===
(
<
any
>
againResolved
).
textEditorModel
);
// Models should not differ because string input is constant
input
.
dispose
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录