Skip to content

Commit 3d87ca1

Browse files
samiyacdevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
Fix code completions generated in Styles pane
This CL updates the generated text to be as per the valid properties - this will remove any inconsistencies between what is shown and what is accepted This CL also adds `}` as a stop sequence This CL also updates removePrompt impl to clear entire AI suggestion instead of just the value ghost text Bug: 502459959 Change-Id: I5eeda4c27f4936282e6ecfc7ed8feb26dd109255 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7806814 Auto-Submit: Samiya Caur <samiyac@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Samiya Caur <samiyac@chromium.org>
1 parent bbba9c4 commit 3d87ca1

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

front_end/panels/elements/StylePropertyTreeElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3515,7 +3515,7 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
35153515
if (this.prompt) {
35163516
this.prompt.detach();
35173517
this.prompt = null;
3518-
this.#clearGhostTextInValue();
3518+
this.section().activeAiSuggestion = undefined;
35193519
}
35203520
}
35213521

front_end/panels/elements/StylesAiCodeCompletionProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ export class StylesAiCodeCompletionProvider {
5555
// early return as this means that code completion was previously setup
5656
return;
5757
}
58+
// Adding '}' as a stop sequence so that suggestion is limited to properties for a given style section
59+
const stopSequences = ['}'];
60+
if (this.#aiCodeCompletionConfig.completionContext.stopSequences) {
61+
stopSequences.push(...this.#aiCodeCompletionConfig.completionContext.stopSequences);
62+
}
5863
this.#aiCodeCompletion = new AiCodeCompletion.AiCodeCompletion.AiCodeCompletion(
59-
{aidaClient: this.#aidaClient}, this.#aiCodeCompletionConfig.panel, undefined,
60-
this.#aiCodeCompletionConfig.completionContext.stopSequences);
64+
{aidaClient: this.#aidaClient}, this.#aiCodeCompletionConfig.panel, undefined, stopSequences);
6165
this.#aiCodeCompletionConfig.onFeatureEnabled();
6266
}
6367

front_end/panels/elements/StylesSidebarPane.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,9 +2268,18 @@ export class CSSPropertyPrompt extends UI.TextPrompt.TextPrompt {
22682268
if (!this.queryRange) {
22692269
this.queryRange = new TextUtils.TextRange.TextRange(0, 0, 0, this.text().length);
22702270
}
2271+
2272+
const properties = this.#getAiSuggestedProperties(args.text);
2273+
if (properties.length === 0) {
2274+
this.treeElement.section().activeAiSuggestion = undefined;
2275+
this.activeAiSuggestionInfo = undefined;
2276+
return;
2277+
}
2278+
2279+
const styleText = properties.map(p => `${p.name}: ${p.value};`).join(' ');
22712280
this.treeElement.section().activeAiSuggestion = {
2272-
text: args.text,
2273-
properties: this.#getAiSuggestedProperties(args.text),
2281+
text: styleText,
2282+
properties,
22742283
cursorPosition: args.from,
22752284
clearCachedRequest: args.clearCachedRequest,
22762285
cssProperty: this.treeElement.property,

0 commit comments

Comments
 (0)