Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d9067043
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,发现更多精彩内容 >>
提交
d9067043
编写于
7月 25, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 'vscode.executeLinkProvider' command
上级
c1b999fd
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
130 addition
and
100 deletion
+130
-100
src/vs/editor/common/services/editorWorkerService.ts
src/vs/editor/common/services/editorWorkerService.ts
+1
-2
src/vs/editor/common/services/editorWorkerServiceImpl.ts
src/vs/editor/common/services/editorWorkerServiceImpl.ts
+16
-7
src/vs/editor/contrib/links/browser/links.ts
src/vs/editor/contrib/links/browser/links.ts
+4
-74
src/vs/editor/contrib/links/common/links.ts
src/vs/editor/contrib/links/common/links.ts
+72
-16
src/vs/workbench/api/node/extHostApiCommands.ts
src/vs/workbench/api/node/extHostApiCommands.ts
+15
-1
src/vs/workbench/test/node/api/extHostApiCommands.test.ts
src/vs/workbench/test/node/api/extHostApiCommands.test.ts
+22
-0
未找到文件。
src/vs/editor/common/services/editorWorkerService.ts
浏览文件 @
d9067043
...
...
@@ -8,7 +8,7 @@ import URI from 'vs/base/common/uri';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IChange
,
ILineChange
,
IPosition
,
IRange
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IInplaceReplaceSupportResult
,
I
Link
,
I
SuggestResult
}
from
'
vs/editor/common/modes
'
;
import
{
IInplaceReplaceSupportResult
,
ISuggestResult
}
from
'
vs/editor/common/modes
'
;
export
var
ID_EDITOR_WORKER_SERVICE
=
'
editorWorkerService
'
;
export
var
IEditorWorkerService
=
createDecorator
<
IEditorWorkerService
>
(
ID_EDITOR_WORKER_SERVICE
);
...
...
@@ -18,7 +18,6 @@ export interface IEditorWorkerService {
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
TPromise
<
ILineChange
[]
>
;
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
TPromise
<
IChange
[]
>
;
computeLinks
(
resource
:
URI
):
TPromise
<
ILink
[]
>
;
textualSuggest
(
resource
:
URI
,
position
:
IPosition
):
TPromise
<
ISuggestResult
[]
>
;
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
TPromise
<
IInplaceReplaceSupportResult
>
;
}
src/vs/editor/common/services/editorWorkerServiceImpl.ts
浏览文件 @
d9067043
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
IntervalTimer
,
ShallowCancelThenPromise
}
from
'
vs/base/common/async
'
;
import
{
IntervalTimer
,
ShallowCancelThenPromise
,
wireCancellationToken
}
from
'
vs/base/common/async
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -12,7 +12,7 @@ import {SimpleWorkerClient} from 'vs/base/common/worker/simpleWorker';
import
{
DefaultWorkerFactory
}
from
'
vs/base/worker/defaultWorkerFactory
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
WordHelper
}
from
'
vs/editor/common/model/textModelWithTokensHelpers
'
;
import
{
IInplaceReplaceSupportResult
,
ILink
,
ISuggestResult
}
from
'
vs/editor/common/modes
'
;
import
{
IInplaceReplaceSupportResult
,
ILink
,
ISuggestResult
,
LinkProviderRegistry
,
LinkProvider
}
from
'
vs/editor/common/modes
'
;
import
{
IEditorWorkerService
}
from
'
vs/editor/common/services/editorWorkerService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
EditorSimpleWorkerImpl
}
from
'
vs/editor/common/services/editorSimpleWorker
'
;
...
...
@@ -31,10 +31,23 @@ const STOP_WORKER_DELTA_TIME_MS = 5 * 60 * 1000;
export
class
EditorWorkerServiceImpl
implements
IEditorWorkerService
{
public
_serviceBrand
:
any
;
private
_workerManager
:
WorkerManager
;
private
_workerManager
:
WorkerManager
;
private
_registration
:
IDisposable
;
constructor
(@
IModelService
modelService
:
IModelService
)
{
this
.
_workerManager
=
new
WorkerManager
(
modelService
);
// todo@joh make sure this happens only once
this
.
_registration
=
LinkProviderRegistry
.
register
(
'
*
'
,
<
LinkProvider
>
{
provideLinks
:
(
model
,
token
)
=>
{
return
wireCancellationToken
(
token
,
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeLinks
(
model
.
uri
)));
}
});
}
public
dispose
():
void
{
this
.
_workerManager
.
dispose
();
this
.
_registration
.
dispose
();
}
public
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
TPromise
<
editorCommon
.
ILineChange
[]
>
{
...
...
@@ -45,10 +58,6 @@ export class EditorWorkerServiceImpl implements IEditorWorkerService {
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeDirtyDiff
(
original
,
modified
,
ignoreTrimWhitespace
));
}
public
computeLinks
(
resource
:
URI
):
TPromise
<
ILink
[]
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeLinks
(
resource
));
}
public
textualSuggest
(
resource
:
URI
,
position
:
editorCommon
.
IPosition
):
TPromise
<
ISuggestResult
[]
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
textualSuggest
(
resource
,
position
));
}
...
...
src/vs/editor/contrib/links/browser/links.ts
浏览文件 @
d9067043
...
...
@@ -16,7 +16,6 @@ import {TPromise} from 'vs/base/common/winjs.base';
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
IEditorService
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
EditorAction
}
from
'
vs/editor/common/editorAction
'
;
import
{
Behaviour
}
from
'
vs/editor/common/editorActionEnablement
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -75,16 +74,6 @@ class LinkOccurence {
}
}
class
Link
{
range
:
Range
;
url
:
string
;
constructor
(
source
:
ILink
)
{
this
.
range
=
new
Range
(
source
.
range
.
startLineNumber
,
source
.
range
.
startColumn
,
source
.
range
.
endLineNumber
,
source
.
range
.
endColumn
);
this
.
url
=
source
.
url
;
}
}
class
LinkDetector
implements
editorCommon
.
IEditorContribution
{
public
static
ID
:
string
=
'
editor.linkDetector
'
;
...
...
@@ -102,7 +91,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
private
editor
:
ICodeEditor
;
private
listenersToRemove
:
IDisposable
[];
private
timeoutPromise
:
TPromise
<
void
>
;
private
computePromise
:
TPromise
<
ILink
[]
>
;
private
computePromise
:
TPromise
<
void
>
;
private
activeLinkDecorationId
:
string
;
private
lastMouseEvent
:
IEditorMouseEvent
;
private
editorService
:
IEditorService
;
...
...
@@ -172,75 +161,16 @@ class LinkDetector implements editorCommon.IEditorContribution {
return
;
}
let
modePromise
:
TPromise
<
ILink
[]
>
=
TPromise
.
as
(
null
);
if
(
LinkProviderRegistry
.
has
(
this
.
editor
.
getModel
()))
{
modePromise
=
getLinks
(
this
.
editor
.
getModel
());
}
let
standardPromise
:
TPromise
<
ILink
[]
>
=
this
.
editorWorkerService
.
computeLinks
(
this
.
editor
.
getModel
().
uri
);
this
.
computePromise
=
TPromise
.
join
([
modePromise
,
standardPromise
]).
then
((
r
)
=>
{
let
a
=
r
[
0
];
let
b
=
r
[
1
];
if
(
!
a
||
a
.
length
===
0
)
{
return
b
||
[];
}
if
(
!
b
||
b
.
length
===
0
)
{
return
a
||
[];
if
(
!
LinkProviderRegistry
.
has
(
this
.
editor
.
getModel
()))
{
return
;
}
return
LinkDetector
.
_linksUnion
(
a
.
map
(
el
=>
new
Link
(
el
)),
b
.
map
(
el
=>
new
Link
(
el
)));
});
this
.
computePromise
.
then
((
links
:
ILink
[])
=>
{
this
.
computePromise
=
getLinks
(
this
.
editor
.
getModel
()).
then
(
links
=>
{
this
.
updateDecorations
(
links
);
this
.
computePromise
=
null
;
});
}
private
static
_linksUnion
(
oldLinks
:
Link
[],
newLinks
:
Link
[]):
Link
[]
{
// reunite oldLinks with newLinks and remove duplicates
var
result
:
Link
[]
=
[],
oldIndex
:
number
,
oldLen
:
number
,
newIndex
:
number
,
newLen
:
number
,
oldLink
:
Link
,
newLink
:
Link
,
comparisonResult
:
number
;
for
(
oldIndex
=
0
,
newIndex
=
0
,
oldLen
=
oldLinks
.
length
,
newLen
=
newLinks
.
length
;
oldIndex
<
oldLen
&&
newIndex
<
newLen
;)
{
oldLink
=
oldLinks
[
oldIndex
];
newLink
=
newLinks
[
newIndex
];
if
(
Range
.
areIntersectingOrTouching
(
oldLink
.
range
,
newLink
.
range
))
{
// Remove the oldLink
oldIndex
++
;
continue
;
}
comparisonResult
=
Range
.
compareRangesUsingStarts
(
oldLink
.
range
,
newLink
.
range
);
if
(
comparisonResult
<
0
)
{
// oldLink is before
result
.
push
(
oldLink
);
oldIndex
++
;
}
else
{
// newLink is before
result
.
push
(
newLink
);
newIndex
++
;
}
}
for
(;
oldIndex
<
oldLen
;
oldIndex
++
)
{
result
.
push
(
oldLinks
[
oldIndex
]);
}
for
(;
newIndex
<
newLen
;
newIndex
++
)
{
result
.
push
(
newLinks
[
newIndex
]);
}
return
result
;
}
private
updateDecorations
(
links
:
ILink
[]):
void
{
this
.
editor
.
changeDecorations
((
changeAccessor
:
editorCommon
.
IModelDecorationsChangeAccessor
)
=>
{
var
oldDecorations
:
string
[]
=
[];
...
...
src/vs/editor/contrib/links/common/links.ts
浏览文件 @
d9067043
...
...
@@ -6,32 +6,88 @@
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IReadOnlyModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ILink
,
LinkProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
export
function
getLinks
(
model
:
IReadOnlyModel
):
TPromise
<
ILink
[]
>
{
const
promises
=
LinkProviderRegistry
.
ordered
(
model
).
map
((
support
)
=>
{
return
asWinJsPromise
((
token
)
=>
{
return
support
.
provideLinks
(
model
,
token
);
}).
then
((
result
)
=>
{
let
links
:
ILink
[]
=
[];
// ask all providers for links in parallel
const
promises
=
LinkProviderRegistry
.
ordered
(
model
).
reverse
().
map
(
support
=>
{
return
asWinJsPromise
(
token
=>
support
.
provideLinks
(
model
,
token
)).
then
(
result
=>
{
if
(
Array
.
isArray
(
result
))
{
return
<
ILink
[]
>
result
;
links
=
union
(
links
,
result
)
;
}
},
err
=>
{
onUnexpectedError
(
err
);
},
onUnexpectedError
);
});
return
TPromise
.
join
(
promises
).
then
(()
=>
{
return
links
;
});
}
function
union
(
oldLinks
:
ILink
[],
newLinks
:
ILink
[]):
ILink
[]
{
// reunite oldLinks with newLinks and remove duplicates
var
result
:
ILink
[]
=
[],
oldIndex
:
number
,
oldLen
:
number
,
newIndex
:
number
,
newLen
:
number
,
oldLink
:
ILink
,
newLink
:
ILink
,
comparisonResult
:
number
;
for
(
oldIndex
=
0
,
newIndex
=
0
,
oldLen
=
oldLinks
.
length
,
newLen
=
newLinks
.
length
;
oldIndex
<
oldLen
&&
newIndex
<
newLen
;)
{
oldLink
=
oldLinks
[
oldIndex
];
newLink
=
newLinks
[
newIndex
];
return
TPromise
.
join
(
promises
).
then
(
manyLinks
=>
{
let
result
:
ILink
[]
=
[];
for
(
let
links
of
manyLinks
)
{
if
(
links
)
{
result
=
result
.
concat
(
links
);
if
(
Range
.
areIntersectingOrTouching
(
oldLink
.
range
,
newLink
.
range
))
{
// Remove the oldLink
oldIndex
++
;
continue
;
}
comparisonResult
=
Range
.
compareRangesUsingStarts
(
oldLink
.
range
,
newLink
.
range
);
if
(
comparisonResult
<
0
)
{
// oldLink is before
result
.
push
(
oldLink
);
oldIndex
++
;
}
else
{
// newLink is before
result
.
push
(
newLink
);
newIndex
++
;
}
}
for
(;
oldIndex
<
oldLen
;
oldIndex
++
)
{
result
.
push
(
oldLinks
[
oldIndex
]);
}
for
(;
newIndex
<
newLen
;
newIndex
++
)
{
result
.
push
(
newLinks
[
newIndex
]);
}
return
result
;
});
}
CommandsRegistry
.
registerCommand
(
'
_executeLinkProvider
'
,
(
accessor
,
...
args
)
=>
{
const
[
uri
]
=
args
;
if
(
!
(
uri
instanceof
URI
))
{
return
;
}
const
model
=
accessor
.
get
(
IModelService
).
getModel
(
uri
);
if
(
!
model
)
{
return
;
}
return
getLinks
(
model
);
});
\ No newline at end of file
src/vs/workbench/api/node/extHostApiCommands.ts
浏览文件 @
d9067043
...
...
@@ -147,7 +147,13 @@ class ExtHostApiCommands {
],
returns
:
'
A promise that resolves to an array of TextEdits.
'
});
this
.
_register
(
'
vscode.executeLinkProvider
'
,
this
.
_executeDocumentLinkProvider
,
{
description
:
'
Execute document link provider.
'
,
args
:
[
{
name
:
'
uri
'
,
description
:
'
Uri of a text document
'
,
constraint
:
URI
}
],
returns
:
'
A promise that resolves to an array of DocumentLink-instances.
'
});
this
.
_register
(
'
vscode.previewHtml
'
,
(
uri
:
URI
,
position
?:
vscode
.
ViewColumn
,
label
?:
string
)
=>
{
return
this
.
_commands
.
executeCommand
(
'
_workbench.previewHtml
'
,
...
...
@@ -417,4 +423,12 @@ class ExtHostApiCommands {
}
});
}
private
_executeDocumentLinkProvider
(
resource
:
URI
):
Thenable
<
vscode
.
DocumentLink
[]
>
{
return
this
.
_commands
.
executeCommand
<
modes
.
ILink
[]
>
(
'
_executeLinkProvider
'
,
resource
).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
typeConverters
.
DocumentLink
.
to
);
}
});
}
}
src/vs/workbench/test/node/api/extHostApiCommands.test.ts
浏览文件 @
d9067043
...
...
@@ -401,4 +401,26 @@ suite('ExtHostLanguageFeatureCommands', function() {
});
});
});
test
(
'
Links, back and forth
'
,
function
()
{
disposables
.
push
(
extHost
.
registerDocumentLinkProvider
(
defaultSelector
,
<
vscode
.
DocumentLinkProvider
>
{
provideDocumentLinks
():
any
{
return
[
new
types
.
DocumentLink
(
new
types
.
Range
(
0
,
0
,
0
,
20
),
URI
.
parse
(
'
foo:bar
'
))];
}
}));
return
threadService
.
sync
().
then
(()
=>
{
return
commands
.
executeCommand
<
vscode
.
DocumentLink
[]
>
(
'
vscode.executeLinkProvider
'
,
model
.
uri
).
then
(
value
=>
{
assert
.
equal
(
value
.
length
,
1
);
let
[
first
]
=
value
;
assert
.
equal
(
first
.
target
.
toString
(),
'
foo:bar
'
);
assert
.
equal
(
first
.
range
.
start
.
line
,
0
);
assert
.
equal
(
first
.
range
.
start
.
character
,
0
);
assert
.
equal
(
first
.
range
.
end
.
line
,
0
);
assert
.
equal
(
first
.
range
.
end
.
character
,
20
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录