{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Language Servers\n", "\n", "`jupyter-lsp` does not come with any Language Servers! However, we will try to\n", "use them if they _are_ installed and we know about them. For the language\n", "servers in the tables below, use one of the suggested package managers to\n", "install them: these implementations are tested to work with `jupyter-lsp`.\n", "\n", "- _You can disable this feature by configuring_\n", " [autodetect](./Configuring.ipynb#autodetect)\n", "\n", "If you do not see a language you would like, but can find it one of these lists:\n", "\n", "- the [official list][lsp-implementations] of language servers\n", "- a [community-curated list][langserver] of language servers\n", "\n", "...you might be able to add it\n", "[via configuration](./Configuring.ipynb#language_servers) or\n", "[build your own spec](./Contributing.ipynb#Specs) for the server in question.\n", "\n", "[language-server]:\n", " https://microsoft.github.io/language-server-protocol/specification\n", "[langserver]: https://langserver.org\n", "[lsp-implementations]:\n", " https://microsoft.github.io/language-server-protocol/implementors/servers" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "import pathlib\n", "\n", "import IPython\n", "from jinja2 import Template\n", "from jupyter_lsp import LanguageServerManager" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "mgr = LanguageServerManager(extra_node_roots=[str(pathlib.Path.cwd().parent)])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "mgr.init_language_servers()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "def lang_server_table(specs):\n", " return IPython.display.HTML(\n", " Template(\n", " \"\"\"\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " {% for key, spec in specs.items() %}\n", " \n", " \n", " \n", " \n", " \n", " {% endfor %}\n", " \n", "
LanguagesImplementationInstallation
\n", " {% for lang in spec.languages %}\n", " {{ lang }}
\n", " {% endfor %}\n", "
\n", " {{key}}\n", " \n", "
    \n", " {% for pkgmgr, inst in spec.install.items() %}\n", "
  • {{pkgmgr}}: {{ inst }}
  • \n", " {% endfor %}\n", "
\n", "
\n", " \"\"\"\n", " ).render(specs=specs)\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notebook-Optimized Language Servers\n", "\n", "These servers have well-tested support for notebooks and file editors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "nb_langs = [\"pyls\", \"r-languageserver\"]\n", "lang_server_table(\n", " {key: spec for key, spec in mgr.language_servers.items() if key in nb_langs}\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### NodeJS-based Language Servers\n", "\n", "These servers have mostly been tested with file editors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "lang_server_table(\n", " {\n", " key: spec\n", " for key, spec in mgr.language_servers.items()\n", " if \"npm\" in spec[\"install\"]\n", " }\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example: Getting All the NodeJS-based Language Servers\n", "\n", "A number of language servers are built on the\n", "[reference implementation](https://github.com/microsoft/vscode-languageserver-node),\n", "powered by NodeJS. The most reliable place to install these is in a\n", "`node_modules` in the directory where you launch `jupyter lab`.\n", "\n", "For example, to install all the servers which are tested as part of\n", "`jupyterlab-lsp`:\n", "\n", "```bash\n", "jlpm add --dev \\\n", " bash-language-server \\\n", " vscode-css-languageserver-bin \\\n", " dockerfile-language-server-nodejs \\\n", " vscode-html-languageserver-bin \\\n", " javascript-typescript-langserver \\\n", " vscode-json-languageserver-bin \\\n", " yaml-language-server\n", "```\n", "\n", "This will create create (or add to):\n", "\n", "- `package.json` (check this in!)\n", "- `yarn.lock` (check this in!)\n", "- `node_modules/` (add to your VCS ignore file)\n", "\n", "If you wish to install these someplace else, you may need to specify where you\n", "install them with [extra_node_roots](./Configuring.ipynb#extra_node_roots)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Other Scientific Languages\n", "\n", "These servers have been mostly tested with file editor." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "sci_langs = [\"texlab\"]\n", "lang_server_table(\n", " {key: spec for key, spec in mgr.language_servers.items() if key in sci_langs}\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example: Getting a $\\LaTeX$ stack\n", "\n", "```bash\n", "conda install -y conda-forge tectonic texlab chktex\n", "```\n", "\n", "This will install:\n", "\n", "- `tectonic`, a cross-platform $\\LaTeX$ processing tool\n", " - note, it will download a large number of packages when first executed\n", "- `texlab`, a Language Server for `.tex` files that supports completion and\n", " refernce navigation\n", "- `chktex`, a `.tex` style checker" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "%%html\n", "" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }