Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
893a7837
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,发现更多精彩内容 >>
提交
893a7837
编写于
11月 27, 2015
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands: executeDocumentSymbolProvider
上级
67084502
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
160 addition
and
54 deletion
+160
-54
src/vs/editor/contrib/quickOpen/common/quickOpen.ts
src/vs/editor/contrib/quickOpen/common/quickOpen.ts
+23
-2
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
...vs/workbench/api/common/extHostLanguageFeatureCommands.ts
+14
-2
src/vs/workbench/api/common/extHostLanguageFeatures.ts
src/vs/workbench/api/common/extHostLanguageFeatures.ts
+1
-11
src/vs/workbench/api/common/pluginHostTypeConverters.ts
src/vs/workbench/api/common/pluginHostTypeConverters.ts
+97
-37
src/vs/workbench/test/common/api/extHostLanguageFeatureCommands.test.ts
...ch/test/common/api/extHostLanguageFeatureCommands.test.ts
+25
-2
未找到文件。
src/vs/editor/contrib/quickOpen/common/quickOpen.ts
浏览文件 @
893a7837
...
...
@@ -5,12 +5,15 @@
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
onUnexpectedError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IOutlineEntry
,
IOutlineSupport
}
from
'
vs/editor/common/modes
'
;
import
LanguageFeatureRegistry
from
'
vs/editor/common/modes/languageFeatureRegistry
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
const
OutlineRegistry
=
new
LanguageFeatureRegistry
<
IOutlineSupport
>
(
'
outlineSupport
'
);
...
...
@@ -20,7 +23,12 @@ export {
IOutlineSupport
}
export
function
getOutlineEntries
(
model
:
IModel
):
TPromise
<
{
entries
:
IOutlineEntry
[],
outlineGroupLabel
:
{
[
n
:
string
]:
string
;}
}
>
{
export
interface
IOutline
{
entries
:
IOutlineEntry
[];
outlineGroupLabel
:
{
[
n
:
string
]:
string
;
};
}
export
function
getOutlineEntries
(
model
:
IModel
):
TPromise
<
IOutline
>
{
let
groupLabels
:
{
[
n
:
string
]:
string
}
=
Object
.
create
(
null
);
let
entries
:
IOutlineEntry
[]
=
[];
...
...
@@ -74,3 +82,16 @@ function flatten(bucket: IOutlineEntry[], entries: IOutlineEntry[], overrideCont
}
}
}
CommonEditorRegistry
.
registerLanguageCommand
(
'
_executeDocumentSymbolProvider
'
,
function
(
accessor
,
args
)
{
const
{
resource
}
=
args
;
if
(
!
URI
.
isURI
(
resource
))
{
throw
illegalArgument
(
'
resource
'
);
}
const
model
=
accessor
.
get
(
IModelService
).
getModel
(
resource
);
if
(
!
model
)
{
throw
illegalArgument
(
'
resource
'
);
}
return
getOutlineEntries
(
model
);
});
\ No newline at end of file
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
浏览文件 @
893a7837
...
...
@@ -29,7 +29,7 @@ import {ExtraInfoRegistry} from 'vs/editor/contrib/hover/common/hover';
import
{
OccurrencesRegistry
}
from
'
vs/editor/contrib/wordHighlighter/common/wordHighlighter
'
;
import
{
ReferenceRegistry
}
from
'
vs/editor/contrib/referenceSearch/common/referenceSearch
'
;
import
{
QuickFixRegistry
}
from
'
vs/editor/contrib/quickFix/common/quickFix
'
;
import
{
OutlineRegistry
,
IOutlineEntry
,
IOutlineSupport
}
from
'
vs/editor/contrib/quickOpen/common/quickOpen
'
;
import
{
IOutline
}
from
'
vs/editor/contrib/quickOpen/common/quickOpen
'
;
import
LanguageFeatureRegistry
from
'
vs/editor/common/modes/languageFeatureRegistry
'
;
import
{
NavigateTypesSupportRegistry
,
INavigateTypesSupport
,
ITypeBearing
}
from
'
vs/workbench/parts/search/common/search
'
import
{
RenameRegistry
}
from
'
vs/editor/contrib/rename/common/rename
'
;
...
...
@@ -45,10 +45,10 @@ import {SuggestRegistry} from 'vs/editor/contrib/suggest/common/suggest';
// vscode.executeReferenceProvider
// vscode.executeDocumentRenameProvider
// vscode.executeSignatureHelpProvider
// vscode.executeDocumentSymbolProvider
// vscode.executeCodeActionProvider
// vscode.executeCodeLensProvider
// vscode.executeDocumentSymbolProvider
// vscode.executeFormatDocumentProvider
// vscode.executeFormatRangeProvider
// vscode.executeFormatOnTypeProvider
...
...
@@ -69,6 +69,7 @@ export class ExtHostLanguageFeatureCommands {
this
.
_register
(
'
vscode.executeReferenceProvider
'
,
this
.
_executeReferenceProvider
);
this
.
_register
(
'
vscode.executeDocumentRenameProvider
'
,
this
.
_executeDocumentRenameProvider
);
this
.
_register
(
'
vscode.executeSignatureHelpProvider
'
,
this
.
_executeSignatureHelpProvider
);
this
.
_register
(
'
vscode.executeDocumentSymbolProvider
'
,
this
.
_executeDocumentSymbolProvider
);
}
private
_register
(
id
:
string
,
callback
:
(...
args
:
any
[])
=>
any
):
void
{
...
...
@@ -166,4 +167,15 @@ export class ExtHostLanguageFeatureCommands {
}
});
}
private
_executeDocumentSymbolProvider
(
resource
:
URI
):
Thenable
<
types
.
SymbolInformation
[]
>
{
const
args
=
{
resource
};
return
this
.
_commands
.
executeCommand
<
IOutline
>
(
'
_executeDocumentSymbolProvider
'
,
args
).
then
(
value
=>
{
if
(
value
&&
Array
.
isArray
(
value
.
entries
))
{
return
value
.
entries
.
map
(
typeConverters
.
SymbolInformation
.
fromOutlineEntry
);
}
});
}
}
\ No newline at end of file
src/vs/workbench/api/common/extHostLanguageFeatures.ts
浏览文件 @
893a7837
...
...
@@ -72,20 +72,10 @@ class OutlineAdapter implements IOutlineSupport {
let
doc
=
this
.
_documents
.
getDocument
(
resource
);
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideDocumentSymbols
(
doc
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
OutlineAdapter
.
_convertSymbolInfo
);
return
value
.
map
(
TypeConverters
.
SymbolInformation
.
toOutlineEntry
);
}
});
}
private
static
_convertSymbolInfo
(
symbol
:
vscode
.
SymbolInformation
):
IOutlineEntry
{
return
<
IOutlineEntry
>
{
type
:
TypeConverters
.
fromSymbolKind
(
symbol
.
kind
),
range
:
TypeConverters
.
fromRange
(
symbol
.
location
.
range
),
containerLabel
:
symbol
.
containerName
,
label
:
symbol
.
name
,
icon
:
undefined
,
};
}
}
class
CodeLensAdapter
implements
modes
.
ICodeLensSupport
{
...
...
src/vs/workbench/api/common/pluginHostTypeConverters.ts
浏览文件 @
893a7837
...
...
@@ -68,43 +68,6 @@ export function fromPosition(position: types.Position):IPosition {
return
{
lineNumber
:
position
.
line
+
1
,
column
:
position
.
character
+
1
};
}
export
function
fromSymbolKind
(
kind
:
number
|
types
.
SymbolKind
):
string
{
switch
(
kind
)
{
case
types
.
SymbolKind
.
Method
:
return
'
method
'
;
case
types
.
SymbolKind
.
Function
:
return
'
function
'
;
case
types
.
SymbolKind
.
Constructor
:
return
'
constructor
'
;
case
types
.
SymbolKind
.
Variable
:
return
'
variable
'
;
case
types
.
SymbolKind
.
Class
:
return
'
class
'
;
case
types
.
SymbolKind
.
Interface
:
return
'
interface
'
;
case
types
.
SymbolKind
.
Module
:
case
types
.
SymbolKind
.
Namespace
:
case
types
.
SymbolKind
.
Package
:
return
'
module
'
;
case
types
.
SymbolKind
.
Property
:
return
'
property
'
;
case
types
.
SymbolKind
.
Enum
:
return
'
enum
'
;
case
types
.
SymbolKind
.
String
:
return
'
string
'
;
case
types
.
SymbolKind
.
File
:
return
'
file
'
;
case
types
.
SymbolKind
.
Array
:
return
'
array
'
;
case
types
.
SymbolKind
.
Number
:
return
'
number
'
;
case
types
.
SymbolKind
.
Boolean
:
return
'
boolean
'
;
}
return
'
property
'
;
}
export
function
fromDiagnosticSeverity
(
value
:
number
):
Severity
{
switch
(
value
)
{
case
types
.
DiagnosticSeverity
.
Error
:
...
...
@@ -211,6 +174,103 @@ export function fromTextEdit(edit: vscode.TextEdit) {
}
}
export
namespace
SymbolKind
{
export
function
from
(
kind
:
number
|
types
.
SymbolKind
):
string
{
switch
(
kind
)
{
case
types
.
SymbolKind
.
Method
:
return
'
method
'
;
case
types
.
SymbolKind
.
Function
:
return
'
function
'
;
case
types
.
SymbolKind
.
Constructor
:
return
'
constructor
'
;
case
types
.
SymbolKind
.
Variable
:
return
'
variable
'
;
case
types
.
SymbolKind
.
Class
:
return
'
class
'
;
case
types
.
SymbolKind
.
Interface
:
return
'
interface
'
;
case
types
.
SymbolKind
.
Module
:
case
types
.
SymbolKind
.
Namespace
:
case
types
.
SymbolKind
.
Package
:
return
'
module
'
;
case
types
.
SymbolKind
.
Property
:
return
'
property
'
;
case
types
.
SymbolKind
.
Enum
:
return
'
enum
'
;
case
types
.
SymbolKind
.
String
:
return
'
string
'
;
case
types
.
SymbolKind
.
File
:
return
'
file
'
;
case
types
.
SymbolKind
.
Array
:
return
'
array
'
;
case
types
.
SymbolKind
.
Number
:
return
'
number
'
;
case
types
.
SymbolKind
.
Boolean
:
return
'
boolean
'
;
}
return
'
property
'
;
}
export
function
to
(
type
:
string
):
types
.
SymbolKind
{
switch
(
type
)
{
case
'
method
'
:
return
types
.
SymbolKind
.
Method
;
case
'
function
'
:
return
types
.
SymbolKind
.
Function
;
case
'
constructor
'
:
return
types
.
SymbolKind
.
Constructor
;
case
'
variable
'
:
return
types
.
SymbolKind
.
Variable
;
case
'
class
'
:
return
types
.
SymbolKind
.
Class
;
case
'
interface
'
:
return
types
.
SymbolKind
.
Interface
;
case
'
module
'
:
// case types.SymbolKind.Namespace:
// case types.SymbolKind.Package:
return
types
.
SymbolKind
.
Module
;
case
'
property
'
:
return
types
.
SymbolKind
.
Property
;
case
'
enum
'
:
return
types
.
SymbolKind
.
Enum
;
case
'
string
'
:
return
types
.
SymbolKind
.
String
;
case
'
file
'
:
return
types
.
SymbolKind
.
File
;
case
'
array
'
:
return
types
.
SymbolKind
.
Array
;
case
'
number
'
:
return
types
.
SymbolKind
.
Number
;
case
'
boolean
'
:
return
types
.
SymbolKind
.
Boolean
;
}
return
types
.
SymbolKind
.
Property
}
}
export
namespace
SymbolInformation
{
export
function
fromOutlineEntry
(
entry
:
modes
.
IOutlineEntry
):
types
.
SymbolInformation
{
return
new
types
.
SymbolInformation
(
entry
.
label
,
SymbolKind
.
to
(
entry
.
type
),
toRange
(
entry
.
range
),
undefined
,
entry
.
containerLabel
)
}
export
function
toOutlineEntry
(
symbol
:
vscode
.
SymbolInformation
):
modes
.
IOutlineEntry
{
return
<
modes
.
IOutlineEntry
>
{
type
:
SymbolKind
.
from
(
symbol
.
kind
),
range
:
fromRange
(
symbol
.
location
.
range
),
containerLabel
:
symbol
.
containerName
,
label
:
symbol
.
name
,
icon
:
undefined
,
};
}
}
export
function
fromSymbolInformation
(
info
:
vscode
.
SymbolInformation
):
ITypeBearing
{
return
<
ITypeBearing
>
{
name
:
info
.
name
,
...
...
src/vs/workbench/test/common/api/extHostLanguageFeatureCommands.test.ts
浏览文件 @
893a7837
...
...
@@ -188,7 +188,7 @@ suite('ExtHostLanguageFeatureCommands', function() {
test
(
'
Definition, ⇔ back and forth
'
,
function
(
done
)
{
disposables
.
push
(
extHost
.
registerDefinitionProvider
(
defaultSelector
,
<
vscode
.
DefinitionProvider
>
{
provideDefinition
(
doc
:
any
):
any
{
provideDefinition
(
doc
:
any
):
any
{
return
new
types
.
Location
(
doc
.
uri
,
new
types
.
Range
(
0
,
0
,
0
,
0
));
}
}));
...
...
@@ -208,5 +208,28 @@ suite('ExtHostLanguageFeatureCommands', function() {
done
();
});
});
})
});
// --- outline
test
(
'
Outline, back and forth
'
,
function
(
done
)
{
disposables
.
push
(
extHost
.
registerDocumentSymbolProvider
(
defaultSelector
,
<
vscode
.
DocumentSymbolProvider
>
{
provideDocumentSymbols
():
any
{
return
[
new
types
.
SymbolInformation
(
'
testing1
'
,
types
.
SymbolKind
.
Enum
,
new
types
.
Range
(
1
,
0
,
1
,
0
)),
new
types
.
SymbolInformation
(
'
testing2
'
,
types
.
SymbolKind
.
Enum
,
new
types
.
Range
(
0
,
1
,
0
,
3
)),
]
}
}));
threadService
.
sync
().
then
(()
=>
{
commands
.
executeCommand
<
vscode
.
SymbolInformation
[]
>
(
'
vscode.executeDocumentSymbolProvider
'
,
model
.
getAssociatedResource
()).
then
(
values
=>
{
assert
.
equal
(
values
.
length
,
2
);
let
[
first
,
second
]
=
values
;
assert
.
equal
(
first
.
name
,
'
testing2
'
);
assert
.
equal
(
second
.
name
,
'
testing1
'
);
done
();
});
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录