Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
7ab052ae
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,发现更多精彩内容 >>
提交
7ab052ae
编写于
5月 19, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first cut of token_at_position api,
https://github.com/microsoft/vscode/issues/91555
上级
a2675641
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
91 addition
and
1 deletion
+91
-1
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+20
-0
src/vs/workbench/api/browser/mainThreadLanguages.ts
src/vs/workbench/api/browser/mainThreadLanguages.ts
+18
-0
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+5
-0
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+1
-0
src/vs/workbench/api/common/extHostLanguages.ts
src/vs/workbench/api/common/extHostLanguages.ts
+29
-0
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+12
-1
src/vs/workbench/api/common/extHostTypes.ts
src/vs/workbench/api/common/extHostTypes.ts
+6
-0
未找到文件。
src/vs/vscode.proposed.d.ts
浏览文件 @
7ab052ae
...
...
@@ -2203,4 +2203,24 @@ declare module 'vscode' {
//#endregion
//#region https://github.com/microsoft/vscode/issues/91555
export
enum
StandardTokenType
{
Other
=
0
,
Comment
=
1
,
String
=
2
,
RegEx
=
4
}
export
interface
TokenInformation
{
type
:
StandardTokenType
;
range
:
Range
;
}
export
namespace
languages
{
export
function
getTokenInformationAtPosition
(
document
:
TextDocument
,
position
:
Position
):
Promise
<
TokenInformation
>
;
}
//#endregion
}
src/vs/workbench/api/browser/mainThreadLanguages.ts
浏览文件 @
7ab052ae
...
...
@@ -8,6 +8,9 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
MainThreadLanguagesShape
,
MainContext
,
IExtHostContext
}
from
'
../common/extHost.protocol
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/common/extHostCustomers
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
IRange
,
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
StandardTokenType
}
from
'
vs/editor/common/modes
'
;
@
extHostNamedCustomer
(
MainContext
.
MainThreadLanguages
)
export
class
MainThreadLanguages
implements
MainThreadLanguagesShape
{
...
...
@@ -40,4 +43,19 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
this
.
_modelService
.
setMode
(
model
,
this
.
_modeService
.
create
(
languageId
));
return
Promise
.
resolve
(
undefined
);
}
async
$tokensAtPosition
(
resource
:
UriComponents
,
position
:
IPosition
):
Promise
<
undefined
|
{
type
:
StandardTokenType
,
range
:
IRange
}
>
{
const
uri
=
URI
.
revive
(
resource
);
const
model
=
this
.
_modelService
.
getModel
(
uri
);
if
(
!
model
)
{
return
undefined
;
}
model
.
tokenizeIfCheap
(
position
.
lineNumber
);
const
tokens
=
model
.
getLineTokens
(
position
.
lineNumber
);
const
idx
=
tokens
.
findTokenIndexAtOffset
(
position
.
column
-
1
);
return
{
type
:
tokens
.
getStandardTokenType
(
idx
),
range
:
new
Range
(
position
.
lineNumber
,
1
+
tokens
.
getStartOffset
(
idx
),
position
.
lineNumber
,
1
+
tokens
.
getEndOffset
(
idx
))
};
}
}
src/vs/workbench/api/common/extHost.api.impl.ts
浏览文件 @
7ab052ae
...
...
@@ -431,6 +431,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
setLanguageConfiguration
:
(
language
:
string
,
configuration
:
vscode
.
LanguageConfiguration
):
vscode
.
Disposable
=>
{
return
extHostLanguageFeatures
.
setLanguageConfiguration
(
extension
,
language
,
configuration
);
},
getTokenInformationAtPosition
(
doc
:
vscode
.
TextDocument
,
pos
:
vscode
.
Position
)
{
checkProposedApiEnabled
(
extension
);
return
extHostLanguages
.
tokenAtPosition
(
doc
,
pos
);
}
};
...
...
@@ -1040,6 +1044,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
SnippetString
:
extHostTypes
.
SnippetString
,
SourceBreakpoint
:
extHostTypes
.
SourceBreakpoint
,
SourceControlInputBoxValidationType
:
extHostTypes
.
SourceControlInputBoxValidationType
,
StandardTokenType
:
extHostTypes
.
StandardTokenType
,
StatusBarAlignment
:
extHostTypes
.
StatusBarAlignment
,
SymbolInformation
:
extHostTypes
.
SymbolInformation
,
SymbolKind
:
extHostTypes
.
SymbolKind
,
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
7ab052ae
...
...
@@ -393,6 +393,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
export
interface
MainThreadLanguagesShape
extends
IDisposable
{
$getLanguages
():
Promise
<
string
[]
>
;
$changeLanguage
(
resource
:
UriComponents
,
languageId
:
string
):
Promise
<
void
>
;
$tokensAtPosition
(
resource
:
UriComponents
,
position
:
IPosition
):
Promise
<
undefined
|
{
type
:
modes
.
StandardTokenType
,
range
:
IRange
}
>
;
}
export
interface
MainThreadMessageOptions
{
...
...
src/vs/workbench/api/common/extHostLanguages.ts
浏览文件 @
7ab052ae
...
...
@@ -6,6 +6,8 @@
import
{
MainContext
,
MainThreadLanguagesShape
,
IMainContext
}
from
'
./extHost.protocol
'
;
import
type
*
as
vscode
from
'
vscode
'
;
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/common/extHostDocuments
'
;
import
*
as
typeConvert
from
'
vs/workbench/api/common/extHostTypeConverters
'
;
import
{
StandardTokenType
,
Range
,
Position
}
from
'
vs/workbench/api/common/extHostTypes
'
;
export
class
ExtHostLanguages
{
...
...
@@ -32,4 +34,31 @@ export class ExtHostLanguages {
}
return
data
.
document
;
}
async
tokenAtPosition
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
):
Promise
<
vscode
.
TokenInformation
>
{
const
versionNow
=
document
.
version
;
const
pos
=
typeConvert
.
Position
.
from
(
position
);
const
info
=
await
this
.
_proxy
.
$tokensAtPosition
(
document
.
uri
,
pos
);
const
defaultRange
=
{
type
:
StandardTokenType
.
Other
,
range
:
document
.
getWordRangeAtPosition
(
position
)
??
new
Range
(
position
.
line
,
position
.
character
,
position
.
line
,
position
.
character
)
};
if
(
!
info
)
{
// no result
return
defaultRange
;
}
const
result
=
{
range
:
typeConvert
.
Range
.
to
(
info
.
range
),
type
:
typeConvert
.
TokenType
.
to
(
info
.
type
)
};
if
(
!
result
.
range
.
contains
(
<
Position
>
position
))
{
// bogous result
return
defaultRange
;
}
if
(
versionNow
!==
document
.
version
)
{
// concurrent change
return
defaultRange
;
}
return
result
;
}
}
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
7ab052ae
...
...
@@ -95,11 +95,22 @@ export namespace Range {
}
}
export
namespace
TokenType
{
export
function
to
(
type
:
modes
.
StandardTokenType
):
types
.
StandardTokenType
{
switch
(
type
)
{
case
modes
.
StandardTokenType
.
Comment
:
return
types
.
StandardTokenType
.
Comment
;
case
modes
.
StandardTokenType
.
Other
:
return
types
.
StandardTokenType
.
Other
;
case
modes
.
StandardTokenType
.
RegEx
:
return
types
.
StandardTokenType
.
RegEx
;
case
modes
.
StandardTokenType
.
String
:
return
types
.
StandardTokenType
.
String
;
}
}
}
export
namespace
Position
{
export
function
to
(
position
:
IPosition
):
types
.
Position
{
return
new
types
.
Position
(
position
.
lineNumber
-
1
,
position
.
column
-
1
);
}
export
function
from
(
position
:
types
.
Position
):
IPosition
{
export
function
from
(
position
:
types
.
Position
|
vscode
.
Position
):
IPosition
{
return
{
lineNumber
:
position
.
line
+
1
,
column
:
position
.
character
+
1
};
}
}
...
...
src/vs/workbench/api/common/extHostTypes.ts
浏览文件 @
7ab052ae
...
...
@@ -2774,3 +2774,9 @@ export class AuthenticationSession implements vscode.AuthenticationSession2 {
}
//#endregion Authentication
export
enum
StandardTokenType
{
Other
=
0
,
Comment
=
1
,
String
=
2
,
RegEx
=
4
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录