Skip to content

Commit

Permalink
Update dependencies and dev dependencies
Browse files Browse the repository at this point in the history
The update of the  `find-up` dependency is held back, as it removes
support for Node.js 16.
  • Loading branch information
remcohaszing committed Apr 11, 2024
1 parent 677777c commit 7bee593
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 82 deletions.
22 changes: 12 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import path from 'node:path'
import {PassThrough} from 'node:stream'
import {fileURLToPath} from 'node:url'
import {fileURLToPath, pathToFileURL} from 'node:url'
import {findUp, pathExists} from 'find-up'
import {loadPlugin} from 'load-plugin'
import {engine} from 'unified-engine'
Expand Down Expand Up @@ -79,8 +79,8 @@ function vfileMessageToDiagnostic(message) {
message.fatal === true
? DiagnosticSeverity.Error
: message.fatal === false
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Information,
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Information,
message.ruleId || undefined,
message.source || undefined
)
Expand Down Expand Up @@ -196,7 +196,7 @@ export function createUnifiedLanguageServer({
try {
processor = /** @type {EngineOptions['processor']} */ (
await loadPlugin(processorName, {
cwd,
from: pathToFileURL(cwd + '/'),
key: processorSpecifier
})
)
Expand Down Expand Up @@ -290,15 +290,17 @@ export function createUnifiedLanguageServer({
let cwd
if (workspaces.size === 0) {
cwd = await findUp(
async (dir) => {
const pkgExists = await pathExists(path.join(dir, 'package.json'))
if (pkgExists) {
return dir
async (directory) => {
const packageExists = await pathExists(
path.join(directory, 'package.json')
)
if (packageExists) {
return directory
}

const gitExists = await pathExists(path.join(dir, '.git'))
const gitExists = await pathExists(path.join(directory, '.git'))
if (gitExists) {
return dir
return directory
}
},
{
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"dependencies": {
"find-up": "^6.0.0",
"load-plugin": "^5.0.0",
"load-plugin": "^6.0.0",
"unified-engine": "^11.0.0",
"unist-util-lsp": "^2.0.0",
"vfile": "^6.0.0",
Expand All @@ -42,15 +42,15 @@
},
"devDependencies": {
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"c8": "^9.0.0",
"prettier": "^3.0.0",
"remark": "^15.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unified": "^11.0.0",
"xo": "^0.56.0"
"xo": "^0.58.0"
},
"scripts": {
"prepack": "npm run build",
Expand Down
122 changes: 62 additions & 60 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ Create a **[language server][]** based on **[unified][]** ecosystems.

## Contents

* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`createUnifiedLanguageServer(options)`](#createunifiedlanguageserveroptions)
* [Examples](#examples)
* [Types](#types)
* [Language Server features](#language-server-features)
* [Watching files](#watching-files)
* [Requests](#requests)
* [Configuration](#configuration)
* [Compatibility](#compatibility)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`createUnifiedLanguageServer(options)`](#createunifiedlanguageserveroptions)
* [Examples](#examples)
* [Types](#types)
* [Language Server features](#language-server-features)
* [Watching files](#watching-files)
* [Requests](#requests)
* [Configuration](#configuration)
* [Compatibility](#compatibility)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

## What is this?

This package exports a function which can be used to create a
[language server][] based on [unified][] processors.
It can do the following:

* format documents based on a unified processor
* validate documents based on a unified processor
* support configuration files (such as `.remarkrc`) using
[`unified-engine`][unified-engine]
* format documents based on a unified processor
* validate documents based on a unified processor
* support configuration files (such as `.remarkrc`) using
[`unified-engine`][unified-engine]

**unified** is a project that validates and transforms content with abstract
syntax trees (ASTs).
Expand All @@ -58,7 +58,7 @@ various editors.

## Install

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
This package is [ESM only][].
In Node.js (version 16.0+), install with [npm][]:

```sh
Expand Down Expand Up @@ -162,11 +162,11 @@ Name of configuration files to load (`string`, optional).

For examples, see the following projects:

* `redot-language-server`
(coming soon)
* `rehype-language-server`
(coming soon)
* [`remark-language-server`](https://github.com/remarkjs/remark-language-server)
* `redot-language-server`
(coming soon)
* `rehype-language-server`
(coming soon)
* [`remark-language-server`](https://github.com/remarkjs/remark-language-server)

## Types

Expand All @@ -187,39 +187,39 @@ change was made.
Language servers created using this package implement the following language
server features:

* `textDocument/codeAction`
— the language server implements code actions based on the `expected` field
on reported messages.
A code action can either insert, replace, or delete text based on the range
of the message and the expected value.
* `textDocument/didChange`
— when a document is changed by the client, the language server processes it
using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.
* `textDocument/didClose`
— when a document is closed by the client, the language server resets
diagnostics by publishing an empty array using
`textDocument/publishDiagnostics`.
* `textDocument/didOpen`
— when a document is opened by the client, the language server processes it
using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.
* `textDocument/formatting`
— when document formatting is requested by the client, the language server
processes it using a unified pipeline.
The stringified result is returned.
* `workspace/didChangeWatchedFiles` and `workspace/didChangeWorkspaceFolders`
— when the client signals a watched file or workspace has changed, the
language server processes all open files using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.
* `textDocument/codeAction`
— the language server implements code actions based on the `expected` field
on reported messages.
A code action can either insert, replace, or delete text based on the range
of the message and the expected value.
* `textDocument/didChange`
— when a document is changed by the client, the language server processes it
using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.
* `textDocument/didClose`
— when a document is closed by the client, the language server resets
diagnostics by publishing an empty array using
`textDocument/publishDiagnostics`.
* `textDocument/didOpen`
— when a document is opened by the client, the language server processes it
using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.
* `textDocument/formatting`
— when document formatting is requested by the client, the language server
processes it using a unified pipeline.
The stringified result is returned.
* `workspace/didChangeWatchedFiles` and `workspace/didChangeWorkspaceFolders`
— when the client signals a watched file or workspace has changed, the
language server processes all open files using a unified pipeline.
Any messages collected are published to the client using
`textDocument/publishDiagnostics`.

### Configuration

* `requireConfig` (default: `false`)
— If true, files will only be checked if a configuration file is present.
* `requireConfig` (default: `false`)
— If true, files will only be checked if a configuration file is present.

## Compatibility

Expand All @@ -234,10 +234,10 @@ It should work anywhere where LSP 3.6.0 or later is implemented.

## Related

* [`unified`](https://github.com/unifiedjs/unified)
— create pipeline for working with syntax trees
* [`unified-args`](https://github.com/unifiedjs/unified-args)
— create a CLI for a unified pipeline
* [`unified`](https://github.com/unifiedjs/unified)
— create pipeline for working with syntax trees
* [`unified-args`](https://github.com/unifiedjs/unified-args)
— create a CLI for a unified pipeline

## Contribute

Expand Down Expand Up @@ -267,6 +267,8 @@ abide by its terms.

[downloads]: https://www.npmjs.com/package/unified-language-server

[esm only]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[size-badge]: https://img.shields.io/bundlephobia/minzip/unified-language-server.svg

[size]: https://bundlephobia.com/result?p=unified-language-server
Expand Down
17 changes: 10 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,28 +981,31 @@ function cleanStack(stack, max) {
* @param relativeCwd The cwd to use for the process relative to this test file.
*/
function startLanguageServer(serverFilePath, relativeCwd = './') {
const bin = fileURLToPath(new URL(serverFilePath, import.meta.url))
const binary = fileURLToPath(new URL(serverFilePath, import.meta.url))
const cwd = new URL(relativeCwd, import.meta.url)

// Using ipc is useful for debugging. This allows logging in the language
// server.
// Enabling this breaks code coverage
// https://github.com/bcoe/c8/issues/189
if (process.argv.includes('--ipc')) {
const proc = spawn('node', [bin, '--node-ipc'], {
const serverProcess = spawn('node', [binary, '--node-ipc'], {
cwd,
stdio: [null, 'inherit', 'inherit', 'ipc']
})
connection = createProtocolConnection(
new IPCMessageReader(proc),
new IPCMessageWriter(proc)
new IPCMessageReader(serverProcess),
new IPCMessageWriter(serverProcess)
)
connection.onDispose(() => {
proc.kill()
serverProcess.kill()
})
} else {
const proc = spawn('node', [bin, '--stdio'], {cwd})
connection = createProtocolConnection(proc.stdout, proc.stdin)
const serverProcess = spawn('node', [binary, '--stdio'], {cwd})
connection = createProtocolConnection(
serverProcess.stdout,
serverProcess.stdin
)
}

connection.onDispose(() => {
Expand Down

0 comments on commit 7bee593

Please sign in to comment.