{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Python LSP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Hover action" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "def square(x):\n", " \"\"\"Can you see me?\"\"\"\n", " return x*x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hover over `square` and see an underline appear; press `Ctrl` to display tooltip with the docstring." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "result = square(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Inspections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This import is underlied as it should be placed at the top of the file; it has an orange underline as this is only a warning." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from statistics import mean" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also hover over statistics and mean (while holding `Ctrl`) to see the documentation of those." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (, line 1)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m if there is invalid syntax:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ "if there is invalid syntax:\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "you will see red underline (\"invalid\" and \"syntax\" above are two expressions which canno be place next to each other without an operator)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Also, spurious whitespaces can be highlighted (if server supports such diagnostic):" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "class Dog:\n", " \n", " def bark(self):\n", " print('🐕 woof woof')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "🐕 woof woof\n" ] } ], "source": [ "Dog().bark()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Empty cells will cause \"too many blank lines\" warning as each cell is padded with two new lines. If we remove the blank cell, everything will be perfect!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Autocompletion" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class Cat:\n", "\n", " def miaow(self):\n", " print('miaow')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Autocompletion works without the kernel - try completing \"Cat\" below using Tab, without running the cell above: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Ca" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can see that all the double-dunder methods of the class are immediately available:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Cat.__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In future, it will automatically invoke the completion suggestions after typing a dot (.):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Cat" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 4 }