Merge pull request #2266 from alixander/fix-lsp-style-suggest
d2lsp: fix nested style map
This commit is contained in:
commit
ebeb8baf08
2 changed files with 44 additions and 5 deletions
|
|
@ -42,18 +42,21 @@ func GetCompletionItems(text string, line, column int) ([]CompletionItem, error)
|
||||||
case "shape", "shape:":
|
case "shape", "shape:":
|
||||||
return getShapeCompletions(), nil
|
return getShapeCompletions(), nil
|
||||||
case "shadow", "3d", "multiple", "animated", "bold", "italic", "underline", "filled", "double-border",
|
case "shadow", "3d", "multiple", "animated", "bold", "italic", "underline", "filled", "double-border",
|
||||||
"shadow:", "3d:", "multiple:", "animated:", "bold:", "italic:", "underline:", "filled:", "double-border:":
|
"shadow:", "3d:", "multiple:", "animated:", "bold:", "italic:", "underline:", "filled:", "double-border:",
|
||||||
|
"style.shadow:", "style.3d:", "style.multiple:", "style.animated:", "style.bold:", "style.italic:", "style.underline:", "style.filled:", "style.double-border:":
|
||||||
return getBooleanCompletions(), nil
|
return getBooleanCompletions(), nil
|
||||||
case "fill-pattern", "fill-pattern:":
|
case "fill-pattern", "fill-pattern:", "style.fill-pattern:":
|
||||||
return getFillPatternCompletions(), nil
|
return getFillPatternCompletions(), nil
|
||||||
case "text-transform", "text-transform:":
|
case "text-transform", "text-transform:", "style.text-transform:":
|
||||||
return getTextTransformCompletions(), nil
|
return getTextTransformCompletions(), nil
|
||||||
case "opacity", "stroke-width", "stroke-dash", "border-radius", "font-size",
|
case "opacity", "stroke-width", "stroke-dash", "border-radius", "font-size",
|
||||||
"stroke", "fill", "font-color":
|
"stroke", "fill", "font-color":
|
||||||
return getValueCompletions(keyword), nil
|
return getValueCompletions(keyword), nil
|
||||||
case "opacity:", "stroke-width:", "stroke-dash:", "border-radius:", "font-size:",
|
case "opacity:", "stroke-width:", "stroke-dash:", "border-radius:", "font-size:",
|
||||||
"stroke:", "fill:", "font-color:":
|
"stroke:", "fill:", "font-color:",
|
||||||
return getValueCompletions(keyword[:len(keyword)-1]), nil
|
"style.opacity:", "style.stroke-width:", "style.stroke-dash:", "style.border-radius:", "style.font-size:",
|
||||||
|
"style.stroke:", "style.fill:", "style.font-color:":
|
||||||
|
return getValueCompletions(strings.TrimSuffix(strings.TrimPrefix(keyword, "style."), ":")), nil
|
||||||
case "width", "height", "top", "left":
|
case "width", "height", "top", "left":
|
||||||
return getValueCompletions(keyword), nil
|
return getValueCompletions(keyword), nil
|
||||||
case "width:", "height:", "top:", "left:":
|
case "width:", "height:", "top:", "left:":
|
||||||
|
|
@ -142,6 +145,9 @@ func getKeywordContext(text string, m *d2ast.Map, line, column int) string {
|
||||||
if _, isBoard := d2ast.BoardKeywords[firstPart]; isBoard {
|
if _, isBoard := d2ast.BoardKeywords[firstPart]; isBoard {
|
||||||
firstPart = ""
|
firstPart = ""
|
||||||
}
|
}
|
||||||
|
if firstPart == "classes" {
|
||||||
|
firstPart = ""
|
||||||
|
}
|
||||||
|
|
||||||
_, isHolder := d2ast.ReservedKeywordHolders[firstPart]
|
_, isHolder := d2ast.ReservedKeywordHolders[firstPart]
|
||||||
if !isHolder {
|
if !isHolder {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,30 @@ func TestGetCompletionItems(t *testing.T) {
|
||||||
column: 8,
|
column: 8,
|
||||||
want: getStyleCompletions(),
|
want: getStyleCompletions(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "classes shapes",
|
||||||
|
text: `classes: {
|
||||||
|
goal: {
|
||||||
|
shape:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
line: 2,
|
||||||
|
column: 10,
|
||||||
|
want: getShapeCompletions(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nested style map suggestions",
|
||||||
|
text: `a: {
|
||||||
|
style: {
|
||||||
|
3d:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
line: 2,
|
||||||
|
column: 7,
|
||||||
|
want: getBooleanCompletions(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "3d style map suggestions",
|
name: "3d style map suggestions",
|
||||||
text: `a.style: {
|
text: `a.style: {
|
||||||
|
|
@ -279,6 +303,15 @@ layers: {
|
||||||
column: 16,
|
column: 16,
|
||||||
want: getShapeCompletions(),
|
want: getShapeCompletions(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "shape 2 suggestions",
|
||||||
|
text: `a: {
|
||||||
|
shape:
|
||||||
|
}`,
|
||||||
|
line: 1,
|
||||||
|
column: 8,
|
||||||
|
want: getShapeCompletions(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue