Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
00a663b3
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
00a663b3
编写于
11月 18, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow to provide regexp when asking for word ranges, #15724
上级
430cbc46
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
7 deletion
+45
-7
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+4
-2
src/vs/workbench/api/node/extHostDocuments.ts
src/vs/workbench/api/node/extHostDocuments.ts
+7
-4
src/vs/workbench/test/node/api/extHostDocuments.test.ts
src/vs/workbench/test/node/api/extHostDocuments.test.ts
+34
-1
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
00a663b3
...
...
@@ -209,14 +209,16 @@ declare module 'vscode' {
/**
* Get a word-range at the given position. By default words are defined by
* common separators, like space, -, _, etc. In addition, per languge custom
* [word definitions](#LanguageConfiguration.wordPattern) can be defined.
* [word definitions](#LanguageConfiguration.wordPattern) can be defined. It
* is also possible to provide a custom regular expression.
*
* The position will be [adjusted](#TextDocument.validatePosition).
*
* @param position A position.
* @param regex Optional regular expression that describes what a word is.
* @return A range spanning a word, or `undefined`.
*/
getWordRangeAtPosition
(
position
:
Position
):
Range
;
getWordRangeAtPosition
(
position
:
Position
,
regex
?:
RegExp
):
Range
;
/**
* Ensure a range is completely contained in this document.
...
...
src/vs/workbench/api/node/extHostDocuments.ts
浏览文件 @
00a663b3
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
regExpLeadsToEndlessLoop
}
from
'
vs/base/common/strings
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
MirrorModel2
}
from
'
vs/editor/common/model/mirrorModel2
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
...
...
@@ -262,7 +263,7 @@ export class ExtHostDocumentData extends MirrorModel2 {
positionAt
(
offset
)
{
return
data
.
positionAt
(
offset
);
},
validateRange
(
ran
)
{
return
data
.
validateRange
(
ran
);
},
validatePosition
(
pos
)
{
return
data
.
validatePosition
(
pos
);
},
getWordRangeAtPosition
(
pos
)
{
return
data
.
getWordRangeAtPosition
(
pos
);
}
getWordRangeAtPosition
(
pos
,
regexp
?)
{
return
data
.
getWordRangeAtPosition
(
pos
,
regexp
);
}
};
}
return
this
.
_document
;
...
...
@@ -410,12 +411,14 @@ export class ExtHostDocumentData extends MirrorModel2 {
return
new
Position
(
line
,
character
);
}
getWordRangeAtPosition
(
_position
:
vscode
.
Position
):
vscode
.
Range
{
getWordRangeAtPosition
(
_position
:
vscode
.
Position
,
regexp
?:
RegExp
):
vscode
.
Range
{
let
position
=
this
.
validatePosition
(
_position
);
if
(
!
regexp
||
regExpLeadsToEndlessLoop
(
regexp
))
{
regexp
=
getWordDefinitionFor
(
this
.
_languageId
);
}
let
wordAtText
=
getWordAtText
(
position
.
character
+
1
,
ensureValidWordDefinition
(
getWordDefinitionFor
(
this
.
_languageId
)
),
ensureValidWordDefinition
(
regexp
),
this
.
_lines
[
position
.
line
],
0
);
...
...
src/vs/workbench/test/node/api/extHostDocuments.test.ts
浏览文件 @
00a663b3
...
...
@@ -204,6 +204,39 @@ suite('ExtHostDocument', () => {
assertPositionAt
(
99
,
3
,
29
);
assertPositionAt
(
Number
.
MAX_VALUE
,
3
,
29
);
});
test
(
'
getWordRangeAtPosition
'
,
function
()
{
data
=
new
ExtHostDocumentData
(
undefined
,
URI
.
file
(
''
),
[
'
aaaa bbbb cccc abc
'
],
'
\n
'
,
'
text
'
,
1
,
false
);
let
range
=
data
.
getWordRangeAtPosition
(
new
Position
(
0
,
2
));
assert
.
equal
(
range
.
start
.
line
,
0
);
assert
.
equal
(
range
.
start
.
character
,
0
);
assert
.
equal
(
range
.
end
.
line
,
0
);
assert
.
equal
(
range
.
end
.
character
,
4
);
range
=
data
.
getWordRangeAtPosition
(
new
Position
(
0
,
2
),
/.*/
);
assert
.
equal
(
range
.
start
.
line
,
0
);
assert
.
equal
(
range
.
start
.
character
,
0
);
assert
.
equal
(
range
.
end
.
line
,
0
);
assert
.
equal
(
range
.
end
.
character
,
4
);
range
=
data
.
getWordRangeAtPosition
(
new
Position
(
0
,
2
),
/a+.+
?
c/
);
assert
.
equal
(
range
.
start
.
line
,
0
);
assert
.
equal
(
range
.
start
.
character
,
0
);
assert
.
equal
(
range
.
end
.
line
,
0
);
assert
.
equal
(
range
.
end
.
character
,
11
);
range
=
data
.
getWordRangeAtPosition
(
new
Position
(
0
,
17
),
/a+.+
?
c/
);
assert
.
equal
(
range
.
start
.
line
,
0
);
assert
.
equal
(
range
.
start
.
character
,
15
);
assert
.
equal
(
range
.
end
.
line
,
0
);
assert
.
equal
(
range
.
end
.
character
,
18
);
range
=
data
.
getWordRangeAtPosition
(
new
Position
(
0
,
11
),
/yy/
);
assert
.
equal
(
range
,
undefined
);
});
});
enum
AssertDocumentLineMappingDirection
{
...
...
@@ -372,4 +405,4 @@ suite('ExtHostDocument updates line mapping', () => {
'
and finished with the fourth.
'
,
],
[
createChangeEvent
(
new
CodeEditorRange
(
1
,
1
,
1
,
1
),
''
,
'
\n
'
)]);
});
});
\ No newline at end of file
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录