{"id":23222703,"url":"https://github.com/pmunch/nimlsp","last_synced_at":"2025-04-05T16:29:03.588Z","repository":{"id":33973629,"uuid":"136237263","full_name":"PMunch/nimlsp","owner":"PMunch","description":"Language Server Protocol implementation for Nim","archived":false,"fork":false,"pushed_at":"2024-04-22T09:58:28.000Z","size":204,"stargazers_count":424,"open_issues_count":41,"forks_count":51,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T18:50:45.129Z","etag":null,"topics":["hacktoberfest","lsp-server"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PMunch.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-05T21:32:27.000Z","updated_at":"2025-02-24T19:24:19.000Z","dependencies_parsed_at":"2023-01-15T03:44:20.652Z","dependency_job_id":"459f8671-a1ca-4cbf-b475-fc88df12557f","html_url":"https://github.com/PMunch/nimlsp","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fnimlsp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fnimlsp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fnimlsp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fnimlsp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PMunch","download_url":"https://codeload.github.com/PMunch/nimlsp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247364789,"owners_count":20927200,"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":["hacktoberfest","lsp-server"],"created_at":"2024-12-18T23:14:04.662Z","updated_at":"2025-04-05T16:29:03.565Z","avatar_url":"https://github.com/PMunch.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"Nim Language Server Protocol\n============================\n\nThis is a `Language Server Protocol\n\u003chttps://microsoft.github.io/language-server-protocol/\u003e`_ implementation in\nNim, for Nim.\nIt is based on nimsuggest, which means that every editor that\nsupports LSP will now have the same quality of suggestions that has previously\nonly been available in supported editors.\n\nInstalling ``nimlsp``\n---------------------\nIf you have installed Nim through ``choosenim`` (recommended) the easiest way to\ninstall ``nimlsp`` is to use ``nimble`` with:\n\n.. code:: bash\n\n   nimble install nimlsp\n\nThis will compile and install it in the ``nimble`` binary directory, which if\nyou have set up ``nimble`` correctly it should be in your path. When compiling\nand using ``nimlsp`` it needs to have Nim's sources available in order to work.\nWith Nim installed through ``choosenim`` these should already be on your system\nand ``nimlsp`` should be able to find and use them automatically. However if you\nhave installed ``nimlsp`` in a different way you might run into issues where it\ncan't find certain files during compilation/running. To fix this you need to\ngrab a copy of Nim sources and then point ``nimlsp`` at them on compile-time by\nusing ``-d:explicitSourcePath=PATH``, where ``PATH`` is where you have your Nim\nsources. You can also pass them at run-time (if for example you're working with\na custom copy of the stdlib by passing it as an argument to ``nimlsp``. How\nexectly to do that will depend on the LSP client.\n\nCompile ``nimlsp``\n------------------\nIf you want more control over the compilation feel free to clone the\nrepository. ``nimlsp`` depends on the ``nimsuggest`` sources which are in the main\nNim repository, so make sure you have a copy of that somewhere. Manually having a\ncopy of Nim this way means the default source path will not work so you need to\nset it explicitly on compilation with ``-d:explicitSourcePath=PATH`` and point to\nit at runtime (technically the runtime should only need the stdlib, so omitting\nit will make ``nimlsp`` try to find it from your Nim install). As of Nim 2.0.0 you must run\nthe 'build_all' script in the Nim repository first (``nimsuggest`` expects to import a file\nthat is not otherwise present).\n\nTo do the standard build run:\n\n.. code:: bash\n\n   nimble build\n\nOr if you want debug output when ``nimlsp`` is running:\n\n.. code:: bash\n\n   nimble debug\n\nOr if you want even more debug output from the LSP format:\n\n.. code:: bash\n\n   nimble debug -d:debugLogging\n\nSupported Protocol features\n---------------------------\n\n======  ================================\nStatus  LSP Command\n======  ================================\n☑ DONE  textDocument/didChange\n☑ DONE  textDocument/didClose\n☑ DONE  textDocument/didOpen\n☑ DONE  textDocument/didSave\n☐ TODO  textDocument/codeAction\n☑ DONE  textDocument/completion\n☑ DONE  textDocument/definition\n☐ TODO  textDocument/documentHighlight\n☑ DONE  textDocument/documentSymbol\n☐ TODO  textDocument/executeCommand\n☐ TODO  textDocument/format\n☑ DONE  textDocument/hover\n☑ DONE  textDocument/rename\n☑ DONE  textDocument/references\n☑ DONE  textDocument/signatureHelp\n☑ DONE  textDocument/publishDiagnostics\n☐ TODO  workspace/symbol\n======  ================================\n\n\nSetting up ``nimlsp``\n--------------------\nSublime Text\n::::::::::::\nInstall the `LSP plugin \u003chttps://packagecontrol.io/packages/LSP\u003e`_.\nInstall the `Nim plugin \u003chttps://packagecontrol.io/packages/Nim\u003e`_ for syntax highlighting.\n\nTo set up LSP, run ``Preferences: LSP settings`` from the command palette and add the following:\n\n.. code:: js\n\n   {\n      \"clients\": {\n         \"nimlsp\": {\n            \"command\": [\"nimlsp\"],\n            \"enabled\": true,\n\n            // ST4 only\n            \"selector\": \"source.nim\",\n\n            // ST3 only\n            \"languageId\": \"nim\",\n            \"scopes\": [\"source.nim\"],\n            \"syntaxes\": [\"Packages/Nim/Syntaxes/Nim.sublime-syntax\"]\n         }\n      }\n   }\n\n*Note: Make sure ``\u003cpath/to\u003e/.nimble/bin`` is added to your ``PATH``.*\n\nTo enable syntax highlighting in popups, run ``Preferences: settings`` and add the following:\n\n.. code:: js\n\n   \"mdpopups.use_sublime_highlighter\": true,\n   \"mdpopups.sublime_user_lang_map\": {\n      \"nim\":\n      [\n         [\n            \"nim\"\n         ],\n         [\n            \"Nim/Syntaxes/Nim\"\n         ]\n      ]\n   }\n\nVim\n::::::::::\nTo use ``nimlsp`` in Vim install the ``prabirshrestha/vim-lsp`` plugin and\ndependencies:\n\n.. code:: vim\n\n   Plugin 'prabirshrestha/asyncomplete.vim'\n   Plugin 'prabirshrestha/async.vim'\n   Plugin 'prabirshrestha/vim-lsp'\n   Plugin 'prabirshrestha/asyncomplete-lsp.vim'\n\nThen set it up to use ``nimlsp`` for Nim files:\n\n.. code:: vim\n\n   let s:nimlspexecutable = \"nimlsp\"\n   let g:lsp_log_verbose = 1\n   let g:lsp_log_file = expand('/tmp/vim-lsp.log')\n   \" for asyncomplete.vim log\n   let g:asyncomplete_log_file = expand('/tmp/asyncomplete.log')\n\n   let g:asyncomplete_auto_popup = 0\n\n   if has('win32')\n      let s:nimlspexecutable = \"nimlsp.cmd\"\n      \" Windows has no /tmp directory, but has $TEMP environment variable\n      let g:lsp_log_file = expand('$TEMP/vim-lsp.log')\n      let g:asyncomplete_log_file = expand('$TEMP/asyncomplete.log')\n   endif\n   if executable(s:nimlspexecutable)\n      au User lsp_setup call lsp#register_server({\n      \\ 'name': 'nimlsp',\n      \\ 'cmd': {server_info-\u003e[s:nimlspexecutable]},\n      \\ 'whitelist': ['nim'],\n      \\ })\n   endif\n\n   function! s:check_back_space() abort\n       let col = col('.') - 1\n       return !col || getline('.')[col - 1]  =~ '\\s'\n   endfunction\n\n   inoremap \u003csilent\u003e\u003cexpr\u003e \u003cTAB\u003e\n     \\ pumvisible() ? \"\\\u003cC-n\u003e\" :\n     \\ \u003cSID\u003echeck_back_space() ? \"\\\u003cTAB\u003e\" :\n     \\ asyncomplete#force_refresh()\n   inoremap \u003cexpr\u003e\u003cS-TAB\u003e pumvisible() ? \"\\\u003cC-p\u003e\" : \"\\\u003cC-h\u003e\"\n\nThis configuration allows you to hit Tab to get auto-complete, and to call\nvarious functions to rename and get definitions. Of course you are free to\nconfigure this any way you'd like.\n\nEmacs\n::::::::\n\nWith lsp-mode and use-package:\n\n.. code:: emacs-lisp\n\n   (use-package nim-mode\n     :ensure t\n     :hook\n     (nim-mode . lsp))\n\nOr with Eglot\n\n.. code:: emacs-lisp\n\n   (add-to-list 'eglot-server-programs\n             '(nim-mode \"nimlsp\"))\n\nIntellij\n::::::::\nYou will need to install the `LSP support plugin \u003chttps://plugins.jetbrains.com/plugin/10209-lsp-support\u003e`_.\nFor syntax highlighting i would recommend the \"official\" `nim plugin \u003chttps://plugins.jetbrains.com/plugin/15128-nim\u003e`_\n(its not exactly official, but its developed by an intellij dev), the plugin will eventually use nimsuggest and have support for \nall this things and probably more, but since its still very new most of the features are still not implemented, so the LSP is a\ndecent solution (and the only one really).\n\nTo use it:\n\n1. Install the LSP and the nim plugin.\n\n2. Go into ``settings \u003e Language \u0026 Frameworks \u003e Language Server Protocol \u003e Server Definitions``.\n\n3. Set the LSP mode to ``executable``, the extension to ``nim`` and in the Path, the path to your nimlsp executable.\n\n4. Hit apply and everything should be working now.\n\nKate\n::::::::\nThe LSP plugin has to be enabled in the Kate (version \u003e= 19.12.0) plugins menu:\n\n1. In ``Settings \u003e Configure Kate \u003e Application \u003e Plugins``, check box next to ``LSP Client`` to enable LSP functionality.\n\n2. Go to the now-available LSP Client menu (``Settings \u003e Configure Kate \u003e Application``) and enter the following in the User Server Settings tab:\n\n.. code:: json\n\n   {\n       \"servers\": {\n           \"nim\": {\n               \"command\": [\".nimble/bin/nimlsp\"],\n               \"url\": \"https://github.com/PMunch/nimlsp\",\n               \"highlightingModeRegex\": \"^Nim$\"\n           }\n       }\n   }\n\nThis assumes that nimlsp was installed through nimble.\n*Note: Server initialization may fail without full path specified, from home directory, under the ``\"command\"`` entry, even if nimlsp is in system's ``PATH``.*\n\nVS Code\n:::::::\nInstall a VS Code extension that supports NimLSP (2 available at the moment):\n\n- https://marketplace.visualstudio.com/items?itemName=junknet.nimlsp\n- https://marketplace.visualstudio.com/items?itemName=bung87.vscode-nim-lsp\n\nSet ``nimlsp.path`` extension setting to the binary path of ``nimlsp``. If you've installed ``nimlsp`` using nimble it is already in system's ``PATH``.\n\n``stderr`` of ``nimlsp`` process will be available in ``Output \u003e nim|nimlsp`` terminal\n\n\nRun Tests\n---------\nNot too many at the moment unfortunately, but they can be run with:\n\n.. code:: bash\n\n    nimble test\n\n\nDebug\n---------\nUse ``nimlsp_debug`` executable instead of ``nimlsp``, which is installed alongside it and should already be available in your path. \n\nLog files containing stdin/out will be generated in ``getTempDir() / \"nimlsp-\" \u0026 $getCurrentProcessId() / \"nimlsp.log\"`` folder, where ``getCurrentProcessId()`` is the running pid of ``nimlsp_debug`` instance executed by the IDE/extension, and can be read using ``pgrep -a nimlsp_debug``. Crashes may print stacktraces in stderr, which is not contained in logs but may captured by LSP client.\n\nwhen stdin/out/err is not enough, it is possible to trace all system calls of ``nimlsp[_debug]`` via ``sudo strace -p\u003cpid\u003e -s9999 \u003e strace.log 2\u003e\u00261``\n\n``test/logrunner`` can be used to replay the query submitted to ``nimlsp`` stored inside nimlsp.log:\n\n.. code::\n\n   NimLSP test runner, run as runner \u003cnimlsp binary\u003e \u003clog file\u003e\n   The log files must be generated by a nimlsp instance with -d:debugCommunication enabled.\n   The nimlsp binary being tested doesn't require this flag.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmunch%2Fnimlsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmunch%2Fnimlsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmunch%2Fnimlsp/lists"}