Skip to content

Commit f26f272

Browse files
committed
Add improved docs
1 parent d850e2e commit f26f272

File tree

2 files changed

+81
-26
lines changed

2 files changed

+81
-26
lines changed

lib/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77

88
/**
9-
* Convert a unist point to an LSP position.
9+
* Turn a unist point into a language server protocol position.
1010
*
1111
* @param {Point} point The unist point to convert.
12-
* @returns {LspPosition} The point converted to an LSP position.
12+
* @returns {LspPosition} The LSP position.
1313
*/
1414
export function fromPoint(point) {
1515
return {
@@ -21,26 +21,26 @@ export function fromPoint(point) {
2121
/**
2222
* Convert an LSP position to a unist point.
2323
*
24-
* @param {LspPosition} position The LSP position to convert.
25-
* @returns {Point} The position converted to a unist point.
24+
* @param {LspPosition} lspPosition The LSP position to convert.
25+
* @returns {Point} The unist point.
2626
*/
27-
export function toPoint(position) {
27+
export function toPoint(lspPosition) {
2828
return {
29-
column: position.character + 1,
30-
line: position.line + 1
29+
column: lspPosition.character + 1,
30+
line: lspPosition.line + 1
3131
}
3232
}
3333

3434
/**
3535
* Convert a unist position to an LSP range.
3636
*
37-
* @param {UnistPosition} position The unist position to convert.
38-
* @returns {Range} The position converted to an LSP range.
37+
* @param {UnistPosition} unistPosition The unist position to convert.
38+
* @returns {Range} The LSP range.
3939
*/
40-
export function fromPosition(position) {
40+
export function fromPosition(unistPosition) {
4141
return {
42-
start: fromPoint(position.start),
43-
end: fromPoint(position.end)
42+
start: fromPoint(unistPosition.start),
43+
end: fromPoint(unistPosition.end)
4444
}
4545
}
4646

readme.md

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
Convert positional info between [unist][] and [language server protocol][]
11+
[unist][] utility to convert positional info between [unist][] and
12+
[language server protocol][]
1213

1314
## Contents
1415

@@ -35,13 +36,13 @@ This package is a utility that converts positional info between [unist][] and
3536

3637
## When should I use this?
3738

38-
This project is useful when you are dealing with both unist ASTs and a language
39-
server.
39+
You can use this package when you are dealing with both unist ASTs and a
40+
language server.
4041

4142
## Install
4243

4344
This package is [ESM only][esm].
44-
In Node.js (version 14.14+, or 16.0+), install with [npm][]:
45+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4546

4647
```sh
4748
npm install unist-util-lsp
@@ -55,7 +56,7 @@ import {
5556
toPosition,
5657
fromPoint,
5758
fromPosition,
58-
} from 'https://esm.sh/unist-util-lsp@?0'
59+
} from 'https://esm.sh/unist-util-lsp@?1'
5960
```
6061

6162
In browsers with [`esm.sh`][esmsh]:
@@ -67,7 +68,7 @@ In browsers with [`esm.sh`][esmsh]:
6768
toPosition,
6869
fromPoint,
6970
fromPosition,
70-
} from 'https://esm.sh/unist-util-lsp@?0'
71+
} from 'https://esm.sh/unist-util-lsp@?1'
7172
</script>
7273
```
7374

@@ -97,7 +98,7 @@ console.log(range)
9798

9899
const position = toPosition(range)
99100

100-
console.log(range)
101+
console.log(position)
101102

102103
const startPosition = fromPoint(mdast.position.start)
103104

@@ -113,39 +114,77 @@ console.log(startPoint)
113114
```js
114115
{
115116
start: { line: 1, column: 1, offset: 0 },
116-
end: { line: 1, column: 20, offset: 19 }
117+
end: { line: 2, column: 1, offset: 20 }
117118
}
118-
{ start: { character: 0, line: 0 }, end: { character: 19, line: 0 } }
119-
{ start: { character: 0, line: 0 }, end: { character: 19, line: 0 } }
119+
{ start: { character: 0, line: 0 }, end: { character: 0, line: 1 } }
120+
{ start: { column: 1, line: 1 }, end: { column: 1, line: 2 } }
120121
{ character: 0, line: 0 }
121122
{ column: 1, line: 1 }
122123
```
123124

124125
## API
125126

126-
This package exports the identifiers `fromPoint`, `fromPosition`, `toPoint`,
127-
and `toPosition`.
127+
This package exports the identifiers [`fromPoint`][api-frompoint],
128+
[`fromPosition`][api-fromposition], [`toPoint`][api-topoint],
129+
and [`toPosition`][api-toposition].
128130
There is no default export.
129131

130132
### `fromPoint(point)`
131133

132134
Turn a unist point into a language server protocol position.
133135

136+
###### Parameters
137+
138+
* `point` ([`Point`][point])
139+
— the unist point to convert
140+
141+
###### Returns
142+
143+
The LSP position ([`LspPosition`][lspposition]).
144+
134145
### `fromPosition(unistPosition)`
135146

136-
Convert a unist position to a language server protocol range.
147+
Convert a unist position to an LSP range.
148+
149+
###### Parameters
150+
151+
* `unistPosition` ([`UnistPosition`][unistposition])
152+
— the unist position to convert
153+
154+
###### Returns
155+
156+
The LSP range ([`Range`][range]).
137157

138158
### `toPoint(lspPosition)`
139159

140160
Convert a language server protocol position to a unist point.
141161

162+
###### Parameters
163+
164+
* `lspPosition` ([`LspPosition`][lspposition])
165+
— the LSP position to convert
166+
167+
###### Returns
168+
169+
The unist point ([`Point`][point]).
170+
142171
### `toPosition(range)`
143172

144-
Convert a language server protocol range to a unist position.
173+
Convert an LSP range to a unist position.
174+
175+
###### Parameters
176+
177+
* `range` ([`Range`][range])
178+
— the LSP range to convert
179+
180+
###### Returns
181+
182+
The range converted to a unist position ([`UnistPosition`][unistposition]).
145183

146184
## Types
147185

148186
This package is fully typed with [TypeScript][].
187+
It exports no additional types.
149188

150189
## Compatibility
151190

@@ -228,3 +267,19 @@ abide by its terms.
228267
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
229268

230269
[unist]: https://github.com/syntax-tree/unist
270+
271+
[point]: https://github.com/syntax-tree/unist#point
272+
273+
[unistposition]: https://github.com/syntax-tree/unist#position
274+
275+
[lspposition]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
276+
277+
[range]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#range
278+
279+
[api-frompoint]: #frompointpoint
280+
281+
[api-fromposition]: #frompositionunistposition
282+
283+
[api-topoint]: #topointlspposition
284+
285+
[api-toposition]: #topositionrange

0 commit comments

Comments
 (0)