Skip to content

Commit

Permalink
Merge pull request #2211 from alixander/lsp-get-board-3
Browse files Browse the repository at this point in the history
d2lsp: getboardatposition edge case
  • Loading branch information
alixander authored Nov 13, 2024
2 parents 10b0190 + 5b13afa commit 7b9f2d1
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 7b9f2d1

Please sign in to comment.