修代码补全

This commit is contained in:
2026-08-01 15:47:51 +02:00
parent 429ea367f3
commit 45fa2b9a27
18 changed files with 802 additions and 37 deletions
+26 -1
View File
@@ -76,7 +76,15 @@ function analyzeStartTag(
// Inside an attribute value?
for (const attr of el.attrs) {
if (attr.hasValue && offset >= attr.quoteStart && offset <= attr.quoteEnd) {
// An unterminated value (quoteEnd < 0) happens while the user is typing
// the opening quote of a new attribute value; it must still be treated as
// an attribute-value context so enum/ref/define completions show up.
if (
attr.hasValue &&
attr.quoteStart >= 0 &&
offset >= attr.quoteStart &&
(attr.quoteEnd < 0 || offset <= attr.quoteEnd)
) {
const start = attr.valueStart;
const prefix = offset > start ? text.slice(start, offset) : "";
return {
@@ -128,3 +136,20 @@ function empty(kind: ContextKind): CompletionContext {
existingAttrs: [],
};
}
/**
* Splits the typed prefix of a whitespace-separated list value (xs:list, e.g.
* bit flags such as Surfaces="GROUND WATER") into the token being edited and
* the offset of that token inside the prefix.
*
* "GROUND WA" -> { token: "WA", start: 7 }
* "GROUND " -> { token: "", start: 7 }
* "WA" -> { token: "WA", start: 0 }
*/
export function splitListValuePrefix(prefix: string): { token: string; start: number } {
let start = prefix.length;
while (start > 0 && !/\s/.test(prefix[start - 1])) {
start--;
}
return { token: prefix.slice(start), start };
}