diff --git a/README.md b/README.md index 1f421ca..27397d8 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,10 @@ Untyped `throw` statements can be a pain for those who come from languages like | Platform | Installation | | -------- | ------------ | -| VsCode | via [Marketplace](https://marketplace.visualstudio.com/items?itemName=michaelangeloio.does-it-throw-vscode) | -| NeoVim | Coming soon... | +| VsCode | [Marketplace](https://marketplace.visualstudio.com/items?itemName=michaelangeloio.does-it-throw-vscode) | +| Neovim | [Neovim Installation Docs](https://github.com/michaelangeloio/does-it-throw/blob/main/docs/neovim.md) | +| LSP Server | [NPM](https://www.npmjs.com/package/does-it-throw-lsp) | +| JetBrains | Coming soon... | > This extension is built with security in mind. It doesn't send any data to any third party servers. All publishes are done via a signed immutable commit from the [CI pipeline](https://github.com/michaelangeloio/does-it-throw/blob/update-details/.github/workflows/release-please.yaml). diff --git a/docs/neovim.md b/docs/neovim.md index 61c155f..3e4e2dd 100644 --- a/docs/neovim.md +++ b/docs/neovim.md @@ -1,7 +1,23 @@ -> *NeoVim is hacky right now, but it works!* -# Lua -Here's an example init.lua config: +> *There are probably ways to improve the Neovim experience. If you have suggestions, please open an issue!* + +# Install the LSP Server + +First, install (globally) the `does-it-throw-lsp` package from NPM: +```bash +npm i -g does-it-throw-lsp +``` + +> You can use your favorite package manager, eg `bun install` + +This package contains the same LSP Server VSCode runs under the hood. The server itself uses Node.js, but the core of the code is written in Rust and compiled to WASM. The server is published to NPM, and the Rust code is published to [crates.io](https://crates.io/crates/does-it-throw). + +> If anyone has ideas on how to run the server via bun with some shim, let me know! The current `bin` script is located [here](https://github.com/michaelangeloio/does-it-throw/blob/main/server/bin/does-it-throw). + +# Lua Setup + +(optional) install Lazy.nvim: ```lua +-- init.lua local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' local uv = vim.uv or vim.loop @@ -15,7 +31,18 @@ if not uv.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) +``` +## Starting the Server + +You can start the server manually by running the following command: +```bash +does-it-throw-lsp --stdio +``` +### Lua Setup (cont'd) + +Tell Neovim to use the LSP server: +```lua require('lazy').setup({{'neovim/nvim-lspconfig'}}) local lsp_configurations = require('lspconfig.configs') @@ -34,8 +61,7 @@ local server_config = { if not lsp_configurations.does_it_throw_server then lsp_configurations.does_it_throw_server = { default_config = { - cmd = {"node", "/Users/angelo/developer/does-it-throw-vscode-0.2.5/extension/server/out/server.js", - "--stdio"}, + cmd = {"does-it-throw-lsp", "--stdio"}, filetypes = {"typescript", "javascript"}, root_dir = function(fname) return vim.fn.getcwd() @@ -48,7 +74,7 @@ require'lspconfig'.does_it_throw_server.setup { on_init = function(client) client.config.settings = server_config end, - -- important to set this up so that the server can find the settings + -- important to set this up so that the server can find your desired settings handlers = { ["workspace/configuration"] = function(_, params, _, _) local configurations = {} @@ -61,7 +87,24 @@ require'lspconfig'.does_it_throw_server.setup { end } } +``` +## Customizations +Notice the above lua config: +```lua +["doesItThrow"] = { + throwStatementSeverity = "Hint", + functionThrowSeverity = "Hint", + callToThrowSeverity = "Hint", + callToImportedThrowSeverity = "Hint", + maxNumberOfProblems = 10000 +} +``` +The settings correspond to the same VSCode settings. These settings and descriptions can be found under [package.json](https://github.com/michaelangeloio/does-it-throw/blob/main/package.json). + + +### (optional) Customize your diagnostics: +```lua vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { -- Enable underline, use default values underline = true, @@ -89,7 +132,10 @@ for type, icon in pairs(signs) do numhl = hl }) end +``` --- Enable diagnostics if you want +If you need to debug the server for whatever reason, you can set the log level to `debug`: +```lua +-- Enable server log diagnostics if you want vim.lsp.set_log_level("debug") ``` \ No newline at end of file