Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fcc508fd
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,发现更多精彩内容 >>
提交
fcc508fd
编写于
3月 07, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DocumentSelector matches on file and untitled only unless scheme is given, #21886
上级
3ae62a8d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
39 deletion
+86
-39
src/vs/editor/common/modes/languageSelector.ts
src/vs/editor/common/modes/languageSelector.ts
+57
-33
src/vs/editor/contrib/quickFix/test/common/quickFixModel.test.ts
...editor/contrib/quickFix/test/common/quickFixModel.test.ts
+1
-1
src/vs/editor/contrib/suggest/test/common/suggest.test.ts
src/vs/editor/contrib/suggest/test/common/suggest.test.ts
+2
-2
src/vs/editor/test/common/modes/languageSelector.test.ts
src/vs/editor/test/common/modes/languageSelector.test.ts
+26
-3
未找到文件。
src/vs/editor/common/modes/languageSelector.ts
浏览文件 @
fcc508fd
...
...
@@ -20,62 +20,86 @@ export default function matches(selection: LanguageSelector, uri: URI, language:
return
score
(
selection
,
uri
,
language
)
>
0
;
}
export
function
score
(
selector
:
LanguageSelector
,
uri
:
URI
,
l
anguage
:
string
):
number
{
export
function
score
(
selector
:
LanguageSelector
,
candidateUri
:
URI
,
candidateL
anguage
:
string
):
number
{
if
(
Array
.
isArray
(
selector
))
{
// for each
let
values
=
(
<
LanguageSelector
[]
>
selector
).
map
(
item
=>
score
(
item
,
uri
,
language
));
return
Math
.
max
(...
values
);
// array -> take max individual value
let
ret
=
0
;
for
(
const
filter
of
selector
)
{
const
value
=
score
(
filter
,
candidateUri
,
candidateLanguage
);
if
(
value
===
10
)
{
return
value
;
// already at the highest
}
if
(
value
>
ret
)
{
ret
=
value
;
}
}
return
ret
;
}
else
if
(
typeof
selector
===
'
string
'
)
{
//
compare language id
if
(
selector
===
language
)
{
return
10
;
}
else
if
(
selector
===
'
*
'
)
{
//
short-hand notion, desugars to
// 'fooLang' -> [{ language: 'fooLang', scheme: 'file' }, { language: 'fooLang', scheme: 'untitled' }]
// '*' -> { language: '*', scheme: '*' }
if
(
selector
===
'
*
'
)
{
return
5
;
}
else
if
(
selector
===
candidateLanguage
&&
_defaultSchemes
[
candidateUri
.
scheme
])
{
return
10
;
}
else
{
return
0
;
}
}
else
if
(
selector
)
{
// all must match but only highest score counts
const
filter
=
<
LanguageFilter
>
selector
;
let
valueLanguage
=
0
;
let
valueScheme
=
0
;
let
valuePattern
=
0
;
// language id
if
(
filter
.
language
)
{
if
(
filter
.
language
===
language
)
{
valueLanguage
=
10
;
}
else
if
(
filter
.
language
===
'
*
'
)
{
valueLanguage
=
5
;
// filter -> select accordingly, use defaults for scheme
const
{
language
,
pattern
,
scheme
}
=
selector
;
let
ret
=
0
;
if
(
scheme
)
{
if
(
scheme
===
candidateUri
.
scheme
)
{
ret
=
10
;
}
else
if
(
scheme
===
'
*
'
)
{
ret
=
5
;
}
else
{
return
0
;
}
}
// scheme
if
(
filter
.
scheme
)
{
if
(
filter
.
scheme
===
uri
.
scheme
)
{
valueScheme
=
10
;
if
(
language
)
{
if
(
language
===
candidateLanguage
)
{
ret
=
10
;
}
else
if
(
language
===
'
*
'
)
{
ret
=
Math
.
max
(
ret
,
5
);
}
else
{
return
0
;
}
}
// match fsPath with pattern
if
(
filter
.
pattern
)
{
if
(
filter
.
pattern
===
uri
.
fsPath
)
{
valuePattern
=
10
;
}
else
if
(
matchGlobPattern
(
filter
.
pattern
,
uri
.
fsPath
))
{
valuePattern
=
5
;
if
(
pattern
)
{
if
(
pattern
===
candidateUri
.
fsPath
||
matchGlobPattern
(
pattern
,
candidateUri
.
fsPath
))
{
ret
=
10
;
}
else
{
return
0
;
}
}
return
Math
.
max
(
valueLanguage
,
valueScheme
,
valuePattern
);
if
(
!
_defaultSchemes
[
candidateUri
.
scheme
]
&&
!
scheme
&&
language
!==
'
*
'
)
{
// undo match when the uri-scheme is special and not
// explicitly selected
return
0
;
}
else
{
return
ret
;
}
}
else
{
return
undefined
;
}
return
undefined
;
}
interface
DefaultSchemes
{
file
:
'
file
'
;
untitled
:
'
untitled
'
;
}
const
_defaultSchemes
:
DefaultSchemes
=
Object
.
create
(
null
);
_defaultSchemes
.
file
=
'
file
'
;
_defaultSchemes
.
untitled
=
'
untitled
'
;
src/vs/editor/contrib/quickFix/test/common/quickFixModel.test.ts
浏览文件 @
fcc508fd
...
...
@@ -18,7 +18,7 @@ import { CodeActionProviderRegistry, LanguageIdentifier } from 'vs/editor/common
suite
(
'
QuickFix
'
,
()
=>
{
const
languageIdentifier
=
new
LanguageIdentifier
(
'
foo-lang
'
,
3
);
let
uri
=
URI
.
parse
(
'
fake
:path
'
);
let
uri
=
URI
.
parse
(
'
untitled
:path
'
);
let
model
=
Model
.
createFromString
(
'
foobar foo bar
\n
farboo far boo
'
,
undefined
,
languageIdentifier
,
uri
);
let
markerService
:
MarkerService
;
let
editor
:
ICommonCodeEditor
;
...
...
src/vs/editor/contrib/suggest/test/common/suggest.test.ts
浏览文件 @
fcc508fd
...
...
@@ -21,7 +21,7 @@ suite('Suggest', function () {
setup
(
function
()
{
model
=
Model
.
createFromString
(
'
FOO
\n
bar
\
BAR
\n
foo
'
,
undefined
,
undefined
,
URI
.
parse
(
'
foo:bar/path
'
));
registration
=
SuggestRegistry
.
register
({
pattern
:
'
bar/path
'
},
{
registration
=
SuggestRegistry
.
register
({
pattern
:
'
bar/path
'
,
scheme
:
'
foo
'
},
{
provideCompletionItems
()
{
return
{
incomplete
:
false
,
...
...
@@ -98,7 +98,7 @@ suite('Suggest', function () {
};
}
};
const
registration
=
SuggestRegistry
.
register
({
pattern
:
'
bar/path
'
},
foo
);
const
registration
=
SuggestRegistry
.
register
({
pattern
:
'
bar/path
'
,
scheme
:
'
foo
'
},
foo
);
provideSuggestionItems
(
model
,
new
Position
(
1
,
1
),
undefined
,
[
foo
]).
then
(
items
=>
{
registration
.
dispose
();
...
...
src/vs/editor/test/common/modes/languageSelector.test.ts
浏览文件 @
fcc508fd
...
...
@@ -26,6 +26,26 @@ suite('LanguageSelector', function () {
test
(
'
score, any language
'
,
function
()
{
assert
.
equal
(
score
({
language
:
'
*
'
},
model
.
uri
,
model
.
language
),
5
);
assert
.
equal
(
score
(
'
*
'
,
model
.
uri
,
model
.
language
),
5
);
assert
.
equal
(
score
(
'
*
'
,
URI
.
parse
(
'
foo:bar
'
),
model
.
language
),
5
);
assert
.
equal
(
score
(
'
farboo
'
,
URI
.
parse
(
'
foo:bar
'
),
model
.
language
),
0
);
});
test
(
'
score, default schemes
'
,
function
()
{
const
uri
=
URI
.
parse
(
'
git:foo/file.txt
'
);
const
language
=
'
farboo
'
;
assert
.
equal
(
score
(
'
*
'
,
uri
,
language
),
5
);
assert
.
equal
(
score
(
'
farboo
'
,
uri
,
language
),
0
);
assert
.
equal
(
score
({
language
:
'
farboo
'
,
scheme
:
''
},
uri
,
language
),
0
);
assert
.
equal
(
score
({
language
:
'
farboo
'
,
scheme
:
'
git
'
},
uri
,
language
),
10
);
assert
.
equal
(
score
({
language
:
'
farboo
'
,
scheme
:
'
*
'
},
uri
,
language
),
10
);
assert
.
equal
(
score
({
language
:
'
farboo
'
},
uri
,
language
),
0
);
assert
.
equal
(
score
({
language
:
'
*
'
},
uri
,
language
),
5
);
assert
.
equal
(
score
({
scheme
:
'
*
'
},
uri
,
language
),
5
);
assert
.
equal
(
score
({
scheme
:
'
git
'
},
uri
,
language
),
10
);
});
test
(
'
score, filter
'
,
function
()
{
...
...
@@ -34,8 +54,10 @@ suite('LanguageSelector', function () {
assert
.
equal
(
score
({
language
:
'
farboo
'
,
scheme
:
'
file
'
},
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
({
language
:
'
farboo
'
,
scheme
:
'
http
'
},
model
.
uri
,
model
.
language
),
0
);
assert
.
equal
(
score
({
pattern
:
'
**/*.fb
'
},
model
.
uri
,
model
.
language
),
5
);
// assert.equal(score({ pattern: '/testbed/file.fb' }, model.uri, model.language), 10); fails on windows
assert
.
equal
(
score
({
pattern
:
'
**/*.fb
'
},
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
({
pattern
:
'
**/*.fb
'
,
scheme
:
'
file
'
},
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
({
pattern
:
'
**/*.fb
'
},
URI
.
parse
(
'
foo:bar
'
),
model
.
language
),
0
);
assert
.
equal
(
score
({
pattern
:
'
**/*.fb
'
,
scheme
:
'
foo
'
},
URI
.
parse
(
'
foo:bar
'
),
model
.
language
),
0
);
});
test
(
'
score, max(filters)
'
,
function
()
{
...
...
@@ -45,7 +67,8 @@ suite('LanguageSelector', function () {
assert
.
equal
(
score
(
match
,
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
(
fail
,
model
.
uri
,
model
.
language
),
0
);
assert
.
equal
(
score
([
match
,
fail
],
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
([
fail
,
fail
],
model
.
uri
,
model
.
language
),
0
);
assert
.
equal
(
score
([
'
farboo
'
,
'
*
'
],
model
.
uri
,
model
.
language
),
10
);
assert
.
equal
(
score
([
'
*
'
,
'
farboo
'
],
model
.
uri
,
model
.
language
),
10
);
});
});
\ No newline at end of file
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录