unifiedjs / unified-language-server Goto Github PK
View Code? Open in Web Editor NEWLanguage server for content, using @unifiedjs
Home Page: https://unifiedjs.com
License: MIT License
Language server for content, using @unifiedjs
Home Page: https://unifiedjs.com
License: MIT License
We already support quick fixes, but they require the user to manually select the quick fix. This is slightly tedious if there’s only one suggestion.
Code actions support the isPreferred
option. This signals the editor that this is the preferred code action for the given diagnostic.
VS Code uses the Quick Fix…
command to apply a code action. We already support this. If we mark a code action as isPreferred
, VS Code can fix the issue using the Auto Fix…
and Fix All
commands, bypassing the quick fix selection. Users can also opt-in to auto fix all violations with preferred fixes on save.
Don’t support this. 🤷
A user wishes to use unified-language-server
or remark-language-server
without installing remark in their local project folder
unified-language-server
should fall back to a global or bundled installation of remark if a local one is not found
installing remark
locally solely for the sake of a specific class of editors is not ideal
You might also support
ancestors
: https://github.com/vfile/vfile-message#fields
Originally posted by @wooorm in #57 (review)
I looked into ancestors, but I think the information is not relevant here. It makes the messages very verbose. As an end user of the language server, the fact that everything is based on ASTs, is an implementation detail.
Originally posted by @remcohaszing in #57 (comment)
I’m not saying it should be a default. It isn’t in vfile-reporter either.
But I see if quite different. There are many reasons for errors to be thrown. I think users and the code that emits errors should decide whether the positional info and other info in the AST is an “implementation detail” or not.
Originally posted by @wooorm in #57 (comment)
Add option showAncestors
. If this is true, the ancestry will be added to the LSP diagnostic message.
showAncestors
was chosen arbritrarily. The name could be different.DiagnosticRelatedInformation
instead of appending to the message. This makes the trace clickable, but it renders differently.Comments in neovim/nvim-lspconfig#1606, neovim/nvim-lspconfig#1641, and mattn/vim-lsp-settings#527 show that users don’t know what remark is. When they open a markdown file, they are prompted to enable remark-language-server
. When they do enable it, they are prompted with a message to install remark
.
Also VS Code users are going to run into this issue. They will install the extension to get the functionality in projects that use remark, but the extension will show a prompt every time they open a project which doesn’t use remark.
Don’t perform actions for workspaces where no remark configuration is found.
To accomplish this, the logic for resolving a configuration needs to be exposed in unified-engine
.
An alternative would be to add language server settings. This allows the user to specify at least VS Code users to define settings to enable or disable certain features per project.
This would be similar to prettier.enable
and prettier.requireConfig
in prettier-vscode
.
This puts control, but also burden in the hands of the users.
Review AST and only reprocess segments that have been changed.
Large documents can be slow to reparse as you type.
Only lint/review parts of the document that have changed.
Allowing for faster feedback.
https://github.com/micromark/micromark for incremental parsing.
This may not be possible with the current design of unified.
Thoughts on how it may be achievable are welcome.
As part of remarkjs/remark#910 I would like to make unified-language-server
based on unified-engine
, so it yields the same result as CLIs created using unified-args
.
Currently the language server is written in CJS, has a custom configuration file, and is synchronous. Unfortunately this means a lot of the existing code needs to be rewritten. Fortunately this also means a lot of code can be removed.
In order to do this right, the command line interface of the language server needs to be redesigned.
I imagine the CLI works like this:
unified-language-server \
--prefix remark \
--plugin remark-parse \
--plugin remark-stringify
--prefix
defines the prefix that’s passed to unified-engine
. I.e. the example loads .remarkrc.js
, .remarkignore
, etc.--plugin
specifies plugins to be loaded that aren’t defined in the configuration file. They will be loaded using load-plugin
.Also I suggest we add a pre existing command line parser, i.e. commander
Another possibility is to load remark
. This better matches behavior of remark-cli
. However, I’m not sure how this should be defined, because remark
uses a named export.
latest
No response
cwd
is not set when creating a file or when creating an engine.
file.cwd
must be set to the folder that is the “workplace”, e.g., the place where the package.json
and .git
are typically.
Right now, it’s not set, so it’s (90% sure) set to a wrong value. Which means certain plugins break (example: https://github.com/remarkjs/remark-usage/blob/ae591a38bfb5424a802f25ae77b69f5dc06836fa/lib/index.js#L13-L27)
Here’s how I found a logical one for atom: https://github.com/unifiedjs/unified-engine-atom/blob/605326d08a6d04b66aa8abf3143313f24c507699/index.js#L44-L53
(unknown behavior, likely broken plugins or unexpected results)
No response
No response
No response
No response
workspace/didChangeWatchedFiles
means a file or folder changed. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_didChangeWatchedFiles. Instead of reprocessing every markdown file (
unified-language-server/lib/index.js
Line 264 in f222a65
perhaps we should use cheap hashes to ensure we only perform work when something changed.
n/a
Input and output file URIs sometimes don‘t match. E.g.,:
While your problem currently presents itself around symlinks, it might not be a problem unique to symlinks (e.g., there might be other values that are sent which are sent back differently, due to escapes/encoding of characters, slashes, case-sensitive/-insensitive file systems, &c.).
(GH-32).
For a solution, I think we can solve this quite like what you’re currently doing it. But I dislike the name file.data.uri. And commenting about symlinks only.
What about calling it file.data.lspInputUri or so? To signal that its purpose is to pass a certain string from that protocol through the engine and back?
lspDocumentUri is great, yeah! I like it more than lspInputUri
(GH-32).
n/a
Add automated tests
Currently the code has only been tested by running manually starting server and running an editor to manually test.
Some testing should be automated.
If the server uses the stdio protocol for communication, stdout is used for communication. However, console.log()
etc statements also write to stdout. This causes the following error:
node_modules/vscode-jsonrpc/lib/common/messageReader.js:138
throw new Error('Header must provide a Content-Length property.');
^
Error: Header must provide a Content-Length property.
at StreamMessageReader.onData (node_modules/vscode-jsonrpc/lib/common/messageReader.js:138:27)
at Socket.<anonymous> (node_modules/vscode-jsonrpc/lib/common/messageReader.js:122:18)
at Socket.emit (node:events:520:28)
The language server simply shouldn’t use console.log()
, but third party plugins or other third party packages might do so.
The language server can rewrite the global console, so its calls are rerouted to connection.console
.
The output could be disabled entirely.
There are several reasons the unified engine throws an error. It’s currently not tested though:
unified-language-server/lib/index.js
Lines 173 to 178 in f222a65
Add a test
n/a
If a plugin throws, an error diagnostic is created. This diagnostic contains the stack trace as the message.
It might look a bit nicer to clean the stack trace using clean-stack
, or to trim out even unified internals, which requires stack-utils
.
Don’t trim stack traces. 🤷
2.x
git clone [email protected]:remcohaszing/vscode-remark.git
cd vscode-remark
npm ci
readme.md
, add the text Foo. Bar.
A diagnostic should appear
No diagnostic appears.
Further inspection showed this is caused by the fact that the current working directory of the language server doesn’t reflect the file opened.
I found this out first by troubleshooting Windows. This shows the following values:
workspacesAsPaths
: C:\Users\remco\AppData\Programs\Microsoft VS Code
file.path
: z:\vs-code\readme.md
There is no correlation between the two.
I was also able to reproduce this on Linux by opening VSCode using the desktop launcher. This sets the cwd to /home/remco
, while the file is in /home/remco/Projects/vscode-remark/readme.md
. remark
should be resolved from /home/remco/Projects/vscode-remark
, not /home/remco
.
While typing this issue, I also noticed the different casing styles used for the drive letters on Windows.
Node v16
npm v7
Other (please specify in steps to reproduce)
esbuild
latest
No response
LSP-remark
Reporemark
defaults to a local directory due to unified engine logicProvides ability to send custom node_module location
Doesn't allow custom paths
Node v16
yarn v2
macOS
No response
Document usage in more editors
Language servers are designed to be usable with almost any editor.
Currently only NeoVim usage is documented.
Include documentation for other editors, including:
https://langserver.org/#implementations-client
Link to external documentation
In a markdown file
Server is running responding 1
(:call LanguageClient_isServerRunning()
)
When I do :call LanguageClient#textDocument_formatting()
I get
[LC] Error: Failure { jsonrpc: Some(V2), error: Error { code: MethodNotFound, message: "Unhandled method textDocument/formatting", data: None }, id: Num(2) }
Some unified plugins support the vfile-message#note
property. It might be nice to support this in the language server as well.
If note
is define on a vfile message, add it to the diagnostic message joined by 1 or 2 newlines.
Better documentation around handling of configuration file, or specifying config file as an argument when starting server
Currently, the docs do not make it clear where and how the configuration file is supposed to be sent to server.
unified-language-server
has the potential to work great for vim-lsp
users editing markdown files. However, it’s a bit annoying to set up.
If it’s registered to vim-lsp-settings
, it can be configured using a single command.
🤷
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.