Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4ac76090
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,发现更多精彩内容 >>
提交
4ac76090
编写于
11月 15, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use state machine for link detection, #62800
上级
6e9070f5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
35 deletion
+83
-35
src/vs/editor/common/modes/linkComputer.ts
src/vs/editor/common/modes/linkComputer.ts
+7
-7
src/vs/workbench/api/node/extHostFileSystem.ts
src/vs/workbench/api/node/extHostFileSystem.ts
+76
-28
未找到文件。
src/vs/editor/common/modes/linkComputer.ts
浏览文件 @
4ac76090
...
...
@@ -13,7 +13,7 @@ export interface ILinkComputerTarget {
getLineContent
(
lineNumber
:
number
):
string
;
}
const
enum
State
{
export
const
enum
State
{
Invalid
=
0
,
Start
=
1
,
H
=
2
,
...
...
@@ -27,12 +27,13 @@ const enum State {
AfterColon
=
10
,
AlmostThere
=
11
,
End
=
12
,
Accept
=
13
Accept
=
13
,
LastKnownState
=
14
// marker, custom states may follow
}
type
Edge
=
[
State
,
number
,
State
];
export
type
Edge
=
[
State
,
number
,
State
];
class
StateMachine
{
export
class
StateMachine
{
private
_states
:
Uint8Matrix
;
private
_maxCharCode
:
number
;
...
...
@@ -141,7 +142,7 @@ function getClassifier(): CharacterClassifier<CharacterClass> {
return
_classifier
;
}
class
LinkComputer
{
export
class
LinkComputer
{
private
static
_createLink
(
classifier
:
CharacterClassifier
<
CharacterClass
>
,
line
:
string
,
lineNumber
:
number
,
linkBeginIndex
:
number
,
linkEndIndex
:
number
):
ILink
{
// Do not allow to end link in certain characters...
...
...
@@ -183,8 +184,7 @@ class LinkComputer {
};
}
public
static
computeLinks
(
model
:
ILinkComputerTarget
):
ILink
[]
{
const
stateMachine
=
getStateMachine
();
public
static
computeLinks
(
model
:
ILinkComputerTarget
,
stateMachine
:
StateMachine
=
getStateMachine
()):
ILink
[]
{
const
classifier
=
getClassifier
();
let
result
:
ILink
[]
=
[];
...
...
src/vs/workbench/api/node/extHostFileSystem.ts
浏览文件 @
4ac76090
...
...
@@ -8,48 +8,96 @@ import { MainContext, IMainContext, ExtHostFileSystemShape, MainThreadFileSystem
import
*
as
vscode
from
'
vscode
'
;
import
*
as
files
from
'
vs/platform/files/common/files
'
;
import
{
IDisposable
,
toDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
Range
,
FileChangeType
}
from
'
vs/workbench/api/node/extHostType
s
'
;
import
{
FileChangeType
,
DocumentLink
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
*
as
typeConverter
from
'
vs/workbench/api/node/extHostTypeConverter
s
'
;
import
{
ExtHostLanguageFeatures
}
from
'
vs/workbench/api/node/extHostLanguageFeatures
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
LabelRules
}
from
'
vs/platform/label/common/label
'
;
import
{
State
,
StateMachine
,
LinkComputer
}
from
'
vs/editor/common/modes/linkComputer
'
;
import
{
commonPrefixLength
}
from
'
vs/base/common/strings
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
class
FsLinkProvider
implements
vscode
.
DocumentLinkProvider
{
class
FsLinkProvider
{
private
_schemes
=
new
Set
<
string
>
()
;
private
_
regex
:
RegExp
;
private
_schemes
:
string
[]
=
[]
;
private
_
stateMachine
:
StateMachine
;
add
(
scheme
:
string
):
void
{
this
.
_
regex
=
undefined
;
this
.
_schemes
.
add
(
scheme
);
this
.
_
stateMachine
=
undefined
;
this
.
_schemes
.
push
(
scheme
);
}
delete
(
scheme
:
string
):
void
{
if
(
this
.
_schemes
.
delete
(
scheme
))
{
this
.
_regex
=
undefined
;
let
idx
=
this
.
_schemes
.
indexOf
(
scheme
);
if
(
idx
>=
0
)
{
this
.
_schemes
.
splice
(
idx
,
1
);
}
}
provideDocumentLinks
(
document
:
vscode
.
TextDocument
):
vscode
.
ProviderResult
<
vscode
.
DocumentLink
[]
>
{
if
(
this
.
_schemes
.
size
===
0
)
{
return
undefined
;
}
if
(
!
this
.
_regex
)
{
this
.
_regex
=
new
RegExp
(
`(
${(
values
(
this
.
_schemes
).
join
(
'
|
'
))}
):[^\\s"']+`
,
'
gi
'
);
}
let
result
:
vscode
.
DocumentLink
[]
=
[];
let
max
=
Math
.
min
(
document
.
lineCount
,
2500
);
for
(
let
line
=
0
;
line
<
max
;
line
++
)
{
this
.
_regex
.
lastIndex
=
0
;
let
textLine
=
document
.
lineAt
(
line
);
let
m
:
RegExpMatchArray
;
while
(
m
=
this
.
_regex
.
exec
(
textLine
.
text
))
{
const
target
=
URI
.
parse
(
m
[
0
]);
if
(
target
.
path
[
0
]
!==
'
/
'
)
{
continue
;
private
_initStateMachine
():
void
{
if
(
!
this
.
_stateMachine
)
{
// sort and compute common prefix with previous scheme
// then build state transitions based on the data
const
schemes
=
this
.
_schemes
.
sort
();
const
edges
=
[];
let
prevScheme
:
string
;
let
prevState
:
State
;
let
nextState
=
State
.
LastKnownState
;
for
(
const
scheme
of
schemes
)
{
// skip the common prefix of the prev scheme
// and continue with its last state
let
pos
=
!
prevScheme
?
0
:
commonPrefixLength
(
prevScheme
,
scheme
);
if
(
pos
===
0
)
{
prevState
=
State
.
Start
;
}
else
{
prevState
=
nextState
;
}
const
range
=
new
Range
(
line
,
this
.
_regex
.
lastIndex
-
m
[
0
].
length
,
line
,
this
.
_regex
.
lastIndex
);
result
.
push
({
target
,
range
});
for
(;
pos
<
scheme
.
length
;
pos
++
)
{
// keep creating new (next) states until the
// end (and the BeforeColon-state) is reached
if
(
pos
+
1
===
scheme
.
length
)
{
nextState
=
State
.
BeforeColon
;
}
else
{
nextState
+=
1
;
}
edges
.
push
([
prevState
,
scheme
.
toUpperCase
().
charCodeAt
(
pos
),
nextState
]);
edges
.
push
([
prevState
,
scheme
.
toLowerCase
().
charCodeAt
(
pos
),
nextState
]);
prevState
=
nextState
;
}
prevScheme
=
scheme
;
}
// all link must match this pattern `<scheme>:/<more>`
edges
.
push
([
State
.
BeforeColon
,
CharCode
.
Colon
,
State
.
AfterColon
]);
edges
.
push
([
State
.
AfterColon
,
CharCode
.
Slash
,
State
.
End
]);
this
.
_stateMachine
=
new
StateMachine
(
edges
);
}
}
provideDocumentLinks
(
document
:
vscode
.
TextDocument
):
vscode
.
ProviderResult
<
vscode
.
DocumentLink
[]
>
{
this
.
_initStateMachine
();
const
result
:
vscode
.
DocumentLink
[]
=
[];
const
links
=
LinkComputer
.
computeLinks
({
getLineContent
(
lineNumber
:
number
):
string
{
return
document
.
lineAt
(
lineNumber
-
1
).
text
;
},
getLineCount
():
number
{
return
document
.
lineCount
;
}
},
this
.
_stateMachine
);
for
(
const
link
of
links
)
{
try
{
let
uri
=
URI
.
parse
(
link
.
url
,
true
);
result
.
push
(
new
DocumentLink
(
typeConverter
.
Range
.
to
(
link
.
range
),
uri
));
}
catch
(
err
)
{
// ignore
}
}
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录