Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1809bb2f
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,发现更多精彩内容 >>
提交
1809bb2f
编写于
6月 19, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use emmet.syntaxProfiles in new emmet
上级
70b02d17
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
60 deletion
+70
-60
extensions/emmet/package.json
extensions/emmet/package.json
+1
-13
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+32
-20
extensions/emmet/src/emmetCompletionProvider.ts
extensions/emmet/src/emmetCompletionProvider.ts
+8
-3
extensions/emmet/src/extension.ts
extensions/emmet/src/extension.ts
+29
-24
未找到文件。
extensions/emmet/package.json
浏览文件 @
1809bb2f
...
...
@@ -15,19 +15,7 @@
"url"
:
"https://github.com/Microsoft/vscode-emmet"
},
"activationEvents"
:
[
"onLanguage:html"
,
"onLanguage:jade"
,
"onLanguage:slim"
,
"onLanguage:haml"
,
"onLanguage:xml"
,
"onLanguage:xsl"
,
"onLanguage:css"
,
"onLanguage:scss"
,
"onLanguage:sass"
,
"onLanguage:less"
,
"onLanguage:stylus"
,
"onLanguage:javascriptreact"
,
"onLanguage:typescriptreact"
"*"
],
"main"
:
"./out/extension"
,
"contributes"
:
{
...
...
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
1809bb2f
...
...
@@ -49,39 +49,51 @@ export function expandAbbreviation() {
return
;
}
let
syntax
=
getSyntax
(
editor
.
document
);
let
output
=
expandAbbreviationHelper
(
syntax
,
editor
.
document
,
editor
.
selection
);
let
mappedSyntax
=
false
;
let
emmetConfig
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
);
if
(
emmetConfig
&&
emmetConfig
[
'
syntaxProfiles
'
])
{
let
syntaxProfiles
=
emmetConfig
[
'
syntaxProfiles
'
];
if
(
typeof
syntaxProfiles
[
syntax
]
===
'
string
'
)
{
syntax
=
syntaxProfiles
[
syntax
];
mappedSyntax
=
true
;
}
}
let
output
=
expandAbbreviationHelper
(
syntax
,
editor
.
document
,
editor
.
selection
,
mappedSyntax
);
if
(
output
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
output
.
expandedText
),
output
.
rangeToReplac
e
);
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
output
.
expandedText
),
output
.
abbreviationRang
e
);
}
}
export
interface
ExpandAbbreviationHelperOutput
{
expandedText
:
string
;
rangeToReplac
e
:
vscode
.
Range
;
abbreviationRang
e
:
vscode
.
Range
;
abbreviation
:
string
;
syntax
:
string
;
}
/**
* Expands abbreviation at given range in the given document
* @param syntax
* @param document
* @param rangeToReplace
*/
export
function
expandAbbreviationHelper
(
syntax
:
string
,
document
:
vscode
.
TextDocument
,
rangeToReplace
:
vscode
.
Range
):
ExpandAbbreviationHelperOutput
{
let
parseContent
=
isStyleSheet
(
syntax
)
?
parseStylesheet
:
parse
;
let
rootNode
:
Node
=
parseContent
(
new
DocumentStreamReader
(
document
));
let
currentNode
=
getNode
(
rootNode
,
rangeToReplace
.
end
);
if
(
forceCssSyntax
(
syntax
,
currentNode
,
rangeToReplace
.
end
))
{
syntax
=
'
css
'
;
}
else
if
(
!
isValidLocationForEmmetAbbreviation
(
currentNode
,
syntax
,
rangeToReplace
.
end
))
{
return
;
* @param syntax string syntax to be used for expanding abbreviations
* @param document vscode.TextDocument
* @param abbreviationRange vscode.Range range of the abbreviation that needs to be expanded
* @param mappedSyntax Boolean Pass true if given document language was mapped to given syntax to get emmet abbreviation expansions.
* */
export
function
expandAbbreviationHelper
(
syntax
:
string
,
document
:
vscode
.
TextDocument
,
abbreviationRange
:
vscode
.
Range
,
mappedSyntax
:
boolean
):
ExpandAbbreviationHelperOutput
{
if
(
!
mappedSyntax
)
{
let
parseContent
=
isStyleSheet
(
syntax
)
?
parseStylesheet
:
parse
;
let
rootNode
:
Node
=
parseContent
(
new
DocumentStreamReader
(
document
));
let
currentNode
=
getNode
(
rootNode
,
abbreviationRange
.
end
);
if
(
forceCssSyntax
(
syntax
,
currentNode
,
abbreviationRange
.
end
))
{
syntax
=
'
css
'
;
}
else
if
(
!
isValidLocationForEmmetAbbreviation
(
currentNode
,
syntax
,
abbreviationRange
.
end
))
{
return
;
}
}
let
abbreviation
=
document
.
getText
(
rangeToReplac
e
);
if
(
rangeToReplac
e
.
isEmpty
)
{
[
rangeToReplace
,
abbreviation
]
=
extractAbbreviation
(
document
,
rangeToReplac
e
.
start
);
let
abbreviation
=
document
.
getText
(
abbreviationRang
e
);
if
(
abbreviationRang
e
.
isEmpty
)
{
[
abbreviationRange
,
abbreviation
]
=
extractAbbreviation
(
document
,
abbreviationRang
e
.
start
);
}
let
options
=
{
...
...
@@ -92,7 +104,7 @@ export function expandAbbreviationHelper(syntax: string, document: vscode.TextDo
};
let
expandedText
=
expand
(
abbreviation
,
options
);
return
{
expandedText
,
rangeToReplac
e
,
abbreviation
,
syntax
};
return
{
expandedText
,
abbreviationRang
e
,
abbreviation
,
syntax
};
}
/**
...
...
extensions/emmet/src/emmetCompletionProvider.ts
浏览文件 @
1809bb2f
...
...
@@ -13,7 +13,12 @@ const field = (index, placeholder) => `\${${index}${placeholder ? ':' + placehol
const
snippetCompletionsCache
=
new
Map
<
string
,
vscode
.
CompletionItem
[]
>
();
export
class
EmmetCompletionItemProvider
implements
vscode
.
CompletionItemProvider
{
private
_mappedSyntax
=
false
;
constructor
(
mappedSyntax
?:
boolean
)
{
if
(
mappedSyntax
)
{
this
.
_mappedSyntax
=
true
;
}
}
public
provideCompletionItems
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
token
:
vscode
.
CancellationToken
):
Thenable
<
vscode
.
CompletionList
>
{
if
(
!
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
useNewEmmet
'
])
{
...
...
@@ -23,12 +28,12 @@ export class EmmetCompletionItemProvider implements vscode.CompletionItemProvide
let
syntax
=
getSyntax
(
document
);
let
expandedAbbr
:
vscode
.
CompletionItem
;
if
(
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
showExpandedAbbreviation
'
])
{
let
output
:
ExpandAbbreviationHelperOutput
=
expandAbbreviationHelper
(
syntax
,
document
,
new
vscode
.
Range
(
position
,
position
));
let
output
:
ExpandAbbreviationHelperOutput
=
expandAbbreviationHelper
(
syntax
,
document
,
new
vscode
.
Range
(
position
,
position
)
,
this
.
_mappedSyntax
);
if
(
output
)
{
expandedAbbr
=
new
vscode
.
CompletionItem
(
output
.
abbreviation
);
expandedAbbr
.
insertText
=
new
vscode
.
SnippetString
(
output
.
expandedText
);
expandedAbbr
.
documentation
=
removeTabStops
(
output
.
expandedText
);
expandedAbbr
.
range
=
output
.
rangeToReplac
e
;
expandedAbbr
.
range
=
output
.
abbreviationRang
e
;
expandedAbbr
.
detail
=
'
Expand Emmet Abbreviation
'
;
syntax
=
output
.
syntax
;
}
...
...
extensions/emmet/src/extension.ts
浏览文件 @
1809bb2f
...
...
@@ -16,34 +16,39 @@ import { toggleComment } from './toggleComment';
import
{
fetchEditPoint
}
from
'
./editPoint
'
;
import
{
fetchSelectItem
}
from
'
./selectItem
'
;
interface
ISupportedLanguageMode
{
id
:
string
;
triggerCharacters
:
string
[];
}
const
LANGUAGE_MODES
:
ISupportedLanguageMode
[]
=
[
{
id
:
'
html
'
,
triggerCharacters
:
[
'
!
'
,
'
.
'
,
'
}
'
]
},
{
id
:
'
jade
'
,
triggerCharacters
:
[
'
!
'
,
'
.
'
,
'
}
'
]
},
{
id
:
'
slim
'
,
triggerCharacters
:
[
'
!
'
,
'
.
'
,
'
}
'
]
},
{
id
:
'
haml
'
,
triggerCharacters
:
[
'
!
'
,
'
.
'
,
'
}
'
]
},
{
id
:
'
xml
'
,
triggerCharacters
:
[
'
.
'
,
'
}
'
]
},
{
id
:
'
xsl
'
,
triggerCharacters
:
[
'
.
'
,
'
}
'
]
},
{
id
:
'
javascriptreact
'
,
triggerCharacters
:
[
'
.
'
]
},
{
id
:
'
typescriptreact
'
,
triggerCharacters
:
[
'
.
'
]
},
{
id
:
'
css
'
,
triggerCharacters
:
[
'
:
'
]
},
{
id
:
'
scss
'
,
triggerCharacters
:
[
'
:
'
]
},
{
id
:
'
sass
'
,
triggerCharacters
:
[
'
:
'
]
},
{
id
:
'
less
'
,
triggerCharacters
:
[
'
:
'
]
},
{
id
:
'
stylus
'
,
triggerCharacters
:
[
'
:
'
]
}
];
const
LANGUAGE_MODES
:
Object
=
{
'
html
'
:
[
'
!
'
,
'
.
'
,
'
}
'
],
'
jade
'
:
[
'
!
'
,
'
.
'
,
'
}
'
],
'
slim
'
:
[
'
!
'
,
'
.
'
,
'
}
'
],
'
haml
'
:
[
'
!
'
,
'
.
'
,
'
}
'
],
'
xml
'
:
[
'
.
'
,
'
}
'
],
'
xsl
'
:
[
'
.
'
,
'
}
'
],
'
javascriptreact
'
:
[
'
.
'
],
'
typescriptreact
'
:
[
'
.
'
],
'
css
'
:
[
'
:
'
],
'
scss
'
:
[
'
:
'
],
'
sass
'
:
[
'
:
'
],
'
less
'
:
[
'
:
'
],
'
stylus
'
:
[
'
:
'
]
};
export
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
let
completionProvider
=
new
EmmetCompletionItemProvider
();
for
(
let
language
of
LANGUAGE_MODES
)
{
const
provider
=
vscode
.
languages
.
registerCompletionItemProvider
(
{
language
:
language
.
id
},
completionProvider
,
...
language
.
triggerCharacters
);
Object
.
keys
(
LANGUAGE_MODES
).
forEach
(
language
=>
{
const
provider
=
vscode
.
languages
.
registerCompletionItemProvider
(
language
,
completionProvider
,
...
LANGUAGE_MODES
[
language
]
);
context
.
subscriptions
.
push
(
provider
);
});
let
completionProviderForMappedSyntax
=
new
EmmetCompletionItemProvider
(
true
);
let
emmetConfig
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
);
if
(
emmetConfig
&&
emmetConfig
[
'
syntaxProfiles
'
])
{
let
syntaxProfiles
=
emmetConfig
[
'
syntaxProfiles
'
];
Object
.
keys
(
syntaxProfiles
).
forEach
(
syntax
=>
{
if
(
typeof
syntaxProfiles
[
syntax
]
===
'
string
'
&&
LANGUAGE_MODES
[
syntaxProfiles
[
syntax
]])
{
const
provider
=
vscode
.
languages
.
registerCompletionItemProvider
(
syntax
,
completionProviderForMappedSyntax
,
...
LANGUAGE_MODES
[
syntaxProfiles
[
syntax
]]);
context
.
subscriptions
.
push
(
provider
);
}
});
}
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
emmet.wrapWithAbbreviation
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录