d2lsp: getboardatposition edge case

This commit is contained in:
Alexander Wang 2024-11-13 11:15:28 -07:00
parent 10b0190f9b
commit 5b13afa6da
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
2 changed files with 18 additions and 0 deletions

View file

@ -143,6 +143,11 @@ func getBoardPathAtPosition(m d2ast.Map, currPath []string, pos d2ast.Position)
return deeperPath return deeperPath
} }
// We're in between boards, e.g. layers.x.scenarios
// Which means, there's no board at this position
if len(newPath)%2 == 1 {
return nil
}
// Nothing deeper matched but we're in this map's range, return current path // Nothing deeper matched but we're in this map's range, return current path
return newPath return newPath
} }

View file

@ -291,6 +291,19 @@ layers: {
position: d2ast.Position{Line: 3, Column: 2}, position: d2ast.Position{Line: 3, Column: 2},
want: []string{"layers", "basic"}, want: []string{"layers", "basic"},
}, },
{
name: "cursor in between",
fs: map[string]string{
"index.d2": `
layers: {
basic: {
}
}`,
},
path: "index.d2",
position: d2ast.Position{Line: 2, Column: 2},
want: nil,
},
} }
for _, tt := range tests { for _, tt := range tests {