Skip to content

Commit 6c5633a

Browse files
authored
(fix) various emmet fixes (#1245)
- add back completion participant behavior, using old emmet code that was thrown out as inspiration. That way emmet completions don't show up in weird places - don't show completions when user disabled emmet completions through emmet VS Code settings - synchronize updates to VS Code emmet settings with language server
1 parent b1b0484 commit 6c5633a

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

packages/language-server/src/plugins/css/CSSPlugin.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,42 @@ export class CSSPlugin
219219
}
220220

221221
const lang = getLanguageService(type);
222-
const emmetResults: CompletionList = (this.configManager.getConfig().css.completions
223-
.emmet &&
224-
doEmmetComplete(
225-
cssDocument,
226-
cssDocument.getGeneratedPosition(position),
227-
getLanguage(type),
228-
this.configManager.getEmmetConfig()
229-
)) || {
222+
let emmetResults: CompletionList = {
230223
isIncomplete: false,
231224
items: []
232225
};
226+
if (
227+
this.configManager.getConfig().css.completions.emmet &&
228+
this.configManager.getEmmetConfig().showExpandedAbbreviation !== 'never'
229+
) {
230+
lang.setCompletionParticipants([
231+
{
232+
onCssProperty: (context) => {
233+
if (context?.propertyName) {
234+
emmetResults =
235+
doEmmetComplete(
236+
cssDocument,
237+
cssDocument.getGeneratedPosition(position),
238+
getLanguage(type),
239+
this.configManager.getEmmetConfig()
240+
) || emmetResults;
241+
}
242+
},
243+
onCssPropertyValue: (context) => {
244+
if (context?.propertyValue) {
245+
emmetResults =
246+
doEmmetComplete(
247+
cssDocument,
248+
cssDocument.getGeneratedPosition(position),
249+
getLanguage(type),
250+
this.configManager.getEmmetConfig()
251+
) || emmetResults;
252+
}
253+
}
254+
}
255+
]);
256+
}
257+
233258
const results = lang.doComplete(
234259
cssDocument,
235260
cssDocument.getGeneratedPosition(position),

packages/language-server/src/plugins/html/HTMLPlugin.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,27 @@ export class HTMLPlugin
8888
return null;
8989
}
9090

91-
const emmetResults: CompletionList = (this.configManager.getConfig().html.completions
92-
.emmet &&
93-
doEmmetComplete(document, position, 'html', this.configManager.getEmmetConfig())) || {
91+
let emmetResults: CompletionList = {
9492
isIncomplete: false,
9593
items: []
9694
};
95+
if (
96+
this.configManager.getConfig().html.completions.emmet &&
97+
this.configManager.getEmmetConfig().showExpandedAbbreviation !== 'never'
98+
) {
99+
this.lang.setCompletionParticipants([
100+
{
101+
onHtmlContent: () =>
102+
(emmetResults =
103+
doEmmetComplete(
104+
document,
105+
position,
106+
'html',
107+
this.configManager.getEmmetConfig()
108+
) || emmetResults)
109+
}
110+
]);
111+
}
97112

98113
const results = this.isInComponentTag(html, document, position)
99114
? // Only allow emmet inside component element tags.

packages/svelte-vscode/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ export function activate(context: ExtensionContext) {
8989
documentSelector: [{ scheme: 'file', language: 'svelte' }],
9090
revealOutputChannelOn: RevealOutputChannelOn.Never,
9191
synchronize: {
92+
// TODO deprecated, rework upon next VS Code minimum version bump
9293
configurationSection: [
9394
'svelte',
95+
'prettier',
96+
'emmet',
9497
'javascript',
9598
'typescript',
96-
'prettier',
9799
'css',
98100
'less',
99101
'scss'

0 commit comments

Comments
 (0)