Skip to content

Commit

Permalink
Add initial implementation
Browse files Browse the repository at this point in the history
Closes GH-1.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>

Co-authored-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
remcohaszing and wooorm committed Aug 28, 2022
1 parent 5754b0b commit 2a72fed
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v3
strategy:
matrix:
node:
- lts/fermium
- node
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
*.d.ts
*.log
*.tgz
coverage/
node_modules/
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/
*.md
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {toPoint, toPosition, fromPoint, fromPosition} from './lib/index.js'
58 changes: 58 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Position} UnistPosition
* @typedef {import('vscode-languageserver-types').Position} LspPosition
* @typedef {import('vscode-languageserver-types').Range} Range
*/

/**
* Convert a unist point to an LSP position.
*
* @param {Point} point The unist point to convert.
* @returns {LspPosition} The point converted to an LSP position.
*/
export function fromPoint(point) {
return {
character: point.column - 1,
line: point.line - 1
}
}

/**
* Convert an LSP position to a unist point.
*
* @param {LspPosition} position The LSP position to convert.
* @returns {Point} The position converted to a unist point.
*/
export function toPoint(position) {
return {
column: position.character + 1,
line: position.line + 1
}
}

/**
* Convert a unist position to an LSP range.
*
* @param {UnistPosition} position The unist position to convert.
* @returns {Range} The position converted to an LSP range.
*/
export function fromPosition(position) {
return {
start: fromPoint(position.start),
end: fromPoint(position.end)
}
}

/**
* Convert an LSP range to a unist position.
*
* @param {Range} range The LSP range to convert.
* @returns {UnistPosition} The range converted to a unist position.
*/
export function toPosition(range) {
return {
start: toPoint(range.start),
end: toPoint(range.end)
}
}
74 changes: 74 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "unist-lsp",
"version": "0.0.0",
"description": "Utility to convert between unist and language server protocol",
"license": "MIT",
"keywords": [
"unist",
"util",
"utility",
"lsp",
"language-server-protocol"
],
"repository": "syntax-tree/unist-lsp",
"bugs": "https://github.com/syntax-tree/unist-lsp/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Remco Haszing <remcohaszing@gmail.com>",
"contributors": [
"Remco Haszing <remcohaszing@gmail.com>"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/unist": "^2.0.0",
"vscode-languageserver-types": "^3.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.52.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc && type-coverage",
"format": "remark . -qfo && prettier -w . --loglevel warn && xo --fix",
"test-api": "node test/index.js",
"test-coverage": "c8 --100 --reporter lcov node test/index.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

0 comments on commit 2a72fed

Please sign in to comment.