Skip to content

Add support for nullish values in points #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
export function fromPoint(point) {
return {
character: point.column - 1,
line: point.line - 1
character: point.column ? point.column - 1 : 0,
line: point.line ? point.line - 1 : 0
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ test('fromPoint', async () => {
{line: 42, character: 99},
'should convert unist points to LSP positions'
)

assert.deepEqual(
fromPoint({line: 0, column: 0}),
{line: 0, character: 0},
'should convert unist points with zero values'
)

assert.deepEqual(
// @ts-expect-error We test invalid user input here.
fromPoint({line: null, column: null}),
{line: 0, character: 0},
'should convert unist points with null values'
)
})

test('toPoint', async () => {
Expand Down