Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a8770233
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a8770233
编写于
10月 24, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
word based completions use insert and replace ranges, #10266
上级
cab4cb5d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
24 deletion
+37
-24
src/vs/editor/common/services/editorSimpleWorker.ts
src/vs/editor/common/services/editorSimpleWorker.ts
+11
-17
src/vs/editor/common/services/editorWorkerServiceImpl.ts
src/vs/editor/common/services/editorWorkerServiceImpl.ts
+24
-4
src/vs/editor/test/common/services/editorSimpleWorker.test.ts
...vs/editor/test/common/services/editorSimpleWorker.test.ts
+2
-3
未找到文件。
src/vs/editor/common/services/editorSimpleWorker.ts
浏览文件 @
a8770233
...
...
@@ -17,7 +17,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
EndOfLineSequence
,
IWordAtPosition
}
from
'
vs/editor/common/model
'
;
import
{
IModelChangedEvent
,
MirrorTextModel
as
BaseMirrorModel
}
from
'
vs/editor/common/model/mirrorTextModel
'
;
import
{
ensureValidWordDefinition
,
getWordAtText
}
from
'
vs/editor/common/model/wordHelper
'
;
import
{
CompletionItem
,
CompletionItemKind
,
CompletionList
,
IInplaceReplaceSupportResult
,
ILink
,
TextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
IInplaceReplaceSupportResult
,
ILink
,
TextEdit
}
from
'
vs/editor/common/modes
'
;
import
{
ILinkComputerTarget
,
computeLinks
}
from
'
vs/editor/common/modes/linkComputer
'
;
import
{
BasicInplaceReplace
}
from
'
vs/editor/common/modes/supports/inplaceReplaceSupport
'
;
import
{
IDiffComputationResult
}
from
'
vs/editor/common/services/editorWorkerService
'
;
...
...
@@ -529,44 +529,38 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable {
private
static
readonly
_suggestionsLimit
=
10000
;
public
async
textualSuggest
(
modelUrl
:
string
,
position
:
IPosition
,
wordDef
:
string
,
wordDefFlags
:
string
):
Promise
<
CompletionList
|
null
>
{
public
async
textualSuggest
(
modelUrl
:
string
,
position
:
IPosition
,
wordDef
:
string
,
wordDefFlags
:
string
):
Promise
<
string
[]
|
null
>
{
const
model
=
this
.
_getModel
(
modelUrl
);
if
(
!
model
)
{
return
null
;
}
const
seen
:
Record
<
string
,
boolean
>
=
Object
.
create
(
null
);
const
suggestions
:
CompletionItem
[]
=
[];
const
words
:
string
[]
=
[];
const
seen
=
new
Set
<
string
>
();
const
wordDefRegExp
=
new
RegExp
(
wordDef
,
wordDefFlags
);
const
wordUntil
=
model
.
getWordUntilPosition
(
position
,
wordDefRegExp
);
const
wordAt
=
model
.
getWordAtPosition
(
position
,
wordDefRegExp
);
if
(
wordAt
)
{
seen
[
model
.
getValueInRange
(
wordAt
)]
=
true
;
seen
.
add
(
model
.
getValueInRange
(
wordAt
))
;
}
for
(
let
iter
=
model
.
createWordIterator
(
wordDefRegExp
),
e
=
iter
.
next
();
!
e
.
done
&&
s
uggestions
.
length
<=
EditorSimpleWorker
.
_suggestionsLimit
;
!
e
.
done
&&
s
een
.
size
<=
EditorSimpleWorker
.
_suggestionsLimit
;
e
=
iter
.
next
()
)
{
const
word
=
e
.
value
;
if
(
seen
[
word
]
)
{
if
(
seen
.
has
(
word
)
)
{
continue
;
}
seen
[
word
]
=
true
;
seen
.
add
(
word
)
;
if
(
!
isNaN
(
Number
(
word
)))
{
continue
;
}
suggestions
.
push
({
kind
:
CompletionItemKind
.
Text
,
label
:
word
,
insertText
:
word
,
range
:
{
startLineNumber
:
position
.
lineNumber
,
startColumn
:
wordUntil
.
startColumn
,
endLineNumber
:
position
.
lineNumber
,
endColumn
:
wordUntil
.
endColumn
}
});
words
.
push
(
word
);
}
return
{
suggestions
}
;
return
words
;
}
...
...
src/vs/editor/common/services/editorWorkerServiceImpl.ts
浏览文件 @
a8770233
...
...
@@ -9,7 +9,7 @@ import { URI } from 'vs/base/common/uri';
import
{
SimpleWorkerClient
,
logOnceWebWorkerWarning
,
IWorkerClient
}
from
'
vs/base/common/worker/simpleWorker
'
;
import
{
DefaultWorkerFactory
}
from
'
vs/base/worker/defaultWorkerFactory
'
;
import
{
IPosition
,
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
IRange
,
Range
}
from
'
vs/editor/common/core/range
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
...
...
@@ -144,7 +144,7 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider {
this
.
_modelService
=
modelService
;
}
provideCompletionItems
(
model
:
ITextModel
,
position
:
Position
):
Promise
<
modes
.
CompletionList
|
null
>
|
undefined
{
async
provideCompletionItems
(
model
:
ITextModel
,
position
:
Position
):
Promise
<
modes
.
CompletionList
|
undefined
>
{
const
{
wordBasedSuggestions
}
=
this
.
_configurationService
.
getValue
<
{
wordBasedSuggestions
?:
boolean
}
>
(
model
.
uri
,
position
,
'
editor
'
);
if
(
!
wordBasedSuggestions
)
{
return
undefined
;
...
...
@@ -152,7 +152,27 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider {
if
(
!
canSyncModel
(
this
.
_modelService
,
model
.
uri
))
{
return
undefined
;
// File too large
}
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
textualSuggest
(
model
.
uri
,
position
));
const
client
=
await
this
.
_workerManager
.
withWorker
();
const
words
=
await
client
.
textualSuggest
(
model
.
uri
,
position
);
if
(
!
words
)
{
return
undefined
;
}
const
word
=
model
.
getWordAtPosition
(
position
);
const
replace
=
!
word
?
Range
.
fromPositions
(
position
)
:
new
Range
(
position
.
lineNumber
,
word
.
startColumn
,
position
.
lineNumber
,
word
.
endColumn
);
const
insert
=
replace
.
setEndPosition
(
position
.
lineNumber
,
position
.
column
);
return
{
suggestions
:
words
.
map
((
word
):
modes
.
CompletionItem
=>
{
return
{
kind
:
modes
.
CompletionItemKind
.
Text
,
label
:
word
,
insertText
:
word
,
range
:
{
insert
,
replace
}
};
})
};
}
}
...
...
@@ -433,7 +453,7 @@ export class EditorWorkerClient extends Disposable {
});
}
public
textualSuggest
(
resource
:
URI
,
position
:
IPosition
):
Promise
<
modes
.
CompletionList
|
null
>
{
public
textualSuggest
(
resource
:
URI
,
position
:
IPosition
):
Promise
<
string
[]
|
null
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
let
model
=
this
.
_modelService
.
getModel
(
resource
);
if
(
!
model
)
{
...
...
src/vs/editor/test/common/services/editorSimpleWorker.test.ts
浏览文件 @
a8770233
...
...
@@ -167,9 +167,8 @@ suite('EditorSimpleWorker', () => {
assert
.
ok
(
false
);
return
;
}
const
{
suggestions
}
=
result
;
assert
.
equal
(
suggestions
.
length
,
1
);
assert
.
equal
(
suggestions
[
0
].
label
,
'
foobar
'
);
assert
.
equal
(
result
.
length
,
1
);
assert
.
equal
(
result
,
'
foobar
'
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录