wooorm / linter-remark

Check markdown with remark in atom
MIT License
12 stars 1 forks source link

Pointers for setting this up on atom #16

Closed whacked closed 2 years ago

whacked commented 2 years ago

Hi, I get the sense that there are pressures from different directions for Atom-based markdown LSP clients, but this one was my starting point. Based on a few discussions from search, it looks like packages moving to ESM means that many are already broken in Atom.

I am trying to piece together a path to a minimum working setup based on this repo, https://github.com/wooorm/linter-remark/pull/15, https://github.com/remarkjs/remark-language-server/pull/4, and others, but haven't gotten anything to work with markdown yet.

For the record, here are some steps that others might find informative:

$ atom --version
Atom    : 1.58.0
Electron: 9.4.4
Chrome  : 83.0.4103.122
Node    : 12.14.1
$ echo $ATOM_HOME 
/tmp/atom-temp
$ ls -1
 shell.nix

we are working with a bare atom setup from a bare directory; shell.nix declares atom and python 3.10 and python-lsp-server. Python is for verification.

$ apm install atom-ide-base atom-ide-ui ide-python  # install lsp-related packages (I think so)
$ atom --dev --portable .  # start atom

In Atom, open the command palette (ctrl-shift-P) and run window:reload. Open a random python file and confirm that LSP integration works. I believe it works because syntax errors get marked in the source file, and the process list shows that atom has spawned a python pylsp process.

Now go back to Install Packages and Themes / apm, and install linter-remark. run window:reload. Open a random markdown file. Following the demo in the readme, I create a file with

This doesn't [exist](#heading)...

The editor doesn't indicate anything wrong, and there is no interesting process under atom's process tree.

Open the dev tools console (ctrl-shift-I). There is an interesting error

Uncaught (in promise) Error: Dependency#0 for linter-remark is invalid
    at invariant (/tmp/atom-temp/packa…ps/lib/index.js:553)
    at /tmp/atom-temp/packa…ps/lib/index.js:571
    at Array.forEach (<anonymous>)
    at getDependencies$2 (/tmp/atom-temp/packa…ps/lib/index.js:561)
    at Object.install (/tmp/atom-temp/packa…ps/lib/index.js:912)

Now, I believe this is the ESM-related error.

Based on #15, there seems to be at least one Just Works scenario (https://github.com/wooorm/linter-remark/pull/15#issuecomment-1003721097) but I am not sure how to navigate linter-remark's code yet, so I try something simpler, which also matches an approach of "bring your own node" I see in some other related threads.

use ide-json as a starting point:

$ pwd
/tmp/atom-temp
$ git clone https://github.com/atom/ide-json
$ cd ide-json
$ npm i  # install deps needed by ide-json
$ apm link ide-json
$ # restart / reload atom

confirm that botching a json file leads to syntax errors in the edit window = lsp is working.

https://github.com/atom/ide-json/blob/master/lib/main.js tells us that at minimum, we need to spawn the LSP server process. So I modify ide-json to use remark-language-server:

  1. change main.js getGrammarScopes to return ['text.md', 'Markdown']; note that the "Grammar" is actually provided by the package language-markdown. This seems to be undocumented. Without the grammar, text.md is not matched for a markdown file.
  2. change the spawn command to
    return super.spawn(
      "/path/to/nodejs",
      [
          "path/to/remark-langage-server/index.js",
          "--stdio"
      ]
    )

    in addition, I confirmed that running node path/to/remark-language-server/index.js --stdio spawns a server process, though I don't know how to communicate with it without a client, and I haven't yet gone down the more often seen "make a VSCode client" rabbithole.

  3. change package.json
    "enhancedScopes": [
    "text.md",
    "Markdown"
    ],
  4. relaunch atom and open a markdown file. At this point, we get some new errors
    Uncaught (in promise) Error [ERR_STREAM_DESTROYED] [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:431)
    at writeOrBuffer (_stream_writable.js:419)
    at Socket.Writable.write (_stream_writable.js:309)
    at …/lib/node/ril.js:90
    at new Promise (<anonymous>)
    at WritableStreamWrapper.write (…/lib/node/ril.js:80)
    at StreamMessageWriter.doWrite (…essageWriter.js:100)
    at …messageWriter.js:91

and some warnings

…ld/lib/logger.js:10 Markdown (remark-language-server) stderr .../ide-json/node_modules/vscode-jsonrpc/lib/common/connection.js:477
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr                         responsePromise.reject(new messages_1.ResponseError(error.code, error.message, error.data));
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr                                                ^
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr ResponseError: Unhandled method client/registerCapability
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr     at handleResponse (.../ide-json/node_modules/vscode-jsonrpc/lib/common/connection.js:477:48)
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr     at processMessageQueue (.../ide-json/node_modules/vscode-jsonrpc/lib/common/connection.js:292:17)
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr     at Immediate.<anonymous> (.../ide-json/node_modules/vscode-jsonrpc/lib/common/connection.js:276:13)
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr     at processImmediate (node:internal/timers:466:21) {
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr   code: -32601,
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr   data: undefined
…ld/lib/logger.js:10 Markdown (remark-language-server) stderr }
…ld/lib/logger.js:10 Markdown (remark-language-server) rpc.onClose The RPC connection closed unexpectedly

the client/registerCapability warning is quite interesting, but since the error appears before it, maybe it's a red herring.

At this point I can use some help from more experienced folks. My goal is to get an LSP client for markdown working in Atom. I'm not tied to a server or client implementation, although remark-language-server and linter-remark appear to be the most recent active projects so far.

Thank you for your time and effort!

wooorm commented 2 years ago

Closing as this package is now deprecated, due to Atom’s own deprecation: https://github.blog/2022-06-08-sunsetting-atom/