Skip to content

Commit

Permalink
d2lsp: getboardatposition edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Nov 13, 2024
1 parent 10b0190 commit 5b13afa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions d2lsp/d2lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func getBoardPathAtPosition(m d2ast.Map, currPath []string, pos d2ast.Position)
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
return newPath
}
Expand Down
13 changes: 13 additions & 0 deletions d2lsp/d2lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ layers: {
position: d2ast.Position{Line: 3, Column: 2},
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 {
Expand Down

0 comments on commit 5b13afa

Please sign in to comment.