Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unified-engine #13

Merged
merged 43 commits into from
Dec 23, 2021
Merged

Use unified-engine #13

merged 43 commits into from
Dec 23, 2021

Conversation

remcohaszing
Copy link
Member

@remcohaszing remcohaszing commented Dec 9, 2021

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

This draft uses unified-engine to process documents. The old code has been left intact for now. The new code also uses ESM and JSDoc type annotations.

Closes #11

This draft uses `unified-engine` to process documents. The old code has been
left intact for now.
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Dec 9, 2021
@remcohaszing
Copy link
Member Author

image

And a screenshot to show what it looks like now with vim-lsp. :)

index.mjs Outdated Show resolved Hide resolved
index.mjs Outdated Show resolved Hide resolved
index.mjs Outdated Show resolved Hide resolved
index.mjs Outdated Show resolved Hide resolved
index.mjs Outdated
initUnifiedLanguageServer(connection, documents, 'remark', [
'remark-parse',
'remark-stringify'
])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual creation of connection and document is necessary for testing purposes, but it may be removed for a public interface.

Now that I have a better idea of how this should work, I can think of 2 options for a public interface. Personally I prefer option 2.

Option 1: Provide a CLI for the unified language server

This means the end user will have to specify some options.

unified-language-server --prefix remark --plugin remark-parse --plugin remark-stringify --stdio

Option 2: Provide a NodeJS API

This means for every unified ecosystem a language server needs to be created. This is similar to unified-args.

Creating remark-language-server will be as simple as:

import {initUnifiedLanguageServer} from 'unified-language-server'

initUnifiedLanguageServer('remark', [
  'remark-parse',
  'remark-stringify'
])

End users will simply run:

remark-language-server --stdio

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There two options aren't strictly mutually exclusive.
If we start with option 2, a NodeJS API, we could build option 1 a CLI on top of that later if wanted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are language servers used? Who is using this already, and how (or what projects do similar stuff that should switch to using this project?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are language servers used?

I mostly used language servers through VSCode.
Which wraps usually wraps the language server as a VSCode extension.
I'm not as familiar with how it is used with other editors.

what projects do similar stuff that should switch to using this project?

I think there are some MDX language servers which could be migrated to use this.
And the remark, and incoming rehype (retextjs/retext#57), language servers would likely need to be updated to leverage the new structure/features

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many editors support this using a minimal amount of code (if any). Based on this language server, it should be fairly straight forward to integrate unified into any of those editors.

Language servers provide many features, but the ones that make sense for unified are linting and formatting.

My goal is to make vscode-remark use this language server. A similar plugin could be created for rehype, redot, and possibly others.

Based on the fact that unified-engine-atom still uses CJS, it’s outdated. That project can probably be discontinued in favor of plugins based on this language server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like fewer things to exist so I'd vote for there being one executable that can be edited to fit multiple roles. One language-server that can both to plain-text, HTML, markdown, asciidoc, .. with the help of plugins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 3: Support language server settings

Language servers support configuration options. This can be leveraged to configure unified-engine.

if (executable('unified-language-server'))
  au User lsp_setup call lsp#register_server({
  \ 'name': 'remark',
  \ 'cmd': {server_info->['unified-language-server', '--stdio']},
  \ 'allowlist': ['markdown'],
  \ 'config': {
  \   'defaultSource': 'remark',
  \   'ignoreName': '.remarkignore',
  \   'packageField': '.remarkConfig',
  \   'pluginPrefix': 'remark',
  \   'plugins': ['remark-parse', 'remark-stringify'],
  \   'rcName': '.remarkrc'
  \ })
endif

I still think option 2 is the way to go. This requires no additional configuration for end users, making it the simplest to use and leaving the least room for users to misconfigure it.

However, option 3 would be nice for some use cases. For example debugging unified-language-server or fiddling with a new ecosysem based on unified.

These options don’t have to exclude each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn’t get loading configuration to work, so I suggest to create an issue for it so it can be implemented later.

@codecov-commenter

This comment has been minimized.

package.json Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
test/index.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@aecepoglu
Copy link
Contributor

Well this seems like a major change :D

I am not keeping up to date with what's happening with unifiedJS or the language server. Ideally my code would have been modifiable enough that not the entirety of it would change :) but I encourage any amount of change including those beyond 99%

If anyone wants their name to be in the author field because they did more work than the original, you're welcome to change it as far as I'm concerned.

👍

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some style things, but 👍 on the code

server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @remcohaszing!
Added a few questions below.

README.md Show resolved Hide resolved
lib/server.js Outdated Show resolved Hide resolved
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(one comment was accidentally in a PR review, see above)

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Is unified-language-server-0.3.0.tgz supposed to be checked in?

index.js Show resolved Hide resolved
remcohaszing and others added 2 commits December 23, 2021 10:16
Co-authored-by: Titus <tituswormer@gmail.com>
@wooorm wooorm changed the title Rewrite using unified-engine Use unified-engine Dec 23, 2021
@wooorm wooorm merged commit 1dbafab into unifiedjs:main Dec 23, 2021
@wooorm wooorm added the 💪 phase/solved Post is done label Dec 23, 2021
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Dec 23, 2021
@wooorm wooorm mentioned this pull request Dec 23, 2021
@wooorm
Copy link
Member

wooorm commented Dec 23, 2021

@remcohaszing Btw, reading the example code, shouldn’t remark-parse, remark-stringify, other other things be added to dependencies in package.json perhaps?

@remcohaszing
Copy link
Member Author

@remcohaszing Btw, reading the example code, shouldn’t remark-parse, remark-stringify, other other things be added to dependencies in package.json perhaps?

No. These will be loaded from the user’s local workspace.

@remcohaszing remcohaszing deleted the unified-engine branch March 13, 2022 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

Implement unified-engine
6 participants