Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
6ad61f01
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,发现更多精彩内容 >>
提交
6ad61f01
编写于
10月 02, 2018
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Getting closer to shared config #59803
上级
5ae10c4e
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
127 addition
and
121 deletion
+127
-121
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+4
-8
extensions/emmet/src/defaultCompletionProvider.ts
extensions/emmet/src/defaultCompletionProvider.ts
+3
-3
extensions/emmet/src/editPoint.ts
extensions/emmet/src/editPoint.ts
+1
-0
extensions/emmet/src/incrementDecrement.ts
extensions/emmet/src/incrementDecrement.ts
+3
-1
extensions/emmet/src/locateFile.ts
extensions/emmet/src/locateFile.ts
+1
-1
extensions/emmet/src/selectItem.ts
extensions/emmet/src/selectItem.ts
+7
-13
extensions/emmet/src/selectItemHTML.ts
extensions/emmet/src/selectItemHTML.ts
+19
-10
extensions/emmet/src/selectItemStylesheet.ts
extensions/emmet/src/selectItemStylesheet.ts
+12
-12
extensions/emmet/src/test/cssAbbreviationAction.test.ts
extensions/emmet/src/test/cssAbbreviationAction.test.ts
+17
-17
extensions/emmet/src/test/editPointSelectItemBalance.test.ts
extensions/emmet/src/test/editPointSelectItemBalance.test.ts
+10
-10
extensions/emmet/src/test/incrementDecrement.test.ts
extensions/emmet/src/test/incrementDecrement.test.ts
+1
-1
extensions/emmet/src/test/partialParsingStylesheet.test.ts
extensions/emmet/src/test/partialParsingStylesheet.test.ts
+8
-8
extensions/emmet/src/test/tagActions.test.ts
extensions/emmet/src/test/tagActions.test.ts
+2
-2
extensions/emmet/src/test/testUtils.ts
extensions/emmet/src/test/testUtils.ts
+1
-1
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
+9
-9
extensions/emmet/src/toggleComment.ts
extensions/emmet/src/toggleComment.ts
+3
-11
extensions/emmet/src/updateImageSize.ts
extensions/emmet/src/updateImageSize.ts
+10
-6
extensions/emmet/src/util.ts
extensions/emmet/src/util.ts
+10
-5
extensions/emmet/tsconfig.json
extensions/emmet/tsconfig.json
+6
-3
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
6ad61f01
...
...
@@ -340,9 +340,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
});
return
expandAbbreviationInRange
(
editor
,
abbreviationList
,
allAbbreviationsSame
).
then
(
success
=>
{
if
(
!
success
)
{
return
fallbackTab
();
}
return
success
?
Promise
.
resolve
(
undefined
)
:
fallbackTab
();
});
}
...
...
@@ -581,7 +579,7 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
/**
* Expands abbreviation as detailed in given input.
*/
function
expandAbbr
(
input
:
ExpandAbbreviationInput
):
string
|
undefined
{
function
expandAbbr
(
input
:
ExpandAbbreviationInput
):
string
{
const
helper
=
getEmmetHelper
();
const
expandOptions
=
helper
.
getExpandOptions
(
input
.
syntax
,
getEmmetConfiguration
(
input
.
syntax
),
input
.
filter
);
...
...
@@ -601,9 +599,9 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
}
}
let
expandedText
;
try
{
// Expand the abbreviation
let
expandedText
;
if
(
input
.
textToWrap
)
{
let
parsedAbbr
=
helper
.
parseAbbreviation
(
input
.
abbreviation
,
expandOptions
);
...
...
@@ -628,13 +626,11 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
expandedText
=
helper
.
expandAbbreviation
(
input
.
abbreviation
,
expandOptions
);
}
return
expandedText
;
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
'
Failed to expand abbreviation
'
);
}
return
expandedText
;
}
function
getSyntaxFromArgs
(
args
:
{
[
x
:
string
]:
string
}):
string
|
undefined
{
...
...
extensions/emmet/src/defaultCompletionProvider.ts
浏览文件 @
6ad61f01
...
...
@@ -12,8 +12,8 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
private
lastCompletionType
:
string
|
undefined
;
public
provideCompletionItems
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
token
:
vscode
.
CancellationToken
,
context
:
vscode
.
CompletionContext
):
Thenable
<
vscode
.
CompletionList
|
undefined
>
|
undefined
{
const
completionResult
=
this
.
provideCompletionItemsInternal
(
document
,
position
,
token
,
context
);
public
provideCompletionItems
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
_
:
vscode
.
CancellationToken
,
context
:
vscode
.
CompletionContext
):
Thenable
<
vscode
.
CompletionList
|
undefined
>
|
undefined
{
const
completionResult
=
this
.
provideCompletionItemsInternal
(
document
,
position
,
context
);
if
(
!
completionResult
)
{
this
.
lastCompletionType
=
undefined
;
return
;
...
...
@@ -38,7 +38,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
});
}
private
provideCompletionItemsInternal
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
token
:
vscode
.
CancellationToken
,
context
:
vscode
.
CompletionContext
):
Thenable
<
vscode
.
CompletionList
|
undefined
>
|
undefined
{
private
provideCompletionItemsInternal
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
context
:
vscode
.
CompletionContext
):
Thenable
<
vscode
.
CompletionList
|
undefined
>
|
undefined
{
const
emmetConfig
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
);
const
excludedLanguages
=
emmetConfig
[
'
excludeLanguages
'
]
?
emmetConfig
[
'
excludeLanguages
'
]
:
[];
if
(
excludedLanguages
.
indexOf
(
document
.
languageId
)
>
-
1
)
{
...
...
extensions/emmet/src/editPoint.ts
浏览文件 @
6ad61f01
...
...
@@ -69,4 +69,5 @@ function findEditPoint(lineNum: number, editor: vscode.TextEditor, position: vsc
if
(
winner
>
-
1
)
{
return
new
vscode
.
Selection
(
lineNum
,
winner
+
1
,
lineNum
,
winner
+
1
);
}
return
;
}
extensions/emmet/src/incrementDecrement.ts
浏览文件 @
6ad61f01
...
...
@@ -45,7 +45,7 @@ export function update(numString: string, delta: number): string {
if
(
m
=
numString
.
match
(
/^
\-?(
0
\d
+
)
/
))
{
// padded number: preserve padding
output
=
output
.
replace
(
/^
(\-?)(\d
+
)
/
,
(
str
,
minus
,
prefix
)
=>
output
=
output
.
replace
(
/^
(\-?)(\d
+
)
/
,
(
_
,
minus
,
prefix
)
=>
minus
+
'
0
'
.
repeat
(
Math
.
max
(
0
,
(
m
?
m
[
1
].
length
:
0
)
-
prefix
.
length
))
+
prefix
);
}
...
...
@@ -102,6 +102,8 @@ export function locate(document: vscode.TextDocument, pos: vscode.Position): vsc
if
(
start
!==
end
&&
isValidNumber
(
line
.
slice
(
start
,
end
)))
{
return
new
vscode
.
Range
(
pos
.
line
,
start
,
pos
.
line
,
end
);
}
return
;
}
/**
...
...
extensions/emmet/src/locateFile.ts
浏览文件 @
6ad61f01
...
...
@@ -51,7 +51,7 @@ function resolveAbsolute(basePath: string, filePath: string): Promise<string> {
const
next
=
(
ctx
:
string
)
=>
{
tryFile
(
path
.
resolve
(
ctx
,
filePath
))
.
then
(
resolve
,
err
=>
{
.
then
(
resolve
,
()
=>
{
const
dir
=
path
.
dirname
(
ctx
);
if
(
!
dir
||
dir
===
ctx
)
{
return
reject
(
`Unable to locate absolute file
${
filePath
}
`
);
...
...
extensions/emmet/src/selectItem.ts
浏览文件 @
6ad61f01
...
...
@@ -7,24 +7,13 @@ import * as vscode from 'vscode';
import
{
validate
,
parseDocument
,
isStyleSheet
}
from
'
./util
'
;
import
{
nextItemHTML
,
prevItemHTML
}
from
'
./selectItemHTML
'
;
import
{
nextItemStylesheet
,
prevItemStylesheet
}
from
'
./selectItemStylesheet
'
;
import
{
HtmlNode
,
CssNode
}
from
'
EmmetNode
'
;
export
function
fetchSelectItem
(
direction
:
string
):
void
{
if
(
!
validate
()
||
!
vscode
.
window
.
activeTextEditor
)
{
return
;
}
const
editor
=
vscode
.
window
.
activeTextEditor
;
let
nextItem
:
any
;
let
prevItem
:
any
;
if
(
isStyleSheet
(
editor
.
document
.
languageId
))
{
nextItem
=
nextItemStylesheet
;
prevItem
=
prevItemStylesheet
;
}
else
{
nextItem
=
nextItemHTML
;
prevItem
=
prevItemHTML
;
}
let
rootNode
=
parseDocument
(
editor
.
document
);
if
(
!
rootNode
)
{
return
;
...
...
@@ -35,7 +24,12 @@ export function fetchSelectItem(direction: string): void {
const
selectionStart
=
selection
.
isReversed
?
selection
.
active
:
selection
.
anchor
;
const
selectionEnd
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
let
updatedSelection
=
direction
===
'
next
'
?
nextItem
(
selectionStart
,
selectionEnd
,
editor
,
rootNode
)
:
prevItem
(
selectionStart
,
selectionEnd
,
editor
,
rootNode
);
let
updatedSelection
;
if
(
isStyleSheet
(
editor
.
document
.
languageId
))
{
updatedSelection
=
direction
===
'
next
'
?
nextItemStylesheet
(
selectionStart
,
selectionEnd
,
<
CssNode
>
rootNode
!
)
:
prevItemStylesheet
(
selectionStart
,
selectionEnd
,
<
CssNode
>
rootNode
!
);
}
else
{
updatedSelection
=
direction
===
'
next
'
?
nextItemHTML
(
selectionStart
,
selectionEnd
,
editor
,
<
HtmlNode
>
rootNode
!
)
:
prevItemHTML
(
selectionStart
,
selectionEnd
,
editor
,
<
HtmlNode
>
rootNode
!
);
}
newSelections
.
push
(
updatedSelection
?
updatedSelection
:
selection
);
});
editor
.
selections
=
newSelections
;
...
...
extensions/emmet/src/selectItemHTML.ts
浏览文件 @
6ad61f01
...
...
@@ -6,6 +6,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
{
getDeepestNode
,
findNextWord
,
findPrevWord
,
getHtmlNode
}
from
'
./util
'
;
import
{
HtmlNode
}
from
'
EmmetNode
'
;
import
{
isNumber
}
from
'
util
'
;
export
function
nextItemHTML
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
editor
:
vscode
.
TextEditor
,
rootNode
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
let
currentNode
=
getHtmlNode
(
editor
.
document
,
rootNode
,
selectionEnd
,
false
);
...
...
@@ -18,12 +19,12 @@ export function nextItemHTML(selectionStart: vscode.Position, selectionEnd: vsco
if
(
currentNode
.
type
!==
'
comment
'
)
{
// If cursor is in the tag name, select tag
if
(
selectionEnd
.
isBefore
(
currentNode
.
open
.
start
.
translate
(
0
,
currentNode
.
name
.
length
)))
{
return
getSelectionFromNode
(
currentNode
,
editor
.
document
);
return
getSelectionFromNode
(
currentNode
);
}
// If cursor is in the open tag, look for attributes
if
(
selectionEnd
.
isBefore
(
currentNode
.
open
.
end
))
{
let
attrSelection
=
getNextAttribute
(
selectionStart
,
selectionEnd
,
editor
.
document
,
currentNode
);
let
attrSelection
=
getNextAttribute
(
selectionStart
,
selectionEnd
,
currentNode
);
if
(
attrSelection
)
{
return
attrSelection
;
}
...
...
@@ -50,7 +51,7 @@ export function nextItemHTML(selectionStart: vscode.Position, selectionEnd: vsco
}
}
return
nextNode
&&
getSelectionFromNode
(
nextNode
,
editor
.
document
);
return
nextNode
&&
getSelectionFromNode
(
nextNode
);
}
export
function
prevItemHTML
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
editor
:
vscode
.
TextEditor
,
rootNode
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
...
...
@@ -98,11 +99,11 @@ export function prevItemHTML(selectionStart: vscode.Position, selectionEnd: vsco
return
undefined
;
}
let
attrSelection
=
getPrevAttribute
(
selectionStart
,
selectionEnd
,
editor
.
document
,
prevNode
);
return
attrSelection
?
attrSelection
:
getSelectionFromNode
(
prevNode
,
editor
.
document
);
let
attrSelection
=
getPrevAttribute
(
selectionStart
,
selectionEnd
,
prevNode
);
return
attrSelection
?
attrSelection
:
getSelectionFromNode
(
prevNode
);
}
function
getSelectionFromNode
(
node
:
HtmlNode
,
document
:
vscode
.
TextDocument
):
vscode
.
Selection
|
undefined
{
function
getSelectionFromNode
(
node
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
if
(
node
&&
node
.
open
)
{
let
selectionStart
=
(
<
vscode
.
Position
>
node
.
open
.
start
).
translate
(
0
,
1
);
let
selectionEnd
=
selectionStart
.
translate
(
0
,
node
.
name
.
length
);
...
...
@@ -112,7 +113,7 @@ function getSelectionFromNode(node: HtmlNode, document: vscode.TextDocument): vs
return
undefined
;
}
function
getNextAttribute
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
document
:
vscode
.
TextDocument
,
node
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
function
getNextAttribute
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
node
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
if
(
!
node
.
attributes
||
node
.
attributes
.
length
===
0
||
node
.
type
===
'
comment
'
)
{
return
;
...
...
@@ -153,6 +154,9 @@ function getNextAttribute(selectionStart: vscode.Position, selectionEnd: vscode.
if
(
pos
!==
undefined
)
{
let
[
newSelectionStartOffset
,
newSelectionEndOffset
]
=
findNextWord
(
attr
.
value
.
toString
(),
pos
);
if
(
!
isNumber
(
newSelectionStartOffset
)
||
!
isNumber
(
newSelectionEndOffset
))
{
return
;
}
if
(
newSelectionStartOffset
>=
0
&&
newSelectionEndOffset
>=
0
)
{
const
newSelectionStart
=
(
<
vscode
.
Position
>
attr
.
value
.
start
).
translate
(
0
,
newSelectionStartOffset
);
const
newSelectionEnd
=
(
<
vscode
.
Position
>
attr
.
value
.
start
).
translate
(
0
,
newSelectionEndOffset
);
...
...
@@ -161,9 +165,11 @@ function getNextAttribute(selectionStart: vscode.Position, selectionEnd: vscode.
}
}
return
;
}
function
getPrevAttribute
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
document
:
vscode
.
TextDocument
,
node
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
function
getPrevAttribute
(
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
node
:
HtmlNode
):
vscode
.
Selection
|
undefined
{
if
(
!
node
.
attributes
||
node
.
attributes
.
length
===
0
||
node
.
type
===
'
comment
'
)
{
return
;
...
...
@@ -194,12 +200,15 @@ function getPrevAttribute(selectionStart: vscode.Position, selectionEnd: vscode.
let
pos
=
selectionStart
.
isAfter
(
attr
.
value
.
end
)
?
attr
.
value
.
toString
().
length
:
selectionStart
.
character
-
attr
.
value
.
start
.
character
;
let
[
newSelectionStartOffset
,
newSelectionEndOffset
]
=
findPrevWord
(
attr
.
value
.
toString
(),
pos
);
if
(
!
isNumber
(
newSelectionStartOffset
)
||
!
isNumber
(
newSelectionEndOffset
))
{
return
;
}
if
(
newSelectionStartOffset
>=
0
&&
newSelectionEndOffset
>=
0
)
{
const
newSelectionStart
=
(
<
vscode
.
Position
>
attr
.
value
.
start
).
translate
(
0
,
newSelectionStartOffset
);
const
newSelectionEnd
=
(
<
vscode
.
Position
>
attr
.
value
.
start
).
translate
(
0
,
newSelectionEndOffset
);
return
new
vscode
.
Selection
(
newSelectionStart
,
newSelectionEnd
);
}
}
return
;
}
\ No newline at end of file
extensions/emmet/src/selectItemStylesheet.ts
浏览文件 @
6ad61f01
...
...
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import
{
getDeepestNode
,
findNextWord
,
findPrevWord
,
getNode
}
from
'
./util
'
;
import
{
Node
,
CssNode
,
Rule
,
Property
}
from
'
EmmetNode
'
;
export
function
nextItemStylesheet
(
startOffset
:
vscode
.
Position
,
endOffset
:
vscode
.
Position
,
editor
:
vscode
.
TextEditor
,
rootNode
:
Node
):
vscode
.
Selection
|
undefined
{
export
function
nextItemStylesheet
(
startOffset
:
vscode
.
Position
,
endOffset
:
vscode
.
Position
,
rootNode
:
Node
):
vscode
.
Selection
|
undefined
{
let
currentNode
=
<
CssNode
>
getNode
(
rootNode
,
endOffset
,
true
);
if
(
!
currentNode
)
{
currentNode
=
<
CssNode
>
rootNode
;
...
...
@@ -17,12 +17,12 @@ export function nextItemStylesheet(startOffset: vscode.Position, endOffset: vsco
}
// Full property is selected, so select full property value next
if
(
currentNode
.
type
===
'
property
'
&&
startOffset
.
isEqual
(
currentNode
.
start
)
&&
endOffset
.
isEqual
(
currentNode
.
end
))
{
return
getSelectionFromProperty
(
currentNode
,
editor
.
document
,
startOffset
,
endOffset
,
true
,
'
next
'
);
return
getSelectionFromProperty
(
currentNode
,
startOffset
,
endOffset
,
true
,
'
next
'
);
}
// Part or whole of propertyValue is selected, so select the next word in the propertyValue
if
(
currentNode
.
type
===
'
property
'
&&
startOffset
.
isAfterOrEqual
((
<
Property
>
currentNode
).
valueToken
.
start
)
&&
endOffset
.
isBeforeOrEqual
((
<
Property
>
currentNode
).
valueToken
.
end
))
{
let
singlePropertyValue
=
getSelectionFromProperty
(
currentNode
,
editor
.
document
,
startOffset
,
endOffset
,
false
,
'
next
'
);
let
singlePropertyValue
=
getSelectionFromProperty
(
currentNode
,
startOffset
,
endOffset
,
false
,
'
next
'
);
if
(
singlePropertyValue
)
{
return
singlePropertyValue
;
}
...
...
@@ -31,7 +31,7 @@ export function nextItemStylesheet(startOffset: vscode.Position, endOffset: vsco
// Cursor is in the selector or in a property
if
((
currentNode
.
type
===
'
rule
'
&&
endOffset
.
isBefore
((
<
Rule
>
currentNode
).
selectorToken
.
end
))
||
(
currentNode
.
type
===
'
property
'
&&
endOffset
.
isBefore
((
<
Property
>
currentNode
).
valueToken
.
end
)))
{
return
getSelectionFromNode
(
currentNode
,
editor
.
document
);
return
getSelectionFromNode
(
currentNode
);
}
// Get the first child of current node which is right after the cursor
...
...
@@ -46,11 +46,11 @@ export function nextItemStylesheet(startOffset: vscode.Position, endOffset: vsco
currentNode
=
currentNode
.
parent
;
}
return
getSelectionFromNode
(
nextNode
,
editor
.
document
);
return
getSelectionFromNode
(
nextNode
);
}
export
function
prevItemStylesheet
(
startOffset
:
vscode
.
Position
,
endOffset
:
vscode
.
Position
,
editor
:
vscode
.
TextEditor
,
rootNode
:
CssNode
):
vscode
.
Selection
|
undefined
{
export
function
prevItemStylesheet
(
startOffset
:
vscode
.
Position
,
endOffset
:
vscode
.
Position
,
rootNode
:
CssNode
):
vscode
.
Selection
|
undefined
{
let
currentNode
=
<
CssNode
>
getNode
(
rootNode
,
startOffset
,
false
);
if
(
!
currentNode
)
{
currentNode
=
rootNode
;
...
...
@@ -61,19 +61,19 @@ export function prevItemStylesheet(startOffset: vscode.Position, endOffset: vsco
// Full property value is selected, so select the whole property next
if
(
currentNode
.
type
===
'
property
'
&&
startOffset
.
isEqual
((
<
Property
>
currentNode
).
valueToken
.
start
)
&&
endOffset
.
isEqual
((
<
Property
>
currentNode
).
valueToken
.
end
))
{
return
getSelectionFromNode
(
currentNode
,
editor
.
document
);
return
getSelectionFromNode
(
currentNode
);
}
// Part of propertyValue is selected, so select the prev word in the propertyValue
if
(
currentNode
.
type
===
'
property
'
&&
startOffset
.
isAfterOrEqual
((
<
Property
>
currentNode
).
valueToken
.
start
)
&&
endOffset
.
isBeforeOrEqual
((
<
Property
>
currentNode
).
valueToken
.
end
))
{
let
singlePropertyValue
=
getSelectionFromProperty
(
currentNode
,
editor
.
document
,
startOffset
,
endOffset
,
false
,
'
prev
'
);
let
singlePropertyValue
=
getSelectionFromProperty
(
currentNode
,
startOffset
,
endOffset
,
false
,
'
prev
'
);
if
(
singlePropertyValue
)
{
return
singlePropertyValue
;
}
}
if
(
currentNode
.
type
===
'
property
'
||
!
currentNode
.
firstChild
||
(
currentNode
.
type
===
'
rule
'
&&
startOffset
.
isBeforeOrEqual
(
currentNode
.
firstChild
.
start
)))
{
return
getSelectionFromNode
(
currentNode
,
editor
.
document
);
return
getSelectionFromNode
(
currentNode
);
}
// Select the child that appears just before the cursor
...
...
@@ -83,12 +83,12 @@ export function prevItemStylesheet(startOffset: vscode.Position, endOffset: vsco
}
prevNode
=
<
CssNode
>
getDeepestNode
(
prevNode
);
return
getSelectionFromProperty
(
prevNode
,
editor
.
document
,
startOffset
,
endOffset
,
false
,
'
prev
'
);
return
getSelectionFromProperty
(
prevNode
,
startOffset
,
endOffset
,
false
,
'
prev
'
);
}
function
getSelectionFromNode
(
node
:
Node
,
document
:
vscode
.
TextDocument
):
vscode
.
Selection
|
undefined
{
function
getSelectionFromNode
(
node
:
Node
):
vscode
.
Selection
|
undefined
{
if
(
!
node
)
{
return
;
}
...
...
@@ -98,7 +98,7 @@ function getSelectionFromNode(node: Node, document: vscode.TextDocument): vscode
}
function
getSelectionFromProperty
(
node
:
Node
,
document
:
vscode
.
TextDocument
,
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
selectFullValue
:
boolean
,
direction
:
string
):
vscode
.
Selection
|
undefined
{
function
getSelectionFromProperty
(
node
:
Node
,
selectionStart
:
vscode
.
Position
,
selectionEnd
:
vscode
.
Position
,
selectFullValue
:
boolean
,
direction
:
string
):
vscode
.
Selection
|
undefined
{
if
(
!
node
||
node
.
type
!==
'
property
'
)
{
return
;
}
...
...
extensions/emmet/src/test/cssAbbreviationAction.test.ts
浏览文件 @
6ad61f01
...
...
@@ -56,7 +56,7 @@ suite('Tests for Expand Abbreviations (CSS)', () => {
teardown
(
closeAllEditors
);
test
(
'
Expand abbreviation (CSS)
'
,
()
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
1
,
3
,
6
),
new
Selection
(
5
,
1
,
5
,
6
)];
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
cssContents
.
replace
(
/pos:f/g
,
'
position: fixed;
'
));
...
...
@@ -75,7 +75,7 @@ suite('Tests for Expand Abbreviations (CSS)', () => {
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
4
,
3
,
4
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -98,7 +98,7 @@ suite('Tests for Expand Abbreviations (CSS)', () => {
nav#
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
5
,
4
,
5
,
4
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -120,7 +120,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -137,7 +137,7 @@ nav#
test
(
'
Skip when typing the last property value in single line rules (CSS)
'
,
()
=>
{
const
testContent
=
`.foo {padding: 10px; margin: a}`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
0
,
30
,
0
,
30
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -159,7 +159,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
12
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
14
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -198,7 +198,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
10
,
3
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -220,7 +220,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
12
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
14
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -258,7 +258,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
10
,
2
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -279,7 +279,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
12
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
const
completionPromise2
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
14
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -317,7 +317,7 @@ nav#
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
2
,
2
,
2
,
2
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
...
...
@@ -336,7 +336,7 @@ nav#
const
abbreviation
=
'
pos:f
'
;
const
expandedText
=
'
position: fixed;
'
;
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
1
,
3
,
6
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
6
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -366,7 +366,7 @@ nav#
});
test
(
'
Expand abbreviation (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
4
,
3
,
4
),
new
Selection
(
5
,
5
,
5
,
5
),
...
...
@@ -382,7 +382,7 @@ nav#
test
(
'
Expand abbreviation in completion list (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
4
,
3
,
4
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise1
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
3
,
4
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -439,7 +439,7 @@ m10
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
3
,
1
,
3
),
// outside rule
new
Selection
(
5
,
15
,
5
,
15
)
// in the value part of property value
...
...
@@ -462,7 +462,7 @@ m10
}
`
;
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContentsNoExpand
,
'
scss
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
1
,
3
,
1
,
3
);
// outside rule
const
cancelSrc
=
new
CancellationTokenSource
();
let
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
editor
.
selection
.
active
,
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
...
...
@@ -487,7 +487,7 @@ m10
});
test
(
'
Skip when typing property values when there is a nested rule in the next line (SCSS)
'
,
()
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContents
,
'
scss
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
19
,
10
,
19
,
10
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
scssContents
);
...
...
extensions/emmet/src/test/editPointSelectItemBalance.test.ts
浏览文件 @
6ad61f01
...
...
@@ -59,7 +59,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
`
;
test
(
'
Emmet Next/Prev Edit point in html file
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
5
,
1
,
5
)];
let
expectedNextEditPoints
:
[
number
,
number
][]
=
[[
4
,
16
],
[
6
,
8
],
[
10
,
2
],
[
20
,
0
]];
...
...
@@ -79,7 +79,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Select Next/Prev Item in html file
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
2
,
2
)];
let
expectedNextItemPoints
:
[
number
,
number
,
number
][]
=
[
...
...
@@ -114,7 +114,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Select Next/Prev item at boundary
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
.html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
4
,
1
,
4
,
1
)];
fetchSelectItem
(
'
next
'
);
...
...
@@ -138,7 +138,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
</div>
</script>
`
;
return
withRandomFileEditor
(
templateContents
,
'
.html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
templateContents
,
'
.html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
2
,
2
)];
let
expectedNextItemPoints
:
[
number
,
number
,
number
][]
=
[
...
...
@@ -167,7 +167,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Select Next/Prev Item in css file
'
,
function
():
any
{
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
0
,
0
,
0
,
0
)];
let
expectedNextItemPoints
:
[
number
,
number
,
number
][]
=
[
...
...
@@ -198,7 +198,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Select Next/Prev Item in scss file with nested rules
'
,
function
():
any
{
return
withRandomFileEditor
(
scssContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
scssContents
,
'
.scss
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
0
,
0
,
0
,
0
)];
let
expectedNextItemPoints
:
[
number
,
number
,
number
][]
=
[
...
...
@@ -229,7 +229,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Balance Out in html file
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
14
,
6
,
14
,
10
)];
let
expectedBalanceOutRanges
:
[
number
,
number
,
number
,
number
][]
=
[
...
...
@@ -266,7 +266,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Balance In using the same stack as Balance out in html file
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
15
,
6
,
15
,
10
)];
let
expectedBalanceOutRanges
:
[
number
,
number
,
number
,
number
][]
=
[
...
...
@@ -295,7 +295,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
test
(
'
Emmet Balance In when selection doesnt span entire node or its inner contents
'
,
function
():
any
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selection
=
new
Selection
(
13
,
7
,
13
,
10
);
// Inside the open tag of <ul class="nav main">
balanceIn
();
...
...
@@ -324,7 +324,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
</div>
</script>`
;
return
withRandomFileEditor
(
htmlTemplate
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlTemplate
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
5
,
24
,
5
,
24
)];
let
expectedBalanceOutRanges
:
[
number
,
number
,
number
,
number
][]
=
[
...
...
extensions/emmet/src/test/incrementDecrement.test.ts
浏览文件 @
6ad61f01
...
...
@@ -9,7 +9,7 @@ import { Selection } from 'vscode';
import
{
withRandomFileEditor
,
closeAllEditors
}
from
'
./testUtils
'
;
import
{
incrementDecrement
as
incrementDecrementImpl
}
from
'
../incrementDecrement
'
;
function
incrementDecrement
(
delta
):
Thenable
<
boolean
>
{
function
incrementDecrement
(
delta
:
number
):
Thenable
<
boolean
>
{
const
result
=
incrementDecrementImpl
(
delta
);
assert
.
ok
(
result
);
return
result
!
;
...
...
extensions/emmet/src/test/partialParsingStylesheet.test.ts
浏览文件 @
6ad61f01
...
...
@@ -15,7 +15,7 @@ suite('Tests for partial parse of Stylesheets', () => {
function
isValid
(
doc
:
vscode
.
TextDocument
,
range
:
vscode
.
Range
,
syntax
:
string
):
boolean
{
const
rootNode
=
parsePartialStylesheet
(
doc
,
range
.
end
);
const
currentNode
=
getNode
(
rootNode
,
range
.
end
,
true
);
return
isValidLocationForEmmetAbbreviation
(
doc
,
rootNode
,
currentNode
,
'
css
'
,
range
.
end
,
range
);
return
isValidLocationForEmmetAbbreviation
(
doc
,
rootNode
,
currentNode
,
syntax
,
range
.
end
,
range
);
}
test
(
'
Ignore block comment inside rule
'
,
function
():
any
{
...
...
@@ -27,7 +27,7 @@ p {
p.
} p
`
;
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
3
,
18
,
3
,
19
),
// Same line after block comment
new
vscode
.
Range
(
4
,
1
,
4
,
2
),
// p after block comment
...
...
@@ -62,7 +62,7 @@ dn {
@
} bg
`
;
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
_
,
doc
)
=>
{
let
rangesNotEmmet
=
[
new
vscode
.
Range
(
1
,
0
,
1
,
4
),
// Selector
new
vscode
.
Range
(
2
,
3
,
2
,
7
),
// Line commented selector
...
...
@@ -91,7 +91,7 @@ comment */
p.
} p
`
;
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
cssContents
,
'
.css
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
7
,
18
,
7
,
19
),
// Same line after block comment
new
vscode
.
Range
(
8
,
1
,
8
,
2
),
// p after block comment
...
...
@@ -130,7 +130,7 @@ comment */
}
}}}
`
;
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
2
,
1
,
2
,
2
),
// Inside a ruleset before errors
new
vscode
.
Range
(
3
,
1
,
3
,
2
),
// Inside a ruleset after no serious error
...
...
@@ -155,7 +155,7 @@ comment */
const
sassContents
=
`
.foo{dn}.bar{.boo{dn}dn}.comd{/*{dn*/p{div{dn}} }.foo{.other{dn}} dn
`
;
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
1
,
5
,
1
,
7
),
// Inside a ruleset
new
vscode
.
Range
(
1
,
18
,
1
,
20
),
// Inside a nested ruleset
...
...
@@ -194,7 +194,7 @@ p.#{dn} {
dn
}
`
;
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
2
,
1
,
2
,
4
),
// p.3 inside a ruleset whose selector uses interpolation
new
vscode
.
Range
(
4
,
1
,
4
,
3
)
// dn inside ruleset after property with variable
...
...
@@ -234,7 +234,7 @@ ment */{
op.3
}
`
;
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
sassContents
,
'
.scss
'
,
(
_
,
doc
)
=>
{
let
rangesForEmmet
=
[
new
vscode
.
Range
(
2
,
14
,
2
,
21
),
// brs6-2p with a block commented line comment ('/* */' overrides '//')
new
vscode
.
Range
(
3
,
1
,
3
,
3
),
// dn after a line with combined comments inside a ruleset
...
...
extensions/emmet/src/test/tagActions.test.ts
浏览文件 @
6ad61f01
...
...
@@ -295,7 +295,7 @@ suite('Tests for Emmet actions on html tags', () => {
// #region match tag
test
(
'
match tag with mutliple cursors
'
,
()
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
0
,
1
,
0
),
// just before tag starts, i.e before <
new
Selection
(
1
,
1
,
1
,
1
),
// just before tag name starts
...
...
@@ -326,7 +326,7 @@ suite('Tests for Emmet actions on html tags', () => {
</div>
</script>`
;
return
withRandomFileEditor
(
templateScript
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
templateScript
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
2
,
2
),
// just before div tag starts, i.e before <
];
...
...
extensions/emmet/src/test/testUtils.ts
浏览文件 @
6ad61f01
...
...
@@ -57,7 +57,7 @@ export function withRandomFileEditor(initialContents: string, fileExtension: str
return
vscode
.
window
.
showTextDocument
(
doc
).
then
((
editor
)
=>
{
return
run
(
editor
,
doc
).
then
(
_
=>
{
if
(
doc
.
isDirty
)
{
return
doc
.
save
().
then
(
saved
=>
{
return
doc
.
save
().
then
(
()
=>
{
return
deleteFile
(
file
);
});
}
else
{
...
...
extensions/emmet/src/test/wrapWithAbbreviation.test.ts
浏览文件 @
6ad61f01
...
...
@@ -127,7 +127,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
0
,
2
,
0
)];
const
promise
=
wrapWithAbbreviation
({
abbreviation
:
'
li.hello|c
'
});
if
(
!
promise
)
{
...
...
@@ -155,7 +155,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</div>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
1
,
1
,
1
)];
const
promise
=
wrapWithAbbreviation
({
abbreviation
:
'
div
'
});
if
(
!
promise
)
{
...
...
@@ -183,7 +183,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</div>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
3
,
1
,
3
,
1
)];
const
promise
=
wrapWithAbbreviation
({
abbreviation
:
'
div
'
});
if
(
!
promise
)
{
...
...
@@ -208,7 +208,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
1
,
2
,
1
,
2
)];
const
promise
=
wrapWithAbbreviation
({
abbreviation
:
'
ul>li>a
'
});
if
(
!
promise
)
{
...
...
@@ -237,7 +237,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
3
,
33
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*
'
});
if
(
!
promise
)
{
...
...
@@ -266,7 +266,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
1
,
4
,
0
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*
'
});
if
(
!
promise
)
{
...
...
@@ -297,7 +297,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
2
,
3
,
33
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello*|c
'
});
if
(
!
promise
)
{
...
...
@@ -326,7 +326,7 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
</ul>
`
;
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
contents
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
[
new
Selection
(
2
,
3
,
3
,
16
)];
const
promise
=
wrapIndividualLinesWithAbbreviation
({
abbreviation
:
'
ul>li.hello$*|t
'
});
if
(
!
promise
)
{
...
...
@@ -344,7 +344,7 @@ suite('Tests for Wrap with Abbreviations', () => {
function
testWrapWithAbbreviation
(
selections
:
Selection
[],
abbreviation
:
string
,
expectedContents
:
string
):
Thenable
<
any
>
{
return
withRandomFileEditor
(
htmlContentsForWrapTests
,
'
html
'
,
(
editor
,
doc
)
=>
{
return
withRandomFileEditor
(
htmlContentsForWrapTests
,
'
html
'
,
(
editor
,
_
)
=>
{
editor
.
selections
=
selections
;
const
promise
=
wrapWithAbbreviation
({
abbreviation
});
if
(
!
promise
)
{
...
...
extensions/emmet/src/toggleComment.ts
浏览文件 @
6ad61f01
...
...
@@ -19,14 +19,6 @@ export function toggleComment(): Thenable<boolean> | undefined {
return
;
}
const
editor
=
vscode
.
window
.
activeTextEditor
;
let
toggleCommentInternal
:
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
rootNode
:
Node
)
=>
vscode
.
TextEdit
[];
if
(
isStyleSheet
(
editor
.
document
.
languageId
))
{
toggleCommentInternal
=
toggleCommentStylesheet
;
}
else
{
toggleCommentInternal
=
toggleCommentHTML
;
}
let
rootNode
=
parseDocument
(
editor
.
document
);
if
(
!
rootNode
)
{
return
;
...
...
@@ -35,7 +27,7 @@ export function toggleComment(): Thenable<boolean> | undefined {
return
editor
.
edit
(
editBuilder
=>
{
let
allEdits
:
vscode
.
TextEdit
[][]
=
[];
editor
.
selections
.
reverse
().
forEach
(
selection
=>
{
let
edits
=
toggleCommentInternal
(
editor
.
document
,
selection
,
rootNode
!
);
let
edits
=
isStyleSheet
(
editor
.
document
.
languageId
)
?
toggleCommentStylesheet
(
selection
,
<
Stylesheet
>
rootNode
)
:
toggleCommentHTML
(
editor
.
document
,
selection
,
rootNode
!
);
if
(
edits
.
length
>
0
)
{
allEdits
.
push
(
edits
);
}
...
...
@@ -76,7 +68,7 @@ function toggleCommentHTML(document: vscode.TextDocument, selection: vscode.Sele
let
buffer
=
new
DocumentStreamReader
(
document
,
startNode
.
open
.
end
,
new
vscode
.
Range
(
startNode
.
open
.
end
,
startNode
.
close
.
start
));
let
cssRootNode
=
parseStylesheet
(
buffer
);
return
toggleCommentStylesheet
(
document
,
selection
,
cssRootNode
);
return
toggleCommentStylesheet
(
selection
,
cssRootNode
);
}
let
allNodes
:
Node
[]
=
getNodesInBetween
(
startNode
,
endNode
);
...
...
@@ -117,7 +109,7 @@ function getRangesToUnCommentHTML(node: Node, document: vscode.TextDocument): vs
return
unCommentTextEdits
;
}
function
toggleCommentStylesheet
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
rootNode
:
Stylesheet
):
vscode
.
TextEdit
[]
{
function
toggleCommentStylesheet
(
selection
:
vscode
.
Selection
,
rootNode
:
Stylesheet
):
vscode
.
TextEdit
[]
{
let
selectionStart
=
selection
.
isReversed
?
selection
.
active
:
selection
.
anchor
;
let
selectionEnd
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
...
...
extensions/emmet/src/updateImageSize.ts
浏览文件 @
6ad61f01
...
...
@@ -35,7 +35,7 @@ export function updateImageSize() {
return
Promise
.
all
(
allUpdatesPromise
).
then
((
updates
)
=>
{
return
editor
.
edit
(
builder
=>
{
updates
.
forEach
(
update
=>
{
update
!
.
forEach
((
textEdit
:
TextEdit
)
=>
{
update
.
forEach
((
textEdit
:
TextEdit
)
=>
{
builder
.
replace
(
textEdit
.
range
,
textEdit
.
newText
);
});
});
...
...
@@ -46,7 +46,7 @@ export function updateImageSize() {
/**
* Updates image size of context tag of HTML model
*/
function
updateImageSizeHTML
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
|
undefined
>
{
function
updateImageSizeHTML
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
>
{
const
imageNode
=
getImageHTMLNode
(
editor
,
position
);
const
src
=
imageNode
&&
getImageSrcHTML
(
imageNode
);
...
...
@@ -64,11 +64,12 @@ function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<Te
if
(
img
&&
getImageSrcHTML
(
img
)
===
src
)
{
return
updateHTMLTag
(
editor
,
img
,
size
.
width
,
size
.
height
);
}
return
[];
})
.
catch
(
err
=>
{
console
.
warn
(
'
Error while updating image size:
'
,
err
);
return
[];
});
}
function
updateImageSizeStyleTag
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
|
undefined
>
{
function
updateImageSizeStyleTag
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
>
{
const
getPropertyInsiderStyleTag
=
(
editor
:
TextEditor
):
Property
|
null
=>
{
const
rootNode
=
parseDocument
(
editor
.
document
);
const
currentNode
=
<
HtmlNode
>
getNode
(
rootNode
,
position
,
true
);
...
...
@@ -86,14 +87,14 @@ function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promis
return
updateImageSizeCSS
(
editor
,
position
,
getPropertyInsiderStyleTag
);
}
function
updateImageSizeCSSFile
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
|
undefined
>
{
function
updateImageSizeCSSFile
(
editor
:
TextEditor
,
position
:
Position
):
Promise
<
TextEdit
[]
>
{
return
updateImageSizeCSS
(
editor
,
position
,
getImageCSSNode
);
}
/**
* Updates image size of context rule of stylesheet model
*/
function
updateImageSizeCSS
(
editor
:
TextEditor
,
position
:
Position
,
fetchNode
:
(
editor
:
TextEditor
,
position
:
Position
)
=>
Property
|
null
):
Promise
<
TextEdit
[]
|
undefined
>
{
function
updateImageSizeCSS
(
editor
:
TextEditor
,
position
:
Position
,
fetchNode
:
(
editor
:
TextEditor
,
position
:
Position
)
=>
Property
|
null
):
Promise
<
TextEdit
[]
>
{
const
node
=
fetchNode
(
editor
,
position
);
const
src
=
node
&&
getImageSrcCSS
(
node
,
position
);
...
...
@@ -103,13 +104,14 @@ function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (
return
locateFile
(
path
.
dirname
(
editor
.
document
.
fileName
),
src
)
.
then
(
getImageSize
)
.
then
((
size
:
any
):
TextEdit
[]
|
undefined
=>
{
.
then
((
size
:
any
):
TextEdit
[]
=>
{
// since this action is asynchronous, we have to ensure that editor wasn’t
// changed and user didn’t moved caret outside <img> node
const
prop
=
fetchNode
(
editor
,
position
);
if
(
prop
&&
getImageSrcCSS
(
prop
,
position
)
===
src
)
{
return
updateCSSNode
(
editor
,
prop
,
size
.
width
,
size
.
height
);
}
return
[];
})
.
catch
(
err
=>
{
console
.
warn
(
'
Error while updating image size:
'
,
err
);
return
[];
});
}
...
...
@@ -261,12 +263,14 @@ function findUrlToken(node: Property, pos: Position): CssToken | undefined {
url
=
token
;
return
false
;
}
return
true
;
});
if
(
url
)
{
return
url
;
}
}
return
;
}
/**
...
...
extensions/emmet/src/util.ts
浏览文件 @
6ad61f01
...
...
@@ -114,6 +114,7 @@ export function getEmmetMode(language: string, excludedLanguages: string[]): str
if
(
emmetModes
.
indexOf
(
language
)
>
-
1
)
{
return
language
;
}
return
;
}
/**
...
...
@@ -259,7 +260,7 @@ export function parsePartialStylesheet(document: vscode.TextDocument, position:
try
{
return
parseStylesheet
(
new
DocumentStreamReader
(
document
,
startPosition
,
new
vscode
.
Range
(
startPosition
,
endPosition
)));
}
catch
(
e
)
{
return
;
}
}
...
...
@@ -351,7 +352,7 @@ export function getDeepestNode(node: Node | undefined): Node | undefined {
return
undefined
;
}
export
function
findNextWord
(
propertyValue
:
string
,
pos
:
number
):
[
number
,
number
]
{
export
function
findNextWord
(
propertyValue
:
string
,
pos
:
number
):
[
number
|
undefined
,
number
|
undefined
]
{
let
foundSpace
=
pos
===
-
1
;
let
foundStart
=
false
;
...
...
@@ -389,7 +390,7 @@ export function findNextWord(propertyValue: string, pos: number): [number, numbe
return
[
newSelectionStart
,
newSelectionEnd
];
}
export
function
findPrevWord
(
propertyValue
:
string
,
pos
:
number
):
[
number
,
number
]
{
export
function
findPrevWord
(
propertyValue
:
string
,
pos
:
number
):
[
number
|
undefined
,
number
|
undefined
]
{
let
foundSpace
=
pos
===
propertyValue
.
length
;
let
foundStart
=
false
;
...
...
@@ -511,12 +512,13 @@ export function getEmmetConfiguration(syntax: string) {
* Itereates by each child, as well as nested child's children, in their order
* and invokes `fn` for each. If `fn` function returns `false`, iteration stops
*/
export
function
iterateCSSToken
(
token
:
CssToken
,
fn
:
(
x
:
any
)
=>
any
)
{
export
function
iterateCSSToken
(
token
:
CssToken
,
fn
:
(
x
:
any
)
=>
any
)
:
boolean
{
for
(
let
i
=
0
,
il
=
token
.
size
;
i
<
il
;
i
++
)
{
if
(
fn
(
token
.
item
(
i
))
===
false
||
iterateCSSToken
(
token
.
item
(
i
),
fn
)
===
false
)
{
return
false
;
}
}
return
true
;
}
/**
...
...
@@ -530,7 +532,7 @@ export function getCssPropertyFromRule(rule: Rule, name: string): Property | und
* Returns css property under caret in given editor or `null` if such node cannot
* be found
*/
export
function
getCssPropertyFromDocument
(
editor
:
vscode
.
TextEditor
,
position
:
vscode
.
Position
):
Property
|
null
|
undefined
{
export
function
getCssPropertyFromDocument
(
editor
:
vscode
.
TextEditor
,
position
:
vscode
.
Position
):
Property
|
null
{
const
rootNode
=
parseDocument
(
editor
.
document
);
const
node
=
getNode
(
rootNode
,
position
,
true
);
...
...
@@ -548,6 +550,8 @@ export function getCssPropertyFromDocument(editor: vscode.TextEditor, position:
const
node
=
getNode
(
rootNode
,
position
,
true
);
return
(
node
&&
node
.
type
===
'
property
'
)
?
<
Property
>
node
:
null
;
}
return
null
;
}
...
...
@@ -569,6 +573,7 @@ export function getEmbeddedCssNodeIfAny(document: vscode.TextDocument, currentNo
}
}
}
return
;
}
export
function
isStyleAttribute
(
currentNode
:
Node
|
null
,
position
:
vscode
.
Position
):
boolean
{
...
...
extensions/emmet/tsconfig.json
浏览文件 @
6ad61f01
{
"compilerOptions"
:
{
"target"
:
"es6"
,
"target"
:
"es2017"
,
"module"
:
"commonjs"
,
"lib"
:
[
"es2016"
"es6"
,
"es2015.promise"
],
"module"
:
"commonjs"
,
"outDir"
:
"./out"
,
"noImplicitReturns"
:
true
,
"noUnusedLocals"
:
true
,
"noUnusedParameters"
:
true
,
"strictNullChecks"
:
true
},
"exclude"
:
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录