Skip to content

Commit

Permalink
feat: neovim/language server docs (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelangeloio authored Dec 16, 2023
1 parent d616575 commit a00d92a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
60 changes: 53 additions & 7 deletions docs/neovim.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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')
Expand All @@ -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()
Expand All @@ -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 = {}
Expand All @@ -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,
Expand Down Expand Up @@ -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")
```

0 comments on commit a00d92a

Please sign in to comment.