# nwscript-lsp
[![PyPI version](https://badge.fury.io/py/nwscript-language-server.svg)](https://badge.fury.io/py/nwscript-language-server)
The LSP is built on [pygls](https://github.com/openlawlibrary/pygls) and [rollnw](https://github.com/jd28/rollnw). It is derived from the [Pygls Playground](https://github.com/openlawlibrary/pygls/tree/main/examples/vscode-playground) and aims, at this point, only to be a tested bed for implementing LSP features. A more robust implementation will come later maybe integrating with [nasher.cfg](https://github.com/squattingmonk/nasher#nashercfg). For now only the current document path will be added to the include path of the script context resman.
That the testbed extension is for vscode is out of simplicity, obviously plugins for any LSP client emacs, (neo)vim, etc will be supported.
Currently, it implements:
* Completions
* Hover
* Workspace Diagnostics
* Document Symbols
* Signature Help
## Setup - Neovim
1. Install required package
```
python -m pip install rollnw
```
2. Install the language server
```
python -m pip install nwscript-language-server
```
Note: Sometimes "--break-system-packages" is needed to install
```
python -m pip install --break-system-packages rollnw
python -m pip install --break-system-packages nwscript-language-server
```
3. Make sure ``nwscript-language-server`` is on your PATH!
4. Setup neovim config - Obviously people's tastes will differ here and not all of it is fully implemented.
```lua
require("config.lazy")
vim.api.nvim_exec(
[[
autocmd FileType nwscript setlocal lsp
]],
false
)
local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")
if not configs.nwscript_language_server then
configs.nwscript_language_server = {
default_config = {
cmd = { "nwscript-language-server" },
filetypes = { "nwscript" },
root_dir = lspconfig.util.root_pattern(".git", "nasher.cfg"),
},
}
end
lspconfig.nwscript_language_server.setup({
on_attach = function(client, bufnr)
-- Custom on_attach function (optional)
print("nwscript language server attached!")
require("lsp_signature").on_attach({
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = "rounded",
},
}, bufnr)
-- Enable snippet support (if your completion plugin supports snippets)
vim.bo[bufnr].expandtab = false
vim.bo[bufnr].shiftwidth = 4
end,
settings = {
["nwscript-language-server"] = {
disableSnippets = "on",
},
},
})
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})
```
## Setup - VS Code Extension debug mode
### Install Server Dependencies
Open a terminal in the repository's root directory
1. Create a virtual environment
```
python -m venv env
```
2. Install pygls
```
python -m pip install -r requirements.txt
```
### Install Client Dependencies
Open terminal in the same directory as this file and execute following commands:
1. Install node dependencies
```
npm install
```
2. Compile the extension
```
npm run compile
```
Alternatively you can run `npm run watch` if you are going to be actively working on the extension itself.
### Run Extension
1. Open this directory in VS Code
2. The playground relies on the [Python extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for choosing the appropriate Python environment in which to run the example language servers.
If you haven't already, you will need to install it and reload the window.
3. Open the Run and Debug view (`ctrl + shift + D`)
4. Select `Launch Client` and press `F5`, this will open a second VSCode window with the `vscode-playground` extension enabled.
5. You will need to make sure that VSCode is using a virtual environment that contains an installation of `pygls`.
The `Python: Select Interpreter` command can be used to pick the correct one.
Alternatively, you can set the `pygls.server.pythonPath` option in the `.vscode/settings.json` file
Raw data
{
"_id": null,
"home_page": "https://github.com/jd28/nwscript-lsp",
"name": "nwscript-language-server",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "nwscript, completion, lsp, language-server-protocol",
"author": "jmd",
"author_email": "joshua.m.dean@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6d/51/f40bbd0f1eacdaf9b7f3cb56f62c2f4b14e653ce62b21da98cd76300d20d/nwscript_language_server-0.12.dev0.tar.gz",
"platform": null,
"description": "# nwscript-lsp\n\n[![PyPI version](https://badge.fury.io/py/nwscript-language-server.svg)](https://badge.fury.io/py/nwscript-language-server)\n\n\nThe LSP is built on [pygls](https://github.com/openlawlibrary/pygls) and [rollnw](https://github.com/jd28/rollnw). It is derived from the [Pygls Playground](https://github.com/openlawlibrary/pygls/tree/main/examples/vscode-playground) and aims, at this point, only to be a tested bed for implementing LSP features. A more robust implementation will come later maybe integrating with [nasher.cfg](https://github.com/squattingmonk/nasher#nashercfg). For now only the current document path will be added to the include path of the script context resman.\n\nThat the testbed extension is for vscode is out of simplicity, obviously plugins for any LSP client emacs, (neo)vim, etc will be supported.\n\nCurrently, it implements:\n* Completions\n* Hover\n* Workspace Diagnostics\n* Document Symbols\n* Signature Help\n\n## Setup - Neovim\n\n1. Install required package\n ```\n python -m pip install rollnw\n ```\n\n2. Install the language server\n ```\n python -m pip install nwscript-language-server\n ```\n\nNote: Sometimes \"--break-system-packages\" is needed to install\n ```\n python -m pip install --break-system-packages rollnw\n python -m pip install --break-system-packages nwscript-language-server\n ```\n\n3. Make sure ``nwscript-language-server`` is on your PATH!\n\n4. Setup neovim config - Obviously people's tastes will differ here and not all of it is fully implemented.\n ```lua\n require(\"config.lazy\")\n\n vim.api.nvim_exec(\n [[\n autocmd FileType nwscript setlocal lsp\n ]],\n false\n )\n\n local lspconfig = require(\"lspconfig\")\n local configs = require(\"lspconfig.configs\")\n\n if not configs.nwscript_language_server then\n configs.nwscript_language_server = {\n default_config = {\n cmd = { \"nwscript-language-server\" },\n filetypes = { \"nwscript\" },\n root_dir = lspconfig.util.root_pattern(\".git\", \"nasher.cfg\"),\n },\n }\n end\n\n lspconfig.nwscript_language_server.setup({\n on_attach = function(client, bufnr)\n -- Custom on_attach function (optional)\n print(\"nwscript language server attached!\")\n\n require(\"lsp_signature\").on_attach({\n bind = true, -- This is mandatory, otherwise border config won't get registered.\n handler_opts = {\n border = \"rounded\",\n },\n }, bufnr)\n\n -- Enable snippet support (if your completion plugin supports snippets)\n vim.bo[bufnr].expandtab = false\n vim.bo[bufnr].shiftwidth = 4\n end,\n settings = {\n [\"nwscript-language-server\"] = {\n disableSnippets = \"on\",\n },\n },\n })\n\n -- Global mappings.\n -- See `:help vim.diagnostic.*` for documentation on any of the below functions\n vim.keymap.set(\"n\", \"<space>e\", vim.diagnostic.open_float)\n vim.keymap.set(\"n\", \"[d\", vim.diagnostic.goto_prev)\n vim.keymap.set(\"n\", \"]d\", vim.diagnostic.goto_next)\n vim.keymap.set(\"n\", \"<space>q\", vim.diagnostic.setloclist)\n\n -- Use LspAttach autocommand to only map the following keys\n -- after the language server attaches to the current buffer\n vim.api.nvim_create_autocmd(\"LspAttach\", {\n group = vim.api.nvim_create_augroup(\"UserLspConfig\", {}),\n callback = function(ev)\n -- Enable completion triggered by <c-x><c-o>\n vim.bo[ev.buf].omnifunc = \"v:lua.vim.lsp.omnifunc\"\n\n -- Buffer local mappings.\n -- See `:help vim.lsp.*` for documentation on any of the below functions\n local opts = { buffer = ev.buf }\n vim.keymap.set(\"n\", \"gD\", vim.lsp.buf.declaration, opts)\n vim.keymap.set(\"n\", \"gd\", vim.lsp.buf.definition, opts)\n vim.keymap.set(\"n\", \"K\", vim.lsp.buf.hover, opts)\n vim.keymap.set(\"n\", \"gi\", vim.lsp.buf.implementation, opts)\n vim.keymap.set(\"n\", \"<C-k>\", vim.lsp.buf.signature_help, opts)\n vim.keymap.set(\"n\", \"<space>wa\", vim.lsp.buf.add_workspace_folder, opts)\n vim.keymap.set(\"n\", \"<space>wr\", vim.lsp.buf.remove_workspace_folder, opts)\n vim.keymap.set(\"n\", \"<space>wl\", function()\n print(vim.inspect(vim.lsp.buf.list_workspace_folders()))\n end, opts)\n vim.keymap.set(\"n\", \"<space>D\", vim.lsp.buf.type_definition, opts)\n vim.keymap.set(\"n\", \"<space>rn\", vim.lsp.buf.rename, opts)\n vim.keymap.set({ \"n\", \"v\" }, \"<space>ca\", vim.lsp.buf.code_action, opts)\n vim.keymap.set(\"n\", \"gr\", vim.lsp.buf.references, opts)\n vim.keymap.set(\"n\", \"<space>f\", function()\n vim.lsp.buf.format({ async = true })\n end, opts)\n end,\n })\n ```\n\n## Setup - VS Code Extension debug mode\n\n### Install Server Dependencies\n\nOpen a terminal in the repository's root directory\n\n1. Create a virtual environment\n ```\n python -m venv env\n ```\n\n2. Install pygls\n ```\n python -m pip install -r requirements.txt\n ```\n\n### Install Client Dependencies\n\nOpen terminal in the same directory as this file and execute following commands:\n\n1. Install node dependencies\n\n ```\n npm install\n ```\n2. Compile the extension\n\n ```\n npm run compile\n ```\n Alternatively you can run `npm run watch` if you are going to be actively working on the extension itself.\n\n### Run Extension\n\n1. Open this directory in VS Code\n\n2. The playground relies on the [Python extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for choosing the appropriate Python environment in which to run the example language servers.\n If you haven't already, you will need to install it and reload the window.\n\n3. Open the Run and Debug view (`ctrl + shift + D`)\n\n4. Select `Launch Client` and press `F5`, this will open a second VSCode window with the `vscode-playground` extension enabled.\n\n5. You will need to make sure that VSCode is using a virtual environment that contains an installation of `pygls`.\n The `Python: Select Interpreter` command can be used to pick the correct one.\n\n Alternatively, you can set the `pygls.server.pythonPath` option in the `.vscode/settings.json` file\n",
"bugtrack_url": null,
"license": null,
"summary": "A language server for Bioware's nwscript",
"version": "0.12.dev0",
"project_urls": {
"Homepage": "https://github.com/jd28/nwscript-lsp",
"Repository": "https://github.com/jd28/nwscript-lsp"
},
"split_keywords": [
"nwscript",
" completion",
" lsp",
" language-server-protocol"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6e856d85c8fac009d2a545c2ffa07eb4224de0429df11e460e6ce4462f10193c",
"md5": "200a47c9f544453ea2592181901b0318",
"sha256": "7a6198aedaf32dd7b4f0c5c068335e7b6cbc65fd8556403eb7c471dead34f21e"
},
"downloads": -1,
"filename": "nwscript_language_server-0.12.dev0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "200a47c9f544453ea2592181901b0318",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 13493,
"upload_time": "2024-10-16T05:08:53",
"upload_time_iso_8601": "2024-10-16T05:08:53.508826Z",
"url": "https://files.pythonhosted.org/packages/6e/85/6d85c8fac009d2a545c2ffa07eb4224de0429df11e460e6ce4462f10193c/nwscript_language_server-0.12.dev0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6d51f40bbd0f1eacdaf9b7f3cb56f62c2f4b14e653ce62b21da98cd76300d20d",
"md5": "371e46e16de7afc97f1557d232e836f3",
"sha256": "6470b6af879ecbfd16112174f8a4c4104ad3a2d994915c39f4d4d74385ca8985"
},
"downloads": -1,
"filename": "nwscript_language_server-0.12.dev0.tar.gz",
"has_sig": false,
"md5_digest": "371e46e16de7afc97f1557d232e836f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 13615,
"upload_time": "2024-10-16T05:08:54",
"upload_time_iso_8601": "2024-10-16T05:08:54.796504Z",
"url": "https://files.pythonhosted.org/packages/6d/51/f40bbd0f1eacdaf9b7f3cb56f62c2f4b14e653ce62b21da98cd76300d20d/nwscript_language_server-0.12.dev0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-16 05:08:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jd28",
"github_project": "nwscript-lsp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nwscript-language-server"
}