Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
70988681
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,发现更多精彩内容 >>
提交
70988681
编写于
11月 26, 2015
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
formatting edit provider as support
上级
c9fd775d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
151 addition
and
5 deletion
+151
-5
src/vs/workbench/api/browser/pluginHost.api.impl.ts
src/vs/workbench/api/browser/pluginHost.api.impl.ts
+3
-3
src/vs/workbench/api/common/extHostLanguageFeatures.ts
src/vs/workbench/api/common/extHostLanguageFeatures.ts
+140
-1
src/vs/workbench/api/common/pluginHostTypeConverters.ts
src/vs/workbench/api/common/pluginHostTypeConverters.ts
+8
-1
未找到文件。
src/vs/workbench/api/browser/pluginHost.api.impl.ts
浏览文件 @
70988681
...
...
@@ -292,13 +292,13 @@ export class PluginHostAPIImplementation {
return
features
.
workspaceSymbols
.
register
(
provider
);
},
registerDocumentFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
DocumentFormattingEditProvider
):
vscode
.
Disposable
{
return
features
.
formatDocument
.
regist
er
(
selector
,
provider
);
return
languageFeatures
.
registerDocumentFormattingEditProvid
er
(
selector
,
provider
);
},
registerDocumentRangeFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
DocumentRangeFormattingEditProvider
):
vscode
.
Disposable
{
return
features
.
formatRange
.
regist
er
(
selector
,
provider
);
return
languageFeatures
.
registerDocumentRangeFormattingEditProvid
er
(
selector
,
provider
);
},
registerOnTypeFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
OnTypeFormattingEditProvider
,
firstTriggerCharacter
:
string
,
...
moreTriggerCharacters
:
string
[]):
vscode
.
Disposable
{
return
features
.
formatOnType
.
register
(
selector
,
{
triggerCharacters
:
[
firstTriggerCharacter
].
concat
(
moreTriggerCharacters
),
provider
}
);
return
languageFeatures
.
registerOnTypeFormattingEditProvider
(
selector
,
provider
,
[
firstTriggerCharacter
].
concat
(
moreTriggerCharacters
)
);
},
registerSignatureHelpProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
SignatureHelpProvider
,
...
triggerCharacters
:
string
[]):
vscode
.
Disposable
{
return
features
.
signatureHelp
.
register
(
selector
,
{
triggerCharacters
,
provider
});
...
...
src/vs/workbench/api/common/extHostLanguageFeatures.ts
浏览文件 @
70988681
...
...
@@ -356,7 +356,78 @@ class QuickFixAdapter implements modes.IQuickFixSupport {
}
}
type
Adapter
=
OutlineAdapter
|
CodeLensAdapter
|
DeclarationAdapter
|
ExtraInfoAdapter
|
OccurrencesAdapter
|
ReferenceAdapter
|
QuickFixAdapter
;
class
DocumentFormattingAdapter
implements
modes
.
IFormattingSupport
{
private
_documents
:
PluginHostModelService
;
private
_provider
:
vscode
.
DocumentFormattingEditProvider
;
constructor
(
documents
:
PluginHostModelService
,
provider
:
vscode
.
DocumentFormattingEditProvider
)
{
this
.
_documents
=
documents
;
this
.
_provider
=
provider
;
}
formatDocument
(
resource
:
URI
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
let
doc
=
this
.
_documents
.
getDocument
(
resource
);
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideDocumentFormattingEdits
(
doc
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
}
});
}
}
class
RangeFormattingAdapter
implements
modes
.
IFormattingSupport
{
private
_documents
:
PluginHostModelService
;
private
_provider
:
vscode
.
DocumentRangeFormattingEditProvider
;
constructor
(
documents
:
PluginHostModelService
,
provider
:
vscode
.
DocumentRangeFormattingEditProvider
)
{
this
.
_documents
=
documents
;
this
.
_provider
=
provider
;
}
formatRange
(
resource
:
URI
,
range
:
IRange
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
let
doc
=
this
.
_documents
.
getDocument
(
resource
);
let
ran
=
TypeConverters
.
toRange
(
range
);
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideDocumentRangeFormattingEdits
(
doc
,
ran
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
}
});
}
}
class
OnTypeFormattingAdapter
implements
modes
.
IFormattingSupport
{
private
_documents
:
PluginHostModelService
;
private
_provider
:
vscode
.
OnTypeFormattingEditProvider
;
constructor
(
documents
:
PluginHostModelService
,
provider
:
vscode
.
OnTypeFormattingEditProvider
)
{
this
.
_documents
=
documents
;
this
.
_provider
=
provider
;
}
autoFormatTriggerCharacters
=
[];
// not here
formatAfterKeystroke
(
resource
:
URI
,
position
:
IPosition
,
ch
:
string
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
let
doc
=
this
.
_documents
.
getDocument
(
resource
);
let
pos
=
TypeConverters
.
toPosition
(
position
);
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideOnTypeFormattingEdits
(
doc
,
pos
,
ch
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
}
});
}
}
type
Adapter
=
OutlineAdapter
|
CodeLensAdapter
|
DeclarationAdapter
|
ExtraInfoAdapter
|
OccurrencesAdapter
|
ReferenceAdapter
|
QuickFixAdapter
|
DocumentFormattingAdapter
|
RangeFormattingAdapter
|
OnTypeFormattingAdapter
;
@
Remotable
.
PluginHostContext
(
'
ExtHostLanguageFeatures
'
)
export
class
ExtHostLanguageFeatures
{
...
...
@@ -491,6 +562,42 @@ export class ExtHostLanguageFeatures {
$runQuickFixAction
(
handle
:
number
,
resource
:
URI
,
range
:
IRange
,
id
:
string
):
any
{
return
this
.
_withAdapter
(
handle
,
QuickFixAdapter
,
adapter
=>
adapter
.
runQuickFixAction
(
resource
,
range
,
id
));
}
// --- formatting
registerDocumentFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
DocumentFormattingEditProvider
):
vscode
.
Disposable
{
const
handle
=
this
.
_nextHandle
();
this
.
_adapter
[
handle
]
=
new
DocumentFormattingAdapter
(
this
.
_documents
,
provider
);
this
.
_proxy
.
$registerDocumentFormattingSupport
(
handle
,
selector
);
return
this
.
_createDisposable
(
handle
);
}
$formatDocument
(
handle
:
number
,
resource
:
URI
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
return
this
.
_withAdapter
(
handle
,
DocumentFormattingAdapter
,
adapter
=>
adapter
.
formatDocument
(
resource
,
options
));
}
registerDocumentRangeFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
DocumentRangeFormattingEditProvider
):
vscode
.
Disposable
{
const
handle
=
this
.
_nextHandle
();
this
.
_adapter
[
handle
]
=
new
RangeFormattingAdapter
(
this
.
_documents
,
provider
);
this
.
_proxy
.
$registerRangeFormattingSupport
(
handle
,
selector
);
return
this
.
_createDisposable
(
handle
);
}
$formatRange
(
handle
:
number
,
resource
:
URI
,
range
:
IRange
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
return
this
.
_withAdapter
(
handle
,
RangeFormattingAdapter
,
adapter
=>
adapter
.
formatRange
(
resource
,
range
,
options
));
}
registerOnTypeFormattingEditProvider
(
selector
:
vscode
.
DocumentSelector
,
provider
:
vscode
.
OnTypeFormattingEditProvider
,
triggerCharacters
:
string
[]):
vscode
.
Disposable
{
const
handle
=
this
.
_nextHandle
();
this
.
_adapter
[
handle
]
=
new
OnTypeFormattingAdapter
(
this
.
_documents
,
provider
);
this
.
_proxy
.
$registerOnTypeFormattingSupport
(
handle
,
selector
,
triggerCharacters
);
return
this
.
_createDisposable
(
handle
);
}
$formatAfterKeystroke
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
ch
:
string
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
{
return
this
.
_withAdapter
(
handle
,
OnTypeFormattingAdapter
,
adapter
=>
adapter
.
formatAfterKeystroke
(
resource
,
position
,
ch
,
options
));
}
}
@
Remotable
.
MainContext
(
'
MainThreadLanguageFeatures
'
)
...
...
@@ -608,4 +715,36 @@ export class MainThreadLanguageFeatures {
});
return
undefined
;
}
// --- formatting
$registerDocumentFormattingSupport
(
handle
:
number
,
selector
:
vscode
.
DocumentSelector
):
TPromise
<
any
>
{
this
.
_registrations
[
handle
]
=
FormatRegistry
.
register
(
selector
,
<
modes
.
IFormattingSupport
>
{
formatDocument
:
(
resource
:
URI
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
=>
{
return
this
.
_proxy
.
$formatDocument
(
handle
,
resource
,
options
);
}
});
return
undefined
;
}
$registerRangeFormattingSupport
(
handle
:
number
,
selector
:
vscode
.
DocumentSelector
):
TPromise
<
any
>
{
this
.
_registrations
[
handle
]
=
FormatRegistry
.
register
(
selector
,
<
modes
.
IFormattingSupport
>
{
formatRange
:
(
resource
:
URI
,
range
:
IRange
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
=>
{
return
this
.
_proxy
.
$formatRange
(
handle
,
resource
,
range
,
options
);
}
});
return
undefined
;
}
$registerOnTypeFormattingSupport
(
handle
:
number
,
selector
:
vscode
.
DocumentSelector
,
autoFormatTriggerCharacters
:
string
[]):
TPromise
<
any
>
{
this
.
_registrations
[
handle
]
=
FormatOnTypeRegistry
.
register
(
selector
,
<
modes
.
IFormattingSupport
>
{
autoFormatTriggerCharacters
,
formatAfterKeystroke
:
(
resource
:
URI
,
position
:
IPosition
,
ch
:
string
,
options
:
modes
.
IFormattingOptions
):
TPromise
<
ISingleEditOperation
[]
>
=>
{
return
this
.
_proxy
.
$formatAfterKeystroke
(
handle
,
resource
,
position
,
ch
,
options
);
}
});
return
undefined
;
}
}
\ No newline at end of file
src/vs/workbench/api/common/pluginHostTypeConverters.ts
浏览文件 @
70988681
...
...
@@ -8,7 +8,7 @@ import Severity from 'vs/base/common/severity';
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
{
Position
as
EditorPosition
}
from
'
vs/platform/editor/common/editor
'
;
import
{
Selection
,
Range
,
Position
,
SymbolKind
,
DiagnosticSeverity
,
ViewColumn
}
from
'
./pluginHostTypes
'
;
import
{
IPosition
,
ISelection
,
IRange
,
IRangeWithMessage
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IPosition
,
ISelection
,
IRange
,
IRangeWithMessage
,
ISingleEditOperation
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IHTMLContentElement
}
from
'
vs/base/common/htmlContent
'
;
export
interface
PositionLike
{
...
...
@@ -189,3 +189,10 @@ export function fromRangeOrRangeWithMessage(ranges:vscode.Range[]|vscode.Decorat
});
}
}
export
function
fromTextEdit
(
edit
:
vscode
.
TextEdit
)
{
return
<
ISingleEditOperation
>
{
text
:
edit
.
newText
,
range
:
fromRange
(
edit
.
range
)
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录