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
24 changes: 22 additions & 2 deletions 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);
Comment thread
NgoQuocViet2001 marked this conversation as resolved.
Resolved
this.getValueEnumProposals(entry, existingNode, result, node);
this.getCSSWideKeywordProposals(entry, existingNode, result);
this.getUnitProposals(entry, existingNode, result);
} else {
Expand All @@ -362,7 +362,27 @@ export class CSSCompletion {
return result;
}

public getValueEnumProposals(entry: IPropertyData | IDescriptorData, existingNode: nodes.Node | null, result: CompletionList): CompletionList {
private getValueEnumEntry(entry: IPropertyData | IDescriptorData, declaration: nodes.Declaration): IPropertyData | IDescriptorData {
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, declaration?: nodes.Declaration): CompletionList {
if (declaration) {
// A shorthand with no values of its own delegates to the longhand the
// caret sits on, so resolve that before reading `values` below.
entry = this.getValueEnumEntry(entry, declaration);
}
if (entry.values) {
for (const value of entry.values) {
let insertString = value.name;
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