8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- Convert positional info between [ unist] [ ] and [ language server protocol] [ ]
11
+ [ unist] [ ] utility to convert positional info between [ unist] [ ] and
12
+ [ language server protocol] [ ]
12
13
13
14
## Contents
14
15
@@ -35,13 +36,13 @@ This package is a utility that converts positional info between [unist][] and
35
36
36
37
## When should I use this?
37
38
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.
40
41
41
42
## Install
42
43
43
44
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] [ ] :
45
46
46
47
``` sh
47
48
npm install unist-util-lsp
@@ -55,7 +56,7 @@ import {
55
56
toPosition ,
56
57
fromPoint ,
57
58
fromPosition ,
58
- } from ' https://esm.sh/unist-util-lsp@?0 '
59
+ } from ' https://esm.sh/unist-util-lsp@?1 '
59
60
```
60
61
61
62
In browsers with [ ` esm.sh ` ] [ esmsh ] :
@@ -67,7 +68,7 @@ In browsers with [`esm.sh`][esmsh]:
67
68
toPosition ,
68
69
fromPoint ,
69
70
fromPosition ,
70
- } from ' https://esm.sh/unist-util-lsp@?0 '
71
+ } from ' https://esm.sh/unist-util-lsp@?1 '
71
72
</script >
72
73
```
73
74
@@ -97,7 +98,7 @@ console.log(range)
97
98
98
99
const position = toPosition (range)
99
100
100
- console .log (range )
101
+ console .log (position )
101
102
102
103
const startPosition = fromPoint (mdast .position .start )
103
104
@@ -113,39 +114,77 @@ console.log(startPoint)
113
114
``` js
114
115
{
115
116
start: { line: 1 , column: 1 , offset: 0 },
116
- end: { line: 1 , column: 20 , offset: 19 }
117
+ end: { line: 2 , column: 1 , offset: 20 }
117
118
}
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 } }
120
121
{ character: 0 , line: 0 }
121
122
{ column: 1 , line: 1 }
122
123
```
123
124
124
125
## API
125
126
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 ] .
128
130
There is no default export.
129
131
130
132
### ` fromPoint(point) `
131
133
132
134
Turn a unist point into a language server protocol position.
133
135
136
+ ###### Parameters
137
+
138
+ * ` point ` ([ ` Point ` ] [ point ] )
139
+ — the unist point to convert
140
+
141
+ ###### Returns
142
+
143
+ The LSP position ([ ` LspPosition ` ] [ lspposition ] ).
144
+
134
145
### ` fromPosition(unistPosition) `
135
146
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 ] ).
137
157
138
158
### ` toPoint(lspPosition) `
139
159
140
160
Convert a language server protocol position to a unist point.
141
161
162
+ ###### Parameters
163
+
164
+ * ` lspPosition ` ([ ` LspPosition ` ] [ lspposition ] )
165
+ — the LSP position to convert
166
+
167
+ ###### Returns
168
+
169
+ The unist point ([ ` Point ` ] [ point ] ).
170
+
142
171
### ` toPosition(range) `
143
172
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 ] ).
145
183
146
184
## Types
147
185
148
186
This package is fully typed with [ TypeScript] [ ] .
187
+ It exports no additional types.
149
188
150
189
## Compatibility
151
190
@@ -228,3 +267,19 @@ abide by its terms.
228
267
[ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
229
268
230
269
[ 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