{"id":13496243,"url":"https://github.com/nim-lang/langserver","last_synced_at":"2025-04-06T20:08:30.970Z","repository":{"id":41565932,"uuid":"136307276","full_name":"nim-lang/langserver","owner":"nim-lang","description":"The Nim language server implementation (based on nimsuggest)","archived":false,"fork":false,"pushed_at":"2025-04-02T11:11:33.000Z","size":1027,"stargazers_count":230,"open_issues_count":24,"forks_count":35,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-02T12:23:58.267Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nim-lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-06T09:41:21.000Z","updated_at":"2025-04-02T11:11:37.000Z","dependencies_parsed_at":"2024-04-09T21:30:08.912Z","dependency_job_id":"2b0b2eca-6bc5-4ad1-892c-8856e31f45c1","html_url":"https://github.com/nim-lang/langserver","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nim-lang%2Flangserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nim-lang%2Flangserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nim-lang%2Flangserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nim-lang%2Flangserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nim-lang","download_url":"https://codeload.github.com/nim-lang/langserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543589,"owners_count":20955865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:44.473Z","updated_at":"2025-04-06T20:08:30.945Z","avatar_url":"https://github.com/nim-lang.png","language":"Nim","readme":"# Nim Language Server\n\nNim Language Server, or `nimlangserver`, is a language server for Nim.\n\n## Installation\n\n**IMPORTANT** you might want to use latest build of the `nimlangserver` and/or build it from source.\n\n`nimlangserver` requires `nimble \u003e= 0.16.1`\n\n### Installing binaries\n\n_NB:_ `nimlangserver` requires `nimsuggest` version that supports `--v3`:\n- `devel` containing [19826](https://github.com/nim-lang/Nim/pull/19826)\n- 1.6+ containing [19892](https://github.com/nim-lang/Nim/pull/19892)\n\nYou can install the latest release into `$HOME/.nimble/bin` using e.g.:\n\n```sh\nnimble install nimlangserver\n```\n\n### From Source\n\n```bash\nnimble build\n```\n\n### VSCode\n- [vscode-nim](https://github.com/nim-lang/vscode-nim) has support for `nimlangserver`. Follow the instructions at:\nhttps://github.com/nim-lang/vscode-nim#using\n\n### Sublime Text\nInstall [LSP-nimlangserver](https://packagecontrol.io/packages/LSP-nimlangserver) from Package Control.\n\n### Zed Editor\nInstall [Nim Extenstion](https://github.com/foxoman/zed-nim) from the Zed Editor extensions.\n\n### Neovim\n- [lsp](https://neovim.io/doc/user/lsp.html) Neovim has built-in LSP support. Although, you might want to use something like [lsp-config](https://github.com/neovim/nvim-lspconfig) to take care of the boilerplate code for the most LSP configurations. Install `lsp-config` using your favourite plugin manager an place the following code into your `init.vim` config:\n```lua\nlua \u003c\u003cEOF\n\nrequire'lspconfig'.nim_langserver.setup{\n  settings = {\n    nim = {\n      nimsuggestPath = \"~/.nimble/bin/custom_lang_server_build\"\n    }\n  }\n}\n\nEOF\n```\nChange configuration to your liking (most probably you don't need to provide any settings at all, defaults should work fine for the majority of the users). You might also want to read `lsp-config` documentation to setup key bindings, autocompletion and so on.\n\n**IMPORTANT** you might want to use latest build of the `nimlangserver` and/or build it from source.\n\n### VIM/Neovim\n- [coc.nvim](https://github.com/neoclide/coc.nvim) supports both classical VIM as well as Neovim. It also supports vscode-like `coc-settings.json` for LSP configuration. Install the plugin via your favourite plugin manager, create `coc-settings.json` alongside your `init.vim` and add the following contents to it:\n```json\n{\n  \"languageserver\": {\n    \"nim\": {\n      \"command\": \"nimlangserver\",\n      \"filetypes\": [\"nim\"],\n      \"trace.server\": \"verbose\",\n      \"settings\": {\n        \"nim\": {\n          \"nimsuggestPath\": \"~/.nimble/bin/nimsuggest\"\n        }\n      }\n    }\n  }\n}\n```\nOf course, change the configuration to your liking. You might also want to read `coc.nvim` documentation to setup key bindings, autocompletion and so on.\n\n\n## Configuration Options\n\n- `nim.projectMapping` - configure how `nimsuggest` should be started. Here it is sample configuration for `VScode`. We don't want `nimlangserver` to start `nimsuggest` for each file and this configuration will allow configuring pair `projectFile`/`fileRegex` so when one of the regexp in the list matches current file then `nimls` will use `root` to start `nimsuggest`. In case there are no matches `nimlangserver` will try to guess the most suitable project root.\n\n``` json\n{\n    \"nim.projectMapping\": [{\n        // open files under tests using one nimsuggest instance started with root = test/all.nim\n        \"projectFile\": \"tests/all.nim\",\n        \"fileRegex\": \"tests/.*\\\\.nim\"\n    }, {\n        // everything else - use main.nim as root.\n        \"projectFile\": \"main.nim\",\n        \"fileRegex\": \".*\\\\.nim\"\n    }]\n}\n```\nNote when in a nimble project, `nimble` will drive the entry points for `nimsuggest`. \n\n- `nim.timeout` - the request timeout in ms after which `nimlangserver` will restart the language server. If not specified the default is 2 minutes.\n- `nim.nimsuggestPath` - the path to the `nimsuggest`. The default is `\"nimsuggest\"`.\n- `nim.autoCheckFile` - check the file on the fly\n- `nim.autoCheckProject` - check the project after saving the file\n- `nim.autoRestart` - auto restart once in case of `nimsuggest` crash. Note that\n  the server won't restart if there weren't any successful calls after the last\n  restart.\n- `nim.workingDirectoryMapping` - configure the working directory for specific projects.\n- `nim.checkOnSave` - check the file on save.\n- `nim.logNimsuggest` - enable logging for `nimsuggest`.\n- `nim.inlayHints` - configure inlay hints.\n- `nim.notificationVerbosity` - configure the verbosity of notifications. Can be set to `\"none\"`, `\"error\"`, `\"warning\"`, or `\"info\"`.\n- `nim.formatOnSave` - format the file on save. Requires `nph` to be available in the PATH.\n- `nim.nimsuggestIdleTimeout` - the timeout in ms after which an idle `nimsuggest` will be stopped. If not specified the default is 120 seconds.\n- `nim.useNimCheck` - use `nim check` instead of `nimsuggest` for linting. Defaults to `true`.\n- `nim.maxNimsuggestProcesses` - the maximum number of `nimsuggest` processes to keep alive. 0 means unlimited. If not specified the default is 0.\n## Features\n\n`nimlangserver` supports the following LSP features:\n\n- Initialize\n- Completions\n- Hover\n- Goto definition\n- Goto declaration\n- Goto type definition\n- Document symbols\n- Find references\n- Code actions\n- Prepare rename\n- Rename symbols\n- Inlay hints\n- Signature help\n- Document formatting (Requires `nph` to be available in the PATH.)\n- Execute command\n- Workspace symbols\n- Document highlight\n- Shutdown\n- Exit\n\nYou can install `nimlangserver` using the instructions for your text editor below:\n\n### Extension methods\nIn addition to the standard `LSP` methods, `nimlangserver` provides additional nim specific methods.\n\n### `extension/macroExpand`\n\n* Request:\n```nim\ntype\n  ExpandTextDocumentPositionParams* = ref object of RootObj\n    textDocument*: TextDocumentIdentifier\n    position*: Position\n    level*: Option[int]\n```\nWhere:\n- `position` is the position in the document.\n- `textDocument` is the document.\n- `level` is the how much levels to expand from the current position\n\n* Response:\n``` nim\ntype\n  ExpandResult* = ref object of RootObj\n    range*: Range\n    content*: string\n```\nWhere:\n- `content` is the expand result\n- `range` is the original range of the request.\n\nHere it is sample request/response:\n\n```\n[Trace - 11:10:09 AM] Sending request 'extension/macroExpand - (141)'.\nParams: {\n  \"textDocument\": {\n    \"uri\": \"file:///.../tests/projects/hw/hw.nim\"\n  },\n  \"position\": {\n    \"line\": 27,\n    \"character\": 2\n  },\n  \"level\": 1\n}\n\n\n[Trace - 11:10:10 AM] Received response 'extension/macroExpand - (141)' in 309ms.\nResult: {\n  \"range\": {\n    \"start\": {\n      \"line\": 27,\n      \"character\": 0\n    },\n    \"end\": {\n      \"line\": 28,\n      \"character\": 19\n    }\n  },\n  \"content\": \"  block:\\n    template field1(): untyped =\\n      a.field1\\n\\n    template field2(): untyped =\\n      a.field2\\n\\n    field1 = field2\"\n}\n\n```\n\n### VSCode\n\nInstall the `vscode-nim` extension from [here](https://github.com/nim-lang/vscode-nim)\n\n### Emacs\n\n- Install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) and `nim-mode` from melpa and add the following to your\n  config:\n\n``` elisp\n(add-hook 'nim-mode-hook #'lsp)\n```\n\n## Transport\n\n`nimlangserver` supports two transport modes:\n- stdio\n- socket\n\nTo use socket mode, start `nimlangserver` with the `--socket` flag. You can set the port using the `--port` flag. If you don't specify the port, `nimlangserver` will automatically find an open port and print it in the console.\n\n## Related Projects\n\n- [nimlsp](https://github.com/PMunch/nimlsp)\n\n   Both `nimlangserver` and `nimlsp` are based on `nimsuggest`, but the main\n   difference is that `nimlsp` has a single specific version of `nimsuggest`\n   embedded in the server executable, while `nimlangserver` launches `nimsuggest`\n   as an external process. This allows `nimlangserver` to handle any `nimsuggest`\n   crashes more gracefully.\n\n## License\n\nMIT\n","funding_links":[],"categories":["Nim"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnim-lang%2Flangserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnim-lang%2Flangserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnim-lang%2Flangserver/lists"}