Merge pull request #2211 from alixander/lsp-get-board-3

d2lsp: getboardatposition edge case
This commit is contained in:
Alexander Wang 2024-11-13 11:15:46 -07:00 committed by GitHub
commit 7b9f2d151c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 {