#!/usr/bin/env python # coding: utf-8 # ## Python LSP # ### Hover action # In[1]: def square(x): """Can you see me?""" return x*x # Hover over `square` and see an underline appear; press Ctrl to display tooltip with the docstring. # In[2]: result = square(2) # ### Inspections # 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. # In[3]: from statistics import mean # You can also hover over `statistics` and `mean` (while holding Ctrl) to see the documentation of those. # In[4]: undefined_variable # you will see red underline for an undefined variable (example above) or for an invalid syntax. # Also, spurious whitespaces can be highlighted (if server supports such diagnostic): # In[5]: class Dog: def bark(self): print('🐕 woof woof') # In[ ]: # In[6]: Dog().bark() # 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! # #### Diagnostics Panel # Search for "Show diagnostics panel" in the commands palette, or invoke it from the context menu to display all the diagnostics from the file in one place. # # The diagnostics panel allows you to sort the inspections and go to the respective locations in the code (just click on the row of interest). # ### Autocompletion # In[ ]: class Cat: def miaow(self): print('miaow') # Autocompletion works without the kernel - try completing "Cat" below using Tab, without running the cell above: # In[ ]: Ca # You can see that all the double-dunder methods of the class are immediately available: # In[ ]: Cat.__ # It also automatically invokes the completion suggestions after typing a dot (.): # In[ ]: Cat # ### Rename # You can rename symbols by pressing F2 or selecting rename option from the context menu. # # If you rename the `test` variable below to `test2`, both occurrences (in the two following cells) will be updated: # In[ ]: test = 1 # In[ ]: test # However, a local reference from a different scope (inside the `abc()` function) will be unafected: # In[ ]: def abc(): test = 2 test # Which is different to the simplistic behaviour of the built-in search-and-replace function.