Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/services/cssCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class CSSCompletion {
}
}
}
this.getValueEnumProposals(entry, existingNode, result);
this.getValueEnumProposals(this.getValueEnumEntry(entry, node), existingNode, result);
this.getCSSWideKeywordProposals(entry, existingNode, result);
this.getUnitProposals(entry, existingNode, result);
} else {
Expand All @@ -362,6 +362,21 @@ export class CSSCompletion {
return result;
}

private getValueEnumEntry(entry: IPropertyData, declaration: nodes.Declaration): IPropertyData {
if (entry.values || !entry.syntax || typeof declaration.colonPosition !== 'number') {
return entry;
}

const match = /^\s*<'([^']+)'>\s+<'([^']+)'>\?\s*$/.exec(entry.syntax);
if (!match) {
return entry;
}

const completedValue = this.textDocument.getText().substring(declaration.colonPosition + 1, this.offset - this.currentWord.length).trim();
const referencedProperty = this.cssDataManager.getProperty(completedValue ? match[2] : match[1]);
return referencedProperty || entry;
}

public getValueEnumProposals(entry: IPropertyData | IDescriptorData, existingNode: nodes.Node | null, result: CompletionList): CompletionList {
if (entry.values) {
for (const value of entry.values) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/css/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ suite('CSS - Completion', () => {
{ label: 'space-evenly', resultText: '#id { justify-content: space-evenly' }
]
});
await testCompletionFor('body { place-items: |', {
items: [
{ label: 'center', resultText: 'body { place-items: center' },
{ label: 'auto', notAvailable: true }
]
});
await testCompletionFor('body { place-items: center |', {
items: [
{ label: 'auto', resultText: 'body { place-items: center auto' }
]
});
await testCompletionFor('.foo { te:n| }', {
items: [
{ label: 'n', notAvailable: true }
Expand Down