New package: unist-lsp #80
-
I’ve started working on MDX intellisense today. It’s very raw, getting things up and running first. Anyway, I need to use functions that already exist in /**
* Convert a unist point to an LSP position.
*
* @param {import('unist').Point} point The point to convert
* @returns {import('vscode-languageserver-types').Position} The converted position
*/
export function unistPointToLspPosition(point) {
return {
character: point.column - 1,
line: point.line - 1,
}
}
/**
* Convert a LSP position to a unist point.
*
* @param {import('vscode-languageserver-types').Position} position The LSP position to convert.
* @returns {import('unist').Point} The converted unist point.
*/
export function lspPositionToUnistPoint(position) {
return {
column: position.character + 1,
line: position.line + 1,
}
}
/**
* Convert a unist position to an LSP range.
*
* @param {import('unist').Position} position The position to convert
* @returns {import('vscode-languageserver-types').Range} The converted range
*/
export function unistPositionToLspRange(position) {
return {
start: unistPointToLspPosition(position.start),
end: unistPointToLspPosition(position.end),
}
}
/**
* Convert a LSP range to a unist position.
*
* @param {import('vscode-languageserver-types').Range} range The LSP range to convert.
* @returns {import('unist').Position} The converted unist position.
*/
export function lspRangeToUnistPosition(range) {
return {
start: lspPositionToUnistPoint(range.start),
end: lspPositionToUnistPoint(range.end),
}
} It may be small, but I suggest to create a new package for this: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Sounds like two separate packages? Good idea otherwise! Need help? |
Beta Was this translation helpful? Give feedback.
-
This has been released as |
Beta Was this translation helpful? Give feedback.
This has been released as
unist-util-lsp
.