Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d7dfd53d
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,发现更多精彩内容 >>
提交
d7dfd53d
编写于
12月 22, 2015
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inline outputworker
上级
243a900a
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
199 addition
and
210 deletion
+199
-210
src/vs/workbench/common/textEditorWorker.ts
src/vs/workbench/common/textEditorWorker.ts
+0
-146
src/vs/workbench/parts/output/common/outputWorker.ts
src/vs/workbench/parts/output/common/outputWorker.ts
+137
-2
src/vs/workbench/parts/output/test/outputWorker.test.ts
src/vs/workbench/parts/output/test/outputWorker.test.ts
+62
-62
未找到文件。
src/vs/workbench/common/textEditorWorker.ts
已删除
100644 → 0
浏览文件 @
243a900a
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IMarkerService
}
from
'
vs/platform/markers/common/markers
'
;
import
{
IResourceService
}
from
'
vs/editor/common/services/resourceService
'
;
import
{
AbstractModeWorker
}
from
'
vs/editor/common/modes/abstractModeWorker
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
arrays
=
require
(
'
vs/base/common/arrays
'
);
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
ILink
,
IMode
,
IWorkerParticipant
}
from
'
vs/editor/common/modes
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IWorkspaceContextService
,
IWorkspace
}
from
'
vs/platform/workspace/common/workspace
'
;
/**
* A base class of text editor worker that helps with detecting links in the text that point to files in the workspace.
*/
export
class
TextEditorWorker
extends
AbstractModeWorker
{
private
_contextService
:
IWorkspaceContextService
;
private
patterns
:
RegExp
[];
constructor
(
mode
:
IMode
,
participants
:
IWorkerParticipant
[],
@
IResourceService
resourceService
:
IResourceService
,
@
IMarkerService
markerService
:
IMarkerService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
)
{
super
(
mode
,
participants
,
resourceService
,
markerService
);
this
.
_contextService
=
contextService
;
let
workspace
=
this
.
_contextService
.
getWorkspace
();
this
.
patterns
=
workspace
?
TextEditorWorker
.
createPatterns
(
workspace
)
:
[];
}
public
get
contextService
():
IWorkspaceContextService
{
return
this
.
_contextService
;
}
public
computeLinks
(
resource
:
URI
):
TPromise
<
ILink
[]
>
{
return
super
.
computeLinks
(
resource
).
then
((
links
)
=>
{
if
(
!
this
.
patterns
.
length
)
{
return
links
;
}
let
model
=
this
.
resourceService
.
get
(
resource
);
for
(
let
i
=
1
,
lineCount
=
model
.
getLineCount
();
i
<=
lineCount
;
i
++
)
{
links
.
push
(...
TextEditorWorker
.
detectLinks
(
model
.
getLineContent
(
i
),
i
,
this
.
patterns
,
this
.
_contextService
));
}
return
links
;
});
}
public
static
createPatterns
(
workspace
:
IWorkspace
):
RegExp
[]
{
let
patterns
:
RegExp
[]
=
[];
let
workspaceRootVariants
=
arrays
.
distinct
([
paths
.
normalize
(
workspace
.
resource
.
fsPath
,
true
),
paths
.
normalize
(
workspace
.
resource
.
fsPath
,
false
)
]);
workspaceRootVariants
.
forEach
((
workspaceRoot
)
=>
{
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\express\server.js on line 8, column 13
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
(
\\
S*) on line ((
\\
d+)(, column (
\\
d+))?)
'
,
'
gi
'
));
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\express\server.js:line 8, column 13
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
(
\\
S*):line ((
\\
d+)(, column (
\\
d+))?)
'
,
'
gi
'
));
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts(45): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts (45): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts(45,18): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts (45,18): error
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
([^
\\
s
\\
(
\\
)]*)(
\\
s?
\\
((
\\
d+)(,(
\\
d+))?)
\\
)
'
,
'
gi
'
));
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts:336
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts:336:9
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
([^:
\\
s
\\
(
\\
)<>
\'\
"
\\
[
\\
]]*)(:(
\\
d+))?(:(
\\
d+))?
'
,
'
gi
'
));
});
return
patterns
;
}
/**
* Detect links. Made public static to allow for tests.
*/
public
static
detectLinks
(
line
:
string
,
lineIndex
:
number
,
patterns
:
RegExp
[],
contextService
:
IWorkspaceContextService
):
ILink
[]
{
let
links
:
ILink
[]
=
[];
patterns
.
forEach
((
pattern
)
=>
{
pattern
.
lastIndex
=
0
;
// the holy grail of software development
let
match
:
RegExpExecArray
;
let
offset
=
0
;
while
((
match
=
pattern
.
exec
(
line
))
!==
null
)
{
// Convert the relative path information to a resource that we can use in links
let
workspaceRelativePath
=
strings
.
replaceAll
(
strings
.
rtrim
(
match
[
1
],
'
.
'
),
'
\\
'
,
'
/
'
);
// remove trailing "." that likely indicate end of sentence
let
resource
:
string
;
try
{
resource
=
contextService
.
toResource
(
workspaceRelativePath
).
toString
();
}
catch
(
error
)
{
continue
;
// we might find an invalid URI and then we dont want to loose all other links
}
// Append line/col information to URI if matching
if
(
match
[
3
])
{
let
lineNumber
=
match
[
3
];
if
(
match
[
5
])
{
let
columnNumber
=
match
[
5
];
resource
=
strings
.
format
(
'
{0}#{1},{2}
'
,
resource
,
lineNumber
,
columnNumber
);
}
else
{
resource
=
strings
.
format
(
'
{0}#{1}
'
,
resource
,
lineNumber
);
}
}
let
fullMatch
=
strings
.
rtrim
(
match
[
0
],
'
.
'
);
// remove trailing "." that likely indicate end of sentence
let
index
=
line
.
indexOf
(
fullMatch
,
offset
);
offset
+=
index
+
fullMatch
.
length
;
var
linkRange
=
{
startColumn
:
index
+
1
,
startLineNumber
:
lineIndex
,
endColumn
:
index
+
1
+
fullMatch
.
length
,
endLineNumber
:
lineIndex
};
if
(
links
.
some
((
link
)
=>
Range
.
areIntersectingOrTouching
(
link
.
range
,
linkRange
)))
{
return
;
// Do not detect duplicate links
}
links
.
push
({
range
:
linkRange
,
url
:
resource
});
}
});
return
links
;
}
}
\ No newline at end of file
src/vs/workbench/parts/output/common/outputWorker.ts
浏览文件 @
d7dfd53d
...
...
@@ -4,8 +4,143 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TextEditorWorker
}
from
'
vs/workbench/common/textEditorWorker
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IMarkerService
}
from
'
vs/platform/markers/common/markers
'
;
import
{
IResourceService
}
from
'
vs/editor/common/services/resourceService
'
;
import
{
AbstractModeWorker
}
from
'
vs/editor/common/modes/abstractModeWorker
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
arrays
=
require
(
'
vs/base/common/arrays
'
);
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
ILink
,
IMode
,
IWorkerParticipant
}
from
'
vs/editor/common/modes
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IWorkspaceContextService
,
IWorkspace
}
from
'
vs/platform/workspace/common/workspace
'
;
export
class
OutputWorker
extends
TextEditorWorker
{
/**
* A base class of text editor worker that helps with detecting links in the text that point to files in the workspace.
*/
export
class
OutputWorker
extends
AbstractModeWorker
{
private
_contextService
:
IWorkspaceContextService
;
private
patterns
:
RegExp
[];
constructor
(
mode
:
IMode
,
participants
:
IWorkerParticipant
[],
@
IResourceService
resourceService
:
IResourceService
,
@
IMarkerService
markerService
:
IMarkerService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
)
{
super
(
mode
,
participants
,
resourceService
,
markerService
);
this
.
_contextService
=
contextService
;
let
workspace
=
this
.
_contextService
.
getWorkspace
();
this
.
patterns
=
workspace
?
OutputWorker
.
createPatterns
(
workspace
)
:
[];
}
public
get
contextService
():
IWorkspaceContextService
{
return
this
.
_contextService
;
}
public
computeLinks
(
resource
:
URI
):
TPromise
<
ILink
[]
>
{
return
super
.
computeLinks
(
resource
).
then
((
links
)
=>
{
if
(
!
this
.
patterns
.
length
)
{
return
links
;
}
let
model
=
this
.
resourceService
.
get
(
resource
);
for
(
let
i
=
1
,
lineCount
=
model
.
getLineCount
();
i
<=
lineCount
;
i
++
)
{
links
.
push
(...
OutputWorker
.
detectLinks
(
model
.
getLineContent
(
i
),
i
,
this
.
patterns
,
this
.
_contextService
));
}
return
links
;
});
}
public
static
createPatterns
(
workspace
:
IWorkspace
):
RegExp
[]
{
let
patterns
:
RegExp
[]
=
[];
let
workspaceRootVariants
=
arrays
.
distinct
([
paths
.
normalize
(
workspace
.
resource
.
fsPath
,
true
),
paths
.
normalize
(
workspace
.
resource
.
fsPath
,
false
)
]);
workspaceRootVariants
.
forEach
((
workspaceRoot
)
=>
{
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\express\server.js on line 8, column 13
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
(
\\
S*) on line ((
\\
d+)(, column (
\\
d+))?)
'
,
'
gi
'
));
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\express\server.js:line 8, column 13
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
(
\\
S*):line ((
\\
d+)(, column (
\\
d+))?)
'
,
'
gi
'
));
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts(45): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts (45): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts(45,18): error
// Example: C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Features.ts (45,18): error
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
([^
\\
s
\\
(
\\
)]*)(
\\
s?
\\
((
\\
d+)(,(
\\
d+))?)
\\
)
'
,
'
gi
'
));
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts:336
// Example: at C:\Users\someone\AppData\Local\Temp\_monacodata_9888\workspaces\mankala\Game.ts:336:9
patterns
.
push
(
new
RegExp
(
strings
.
escapeRegExpCharacters
(
workspaceRoot
)
+
'
([^:
\\
s
\\
(
\\
)<>
\'\
"
\\
[
\\
]]*)(:(
\\
d+))?(:(
\\
d+))?
'
,
'
gi
'
));
});
return
patterns
;
}
/**
* Detect links. Made public static to allow for tests.
*/
public
static
detectLinks
(
line
:
string
,
lineIndex
:
number
,
patterns
:
RegExp
[],
contextService
:
IWorkspaceContextService
):
ILink
[]
{
let
links
:
ILink
[]
=
[];
patterns
.
forEach
((
pattern
)
=>
{
pattern
.
lastIndex
=
0
;
// the holy grail of software development
let
match
:
RegExpExecArray
;
let
offset
=
0
;
while
((
match
=
pattern
.
exec
(
line
))
!==
null
)
{
// Convert the relative path information to a resource that we can use in links
let
workspaceRelativePath
=
strings
.
replaceAll
(
strings
.
rtrim
(
match
[
1
],
'
.
'
),
'
\\
'
,
'
/
'
);
// remove trailing "." that likely indicate end of sentence
let
resource
:
string
;
try
{
resource
=
contextService
.
toResource
(
workspaceRelativePath
).
toString
();
}
catch
(
error
)
{
continue
;
// we might find an invalid URI and then we dont want to loose all other links
}
// Append line/col information to URI if matching
if
(
match
[
3
])
{
let
lineNumber
=
match
[
3
];
if
(
match
[
5
])
{
let
columnNumber
=
match
[
5
];
resource
=
strings
.
format
(
'
{0}#{1},{2}
'
,
resource
,
lineNumber
,
columnNumber
);
}
else
{
resource
=
strings
.
format
(
'
{0}#{1}
'
,
resource
,
lineNumber
);
}
}
let
fullMatch
=
strings
.
rtrim
(
match
[
0
],
'
.
'
);
// remove trailing "." that likely indicate end of sentence
let
index
=
line
.
indexOf
(
fullMatch
,
offset
);
offset
+=
index
+
fullMatch
.
length
;
var
linkRange
=
{
startColumn
:
index
+
1
,
startLineNumber
:
lineIndex
,
endColumn
:
index
+
1
+
fullMatch
.
length
,
endLineNumber
:
lineIndex
};
if
(
links
.
some
((
link
)
=>
Range
.
areIntersectingOrTouching
(
link
.
range
,
linkRange
)))
{
return
;
// Do not detect duplicate links
}
links
.
push
({
range
:
linkRange
,
url
:
resource
});
}
});
return
links
;
}
}
\ No newline at end of file
src/vs/workbench/
test/browser/parts/editor/textEditor
Worker.test.ts
→
src/vs/workbench/
parts/output/test/output
Worker.test.ts
浏览文件 @
d7dfd53d
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录