Skip to content

Python language server

Sergey Skorik edited this page Sep 11, 2018 · 11 revisions

Preconditions:

  1. Create workspace from the Python stack with console-python3-simple project.
  2. Enable Python language server in the Installers tab and start the workspace.
  3. Create "calc.py" file with content:
import main.py

var2 = main.add(100, 200)
  1. Create “towers.py” file with content:
def towers(i, start, finish, middle):
    if i > 0:
        towers(i-1, start, middle, finish)
        print('move disk from ', start, ' to ', finish)
        towers  ( i-1, middle, finish, start   )

towers  ( 5, 'X', 'Z', 'Y'      )
  1. Create "main.py" with content:
class MyClass:
    var = 1
    variable = "variable"

    def function(self):
        print("This is a message inside the class.")


def add(a, b):
    return a + b

Testing process

  • Language server initialization
  1. From the project open "main.py" file.
  2. Check Finished language servers initialization, file path '/console-python3-simple/main.py' message in the dev-machine console.
  • Autocomplete feature
  1. Open "main.py" file.
  2. In the last line type code fragment like myobjectx = MyClass().
  3. Press ENTER button, type "myobjectx." and than Ctrl+Space buttons. Make sure that function, var and variable fields are available from the class in the proposal menu.
  4. Delete added lines
  • Find definition feature
  1. Open "calc.py" file.
  2. Set cursor to 3:15 position and invoke Assistant -> Find Definition. The "main.py" file should be opened and add function should be selected.
  3. Close the "main.py" file. Repeat previous step using F4 key instead of Assistant -> Find Definition invocation.
  • Code validation feature, Comment line
  1. Open "calc.py" file.
  2. Move cursor in 1:1 position.
  3. Type any symbol there and check that error marker is appeared. Click on error marker - the proposal widget should be show invalid syntax message.
  4. Restore content. Error marker should disappear.
  5. Add empty line in the end of file and press SPACE button. Make sure that warning marker with message: W293 blank line contains whitespace in line 4 is present.
  6. Delete this line. The warning marker should disappear.
  7. Move cursor in line 3 position and comment this line by Ctrl+/ buttons.
  8. Check that text in line 3 was changed from var2 = main.add(100, 200) to #var2 = main.add(100, 200).
  9. Uncomment this line by Ctrl+/ buttons.
  • Hover feature
  1. Open "main.py" file.
  2. Move mouse pointer on position 6:12(print function).
  3. Wait hover popup is appeared with text Prints the values to a stream, of to sys.stdout by default.
  • Format code feature
  1. Open "towers.py" file.
  2. Select all text on line 7.
  3. Start Format option from context menu;
  4. Check that the file content after formatting selected code was changed to:
def towers(i, start, finish, middle):
    if i > 0:
        towers(i-1, start, middle, finish)
        print('move disk from ', start, ' to ', finish)
        towers  ( i-1, middle, finish, start   )


towers(5, 'X', 'Z', 'Y')
  1. Start Format option from context menu again.
  2. Check that the file content after full file formatting was changed to:
def towers(i, start, finish, middle):
    if i > 0:
        towers(i-1, start, middle, finish)
        print('move disk from ', start, ' to ', finish)
        towers(i-1, middle, finish, start)


towers(5, 'X', 'Z', 'Y')

Rename

  1. Open "main.py" file.
  2. Select "var" variable.
  3. Start Rename feature by Shift+F6 or from Assistant menu.
  4. Type new variable name.
  5. Check that the variable name was changed.

Find References

  1. Open "calc.py" file.
  2. Select var2 variable.
  3. Start Find References feature by pressing Alt+F7 buttons or from Assistant menu.
  4. Check that Find References panel is opened with /console-python3-simple/calc.py From:3:0 To:3:5 result in it.

Signature Help

  1. Open "calc.py" file.
  2. Type main.add on line 4.
  3. Type '(' symbol and wait for hover popup with add(a,b) text.
  4. Delete added line

Go To Symbol

  1. Open "main.py" file.
  2. Start Go To Symbol feature by Ctrl+F12 buttons or from Assistant menu.
  3. Wait for Go To Symbol form is opened with next lines:
MyClass symbols(5)
var
variable
function
add
  1. Click on any of them and check that it correctly selected in file.