Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0c50806e
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,发现更多精彩内容 >>
提交
0c50806e
编写于
10月 19, 2020
作者:
R
Raymond Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Emmet abbrevationAction files
上级
2c53d687
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
75 addition
and
75 deletion
+75
-75
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+21
-21
extensions/emmet/src/test/abbreviationAction.test.ts
extensions/emmet/src/test/abbreviationAction.test.ts
+54
-54
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
0c50806e
...
...
@@ -66,7 +66,7 @@ function doWrapping(individualLines: boolean, args: any) {
const
helper
=
getEmmetHelper
();
// Fetch general information for the succesive expansions. i.e. the ranges to replace and its contents
le
t
rangesToReplace
:
PreviewRangesWithContent
[]
=
editor
.
selections
.
sort
((
a
:
vscode
.
Selection
,
b
:
vscode
.
Selection
)
=>
{
return
a
.
start
.
compareTo
(
b
.
start
);
}).
map
(
selection
=>
{
cons
t
rangesToReplace
:
PreviewRangesWithContent
[]
=
editor
.
selections
.
sort
((
a
:
vscode
.
Selection
,
b
:
vscode
.
Selection
)
=>
{
return
a
.
start
.
compareTo
(
b
.
start
);
}).
map
(
selection
=>
{
let
rangeToReplace
:
vscode
.
Range
=
selection
.
isReversed
?
new
vscode
.
Range
(
selection
.
active
,
selection
.
anchor
)
:
selection
;
if
(
!
rangeToReplace
.
isSingleLine
&&
rangeToReplace
.
end
.
character
===
0
)
{
const
previousLine
=
rangeToReplace
.
end
.
line
-
1
;
...
...
@@ -88,7 +88,7 @@ function doWrapping(individualLines: boolean, args: any) {
rangeToReplace
=
new
vscode
.
Range
(
rangeToReplace
.
start
.
line
,
rangeToReplace
.
start
.
character
+
extraWhitespaceSelected
,
rangeToReplace
.
end
.
line
,
rangeToReplace
.
end
.
character
);
let
textToWrapInPreview
:
string
[];
le
t
textToReplace
=
editor
.
document
.
getText
(
rangeToReplace
);
cons
t
textToReplace
=
editor
.
document
.
getText
(
rangeToReplace
);
if
(
individualLines
)
{
textToWrapInPreview
=
textToReplace
.
split
(
'
\n
'
).
map
(
x
=>
x
.
trim
());
}
else
{
...
...
@@ -144,7 +144,7 @@ function doWrapping(individualLines: boolean, args: any) {
const
oldPreviewLines
=
oldPreviewRange
.
end
.
line
-
oldPreviewRange
.
start
.
line
+
1
;
const
newLinesInserted
=
expandedTextLines
.
length
-
oldPreviewLines
;
le
t
newPreviewLineStart
=
oldPreviewRange
.
start
.
line
+
totalLinesInserted
;
cons
t
newPreviewLineStart
=
oldPreviewRange
.
start
.
line
+
totalLinesInserted
;
let
newPreviewStart
=
oldPreviewRange
.
start
.
character
;
const
newPreviewLineEnd
=
oldPreviewRange
.
end
.
line
+
totalLinesInserted
+
newLinesInserted
;
let
newPreviewEnd
=
expandedTextLines
[
expandedTextLines
.
length
-
1
].
length
;
...
...
@@ -177,19 +177,19 @@ function doWrapping(individualLines: boolean, args: any) {
return
inPreview
?
revertPreview
().
then
(()
=>
{
return
false
;
})
:
Promise
.
resolve
(
inPreview
);
}
le
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
inputAbbreviation
);
cons
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
inputAbbreviation
);
if
(
!
extractedResults
)
{
return
Promise
.
resolve
(
inPreview
);
}
else
if
(
extractedResults
.
abbreviation
!==
inputAbbreviation
)
{
// Not clear what should we do in this case. Warn the user? How?
}
le
t
{
abbreviation
,
filter
}
=
extractedResults
;
cons
t
{
abbreviation
,
filter
}
=
extractedResults
;
if
(
definitive
)
{
const
revertPromise
=
inPreview
?
revertPreview
()
:
Promise
.
resolve
();
return
revertPromise
.
then
(()
=>
{
const
expandAbbrList
:
ExpandAbbreviationInput
[]
=
rangesToReplace
.
map
(
rangesAndContent
=>
{
le
t
rangeToReplace
=
rangesAndContent
.
originalRange
;
cons
t
rangeToReplace
=
rangesAndContent
.
originalRange
;
let
textToWrap
:
string
[];
if
(
individualLines
)
{
textToWrap
=
rangesAndContent
.
textToWrapInPreview
;
...
...
@@ -270,17 +270,17 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
return
fallbackTab
();
}
le
t
abbreviationList
:
ExpandAbbreviationInput
[]
=
[];
cons
t
abbreviationList
:
ExpandAbbreviationInput
[]
=
[];
let
firstAbbreviation
:
string
;
let
allAbbreviationsSame
:
boolean
=
true
;
const
helper
=
getEmmetHelper
();
le
t
getAbbreviation
=
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
position
:
vscode
.
Position
,
syntax
:
string
):
[
vscode
.
Range
|
null
,
string
,
string
]
=>
{
cons
t
getAbbreviation
=
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
position
:
vscode
.
Position
,
syntax
:
string
):
[
vscode
.
Range
|
null
,
string
,
string
]
=>
{
position
=
document
.
validatePosition
(
position
);
let
rangeToReplace
:
vscode
.
Range
=
selection
;
let
abbr
=
document
.
getText
(
rangeToReplace
);
if
(
!
rangeToReplace
.
isEmpty
)
{
le
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
abbr
);
cons
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
abbr
);
if
(
extractedResults
)
{
return
[
rangeToReplace
,
extractedResults
.
abbreviation
,
extractedResults
.
filter
];
}
...
...
@@ -293,23 +293,23 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
// Expand cases like <div to <div></div> explicitly
// else we will end up with <<div></div>
if
(
syntax
===
'
html
'
)
{
le
t
matches
=
textTillPosition
.
match
(
/<
(\w
+
)
$/
);
cons
t
matches
=
textTillPosition
.
match
(
/<
(\w
+
)
$/
);
if
(
matches
)
{
abbr
=
matches
[
1
];
rangeToReplace
=
new
vscode
.
Range
(
position
.
translate
(
0
,
-
(
abbr
.
length
+
1
)),
position
);
return
[
rangeToReplace
,
abbr
,
''
];
}
}
le
t
extractedResults
=
helper
.
extractAbbreviation
(
toLSTextDocument
(
editor
.
document
),
position
,
false
);
cons
t
extractedResults
=
helper
.
extractAbbreviation
(
toLSTextDocument
(
editor
.
document
),
position
,
false
);
if
(
!
extractedResults
)
{
return
[
null
,
''
,
''
];
}
le
t
{
abbreviationRange
,
abbreviation
,
filter
}
=
extractedResults
;
cons
t
{
abbreviationRange
,
abbreviation
,
filter
}
=
extractedResults
;
return
[
new
vscode
.
Range
(
abbreviationRange
.
start
.
line
,
abbreviationRange
.
start
.
character
,
abbreviationRange
.
end
.
line
,
abbreviationRange
.
end
.
character
),
abbreviation
,
filter
];
};
le
t
selectionsInReverseOrder
=
editor
.
selections
.
slice
(
0
);
cons
t
selectionsInReverseOrder
=
editor
.
selections
.
slice
(
0
);
selectionsInReverseOrder
.
sort
((
a
,
b
)
=>
{
const
posA
=
a
.
isReversed
?
a
.
anchor
:
a
.
active
;
const
posB
=
b
.
isReversed
?
b
.
anchor
:
b
.
active
;
...
...
@@ -322,7 +322,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
return
rootNode
;
}
le
t
usePartialParsing
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
optimizeStylesheetParsing
'
]
===
true
;
cons
t
usePartialParsing
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
optimizeStylesheetParsing
'
]
===
true
;
if
(
editor
.
selections
.
length
===
1
&&
isStyleSheet
(
editor
.
document
.
languageId
)
&&
usePartialParsing
&&
editor
.
document
.
lineCount
>
1000
)
{
rootNode
=
parsePartialStylesheet
(
editor
.
document
,
editor
.
selection
.
isReversed
?
editor
.
selection
.
anchor
:
editor
.
selection
.
active
);
}
else
{
...
...
@@ -333,8 +333,8 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
}
selectionsInReverseOrder
.
forEach
(
selection
=>
{
le
t
position
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
le
t
[
rangeToReplace
,
abbreviation
,
filter
]
=
getAbbreviation
(
editor
.
document
,
selection
,
position
,
syntax
);
cons
t
position
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
cons
t
[
rangeToReplace
,
abbreviation
,
filter
]
=
getAbbreviation
(
editor
.
document
,
selection
,
position
,
syntax
);
if
(
!
rangeToReplace
)
{
return
;
}
...
...
@@ -578,7 +578,7 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
// Snippet to replace at multiple cursors are not the same
// `editor.insertSnippet` will have to be called for each instance separately
// We will not be able to maintain multiple cursors after snippet insertion
le
t
insertPromises
:
Thenable
<
boolean
>
[]
=
[];
cons
t
insertPromises
:
Thenable
<
boolean
>
[]
=
[];
if
(
!
insertSameSnippet
)
{
expandAbbrList
.
sort
((
a
:
ExpandAbbreviationInput
,
b
:
ExpandAbbreviationInput
)
=>
{
return
b
.
rangeToReplace
.
start
.
compareTo
(
a
.
rangeToReplace
.
start
);
}).
forEach
((
expandAbbrInput
:
ExpandAbbreviationInput
)
=>
{
let
expandedText
=
expandAbbr
(
expandAbbrInput
);
...
...
@@ -596,8 +596,8 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
// We can pass all ranges to `editor.insertSnippet` in a single call so that
// all cursors are maintained after snippet insertion
const
anyExpandAbbrInput
=
expandAbbrList
[
0
];
le
t
expandedText
=
expandAbbr
(
anyExpandAbbrInput
);
le
t
allRanges
=
expandAbbrList
.
map
(
value
=>
{
cons
t
expandedText
=
expandAbbr
(
anyExpandAbbrInput
);
cons
t
allRanges
=
expandAbbrList
.
map
(
value
=>
{
return
new
vscode
.
Range
(
value
.
rangeToReplace
.
start
.
line
,
value
.
rangeToReplace
.
start
.
character
,
value
.
rangeToReplace
.
end
.
line
,
value
.
rangeToReplace
.
end
.
character
);
});
if
(
expandedText
)
{
...
...
@@ -614,7 +614,7 @@ function walk(root: any, fn: ((node: any) => boolean)): boolean {
let
ctx
=
root
;
while
(
ctx
)
{
le
t
next
=
ctx
.
next
;
cons
t
next
=
ctx
.
next
;
if
(
fn
(
ctx
)
===
false
||
walk
(
ctx
.
firstChild
,
fn
)
===
false
)
{
return
false
;
}
...
...
@@ -653,7 +653,7 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
// Expand the abbreviation
if
(
input
.
textToWrap
)
{
le
t
parsedAbbr
=
helper
.
parseAbbreviation
(
input
.
abbreviation
,
expandOptions
);
cons
t
parsedAbbr
=
helper
.
parseAbbreviation
(
input
.
abbreviation
,
expandOptions
);
if
(
input
.
rangeToReplace
.
isSingleLine
&&
input
.
textToWrap
.
length
===
1
)
{
// Fetch rightmost element in the parsed abbreviation (i.e the element that will contain the wrapped text).
...
...
extensions/emmet/src/test/abbreviationAction.test.ts
浏览文件 @
0c50806e
...
...
@@ -61,7 +61,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
'
img
'
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
3
,
0
,
3
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<img src=
\
"
\
" alt=
\
"
\
">
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<img src=
\
"
\
" alt=
\
"
\
">
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -72,14 +72,14 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
e
qual
(
!
completionPromise
,
false
,
`Got unexpected undefined instead of a completion promise`
);
assert
.
strictE
qual
(
!
completionPromise
,
false
,
`Got unexpected undefined instead of a completion promise`
);
return
Promise
.
resolve
();
}
const
completionList
=
await
completionPromise
;
assert
.
e
qual
(
completionList
&&
completionList
.
items
&&
completionList
.
items
.
length
>
0
,
true
);
assert
.
strictE
qual
(
completionList
&&
completionList
.
items
&&
completionList
.
items
.
length
>
0
,
true
);
if
(
completionList
)
{
assert
.
e
qual
(
completionList
.
items
[
0
].
label
,
'
img
'
);
assert
.
e
qual
(((
<
string
>
completionList
.
items
[
0
].
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
'
<img src=
\
"
\
" alt=
\
"
\
">
'
);
assert
.
strictE
qual
(
completionList
.
items
[
0
].
label
,
'
img
'
);
assert
.
strictE
qual
(((
<
string
>
completionList
.
items
[
0
].
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
'
<img src=
\
"
\
" alt=
\
"
\
">
'
);
}
return
Promise
.
resolve
();
});
...
...
@@ -161,7 +161,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
4
,
2
,
4
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
);
return
Promise
.
resolve
();
});
});
...
...
@@ -171,7 +171,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
editor
.
selection
=
new
Selection
(
2
,
4
,
2
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
assert
.
e
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
assert
.
strictE
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -180,7 +180,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
9
,
8
,
9
,
8
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
);
return
Promise
.
resolve
();
});
});
...
...
@@ -190,7 +190,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
editor
.
selection
=
new
Selection
(
9
,
8
,
9
,
8
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
assert
.
e
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
assert
.
strictE
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -200,7 +200,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
fileContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
fileContents
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
fileContents
);
return
Promise
.
resolve
();
});
});
...
...
@@ -211,7 +211,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
assert
.
e
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
assert
.
strictE
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -219,12 +219,12 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
test
(
'
Expand css when inside style tag (HTML)
'
,
()
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
13
,
16
,
13
,
19
);
le
t
expandPromise
=
expandEmmetAbbreviation
({
language
:
'
css
'
});
cons
t
expandPromise
=
expandEmmetAbbreviation
({
language
:
'
css
'
});
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
await
expandPromise
;
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
...
...
@@ -238,19 +238,19 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding m10`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
completionList
=
await
completionPromise
;
if
(
!
completionList
||
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding m10`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
e
qual
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
e
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
e
qual
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
strictE
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -259,7 +259,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
13
,
14
,
13
,
14
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
);
return
Promise
.
resolve
();
});
});
...
...
@@ -268,12 +268,12 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
styleAttributeContent
=
'
<div style="m10" class="hello"></div>
'
;
return
withRandomFileEditor
(
styleAttributeContent
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
15
,
0
,
15
);
le
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
cons
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
await
expandPromise
;
assert
.
e
qual
(
editor
.
document
.
getText
(),
styleAttributeContent
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
styleAttributeContent
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
...
...
@@ -287,19 +287,19 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding m10`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
completionList
=
await
completionPromise
;
if
(
!
completionList
||
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding m10`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding m10`
);
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
e
qual
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
e
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
e
qual
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
label
,
expandedText
,
`Label of completion item doesnt match.`
);
assert
.
strictE
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
filterText
,
abbreviation
,
`FilterText of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -307,12 +307,12 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
test
(
'
Expand html when inside script tag with html type (HTML)
'
,
()
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
21
,
12
,
21
,
12
);
le
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
cons
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
await
expandPromise
;
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
span.hello
'
,
'
<span class="hello"></span>
'
));
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
span.hello
'
,
'
<span class="hello"></span>
'
));
return
Promise
.
resolve
();
});
});
...
...
@@ -326,18 +326,18 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding span.hello`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding span.hello`
);
return
Promise
.
resolve
();
}
const
completionList
=
await
completionPromise
;
if
(
!
completionList
||
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding span.hello`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding span.hello`
);
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
e
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item doesnt match.`
);
assert
.
e
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item doesnt match.`
);
assert
.
strictE
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -346,7 +346,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
24
,
12
,
24
,
12
);
await
expandEmmetAbbreviation
(
null
);
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
);
return
Promise
.
resolve
();
});
});
...
...
@@ -356,7 +356,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
editor
.
selection
=
new
Selection
(
24
,
12
,
24
,
12
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
assert
.
e
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
assert
.
strictE
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
return
Promise
.
resolve
();
});
});
...
...
@@ -365,12 +365,12 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
await
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
{
'
javascript
'
:
'
html
'
},
ConfigurationTarget
.
Global
);
await
withRandomFileEditor
(
htmlContents
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
24
,
10
,
24
,
10
);
le
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
cons
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
await
expandPromise
;
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
span.bye
'
,
'
<span class="bye"></span>
'
));
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
span.bye
'
,
'
<span class="bye"></span>
'
));
});
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
oldValueForInlcudeLanguages
||
{},
ConfigurationTarget
.
Global
);
});
...
...
@@ -384,17 +384,17 @@ suite('Tests for Expand Abbreviations (HTML)', () => {
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding span.bye`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding span.bye`
);
return
Promise
.
resolve
();
}
const
completionList
=
await
completionPromise
;
if
(
!
completionList
||
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding span.bye`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding span.bye`
);
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
e
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item (
${
emmetCompletionItem
.
label
}
) doesnt match.`
);
assert
.
e
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item (
${
emmetCompletionItem
.
label
}
) doesnt match.`
);
assert
.
strictE
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
includeLanguages
'
,
oldValueForInlcudeLanguages
||
{},
ConfigurationTarget
.
Global
);
...
...
@@ -433,7 +433,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
ul.nav
'
,
'
javascriptreact
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
({
language
:
'
javascriptreact
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<ul className="nav"></ul>
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<ul className="nav"></ul>
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -442,7 +442,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
img
'
,
'
javascriptreact
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
({
language
:
'
javascriptreact
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt=""/>
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt=""/>
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -452,7 +452,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
img
'
,
'
javascriptreact
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
({
language
:
'
javascriptreact
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<img src=
\'\'
alt=
\'\'
/>
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<img src=
\'\'
alt=
\'\'
/>
'
);
return
workspace
.
getConfiguration
(
'
emmet
'
).
update
(
'
syntaxProfiles
'
,
oldValueForSyntaxProfiles
?
oldValueForSyntaxProfiles
.
globalValue
:
undefined
,
ConfigurationTarget
.
Global
);
});
});
...
...
@@ -461,7 +461,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
img
'
,
'
xml
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
({
language
:
'
xml
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt=""/>
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt=""/>
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -470,7 +470,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
img
'
,
'
html
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
6
,
0
,
6
);
await
expandEmmetAbbreviation
({
language
:
'
html
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt="">
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
<img src="" alt="">
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -479,7 +479,7 @@ suite('Tests for jsx, xml and xsl', () => {
return
withRandomFileEditor
(
'
if (foo < 10) { span.bar
'
,
'
javascriptreact
'
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
27
,
0
,
27
);
await
expandEmmetAbbreviation
({
language
:
'
javascriptreact
'
});
assert
.
e
qual
(
editor
.
document
.
getText
(),
'
if (foo < 10) { <span className="bar"></span>
'
);
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
'
if (foo < 10) { <span className="bar"></span>
'
);
return
Promise
.
resolve
();
});
});
...
...
@@ -505,15 +505,15 @@ suite('Tests for jsx, xml and xsl', () => {
function
testExpandAbbreviation
(
syntax
:
string
,
selection
:
Selection
,
abbreviation
:
string
,
expandedText
:
string
,
shouldFail
?:
boolean
):
Thenable
<
any
>
{
return
withRandomFileEditor
(
htmlContents
,
syntax
,
async
(
editor
,
_doc
)
=>
{
editor
.
selection
=
selection
;
le
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
cons
t
expandPromise
=
expandEmmetAbbreviation
(
null
);
if
(
!
expandPromise
)
{
if
(
!
shouldFail
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
}
return
Promise
.
resolve
();
}
await
expandPromise
;
assert
.
e
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
abbreviation
,
expandedText
));
assert
.
strictE
qual
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
abbreviation
,
expandedText
));
return
Promise
.
resolve
();
});
}
...
...
@@ -525,7 +525,7 @@ function testHtmlCompletionProvider(selection: Selection, abbreviation: string,
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
!
completionPromise
)
{
if
(
!
shouldFail
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
}
return
Promise
.
resolve
();
}
...
...
@@ -533,13 +533,13 @@ function testHtmlCompletionProvider(selection: Selection, abbreviation: string,
const
completionList
=
await
completionPromise
;
if
(
!
completionList
||
!
completionList
.
items
||
!
completionList
.
items
.
length
)
{
if
(
!
shouldFail
)
{
assert
.
e
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
assert
.
strictE
qual
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
}
return
Promise
.
resolve
();
}
const
emmetCompletionItem
=
completionList
.
items
[
0
];
assert
.
e
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item doesnt match.`
);
assert
.
e
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
assert
.
strictE
qual
(
emmetCompletionItem
.
label
,
abbreviation
,
`Label of completion item doesnt match.`
);
assert
.
strictE
qual
(((
<
string
>
emmetCompletionItem
.
documentation
)
||
''
).
replace
(
/
\|
/g
,
''
),
expandedText
,
`Docs of completion item doesnt match.`
);
return
Promise
.
resolve
();
});
}
...
...
@@ -549,7 +549,7 @@ function testNoCompletion(syntax: string, fileContents: string, selection: Selec
editor
.
selection
=
selection
;
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
assert
.
e
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
assert
.
strictE
qual
(
!
completionPromise
,
true
,
`Got unexpected comapletion promise instead of undefined`
);
return
Promise
.
resolve
();
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录