Sublime Forum

Is it possible to use Python stubs for intellisense-like autocomplete

#1

I’m currently trying to write Python scripts to help me automate some tasks in an Unreal Engine project, but the Python API for Unreal is huge, the docs are not great, and docs search is slow. To help me easily find functions, I’d like to be able to use a Python stub file (generated by the engine, and named unreal.py) to give Sublime Text information about the API so it can provide me with autocomplete suggestions, and ideally show function parameters etc. as an IDE might. I’ve seen examples of people using this stub file to set up autocomplete with PyCharm, and was wondering if it was possible in Sublime.

If someone has experience with this kind of thing and can explain how to set it up, I would be super happy.

Below is an example of the code inside the stub file unreal.py:

class LayersSubsystem(EditorSubsystem):
    """
    Layers Subsystem
    
    **C++ Source:**
    
    - **Module**: UnrealEd
    - **File**: LayersSubsystem.h
    
    """
    def update_all_view_visibility(self, layer_that_changed):
        """
        x.update_all_view_visibility(layer_that_changed) -> None
        Updates the visibility for all actors for all views.
        
        Args:
            layer_that_changed (Name): If one layer was changed (toggled in view pop-up, etc), then we only need to modify actors that use that layer.
        """
        return None
0 Likes

#2

Yes this is possible with LSP-pyright.

0 Likes

#3

Thank you! Hopefully I can figure out how to set it up properly.

0 Likes

#5

If anyone ends up here and has no idea what they’re doing, here’s a step by step solution

Open Sublime and install Package Control

Details here: https://packagecontrol.io/installation

  1. Open the command palette
    Win/Linux: ctrl+shift+p, Mac: cmd+shift+p
  2. Type Install Package Control, press enter
Install LSP

Details here: https://github.com/sublimelsp/LSP-pyright

  • Install LSP and LSP-pyright via Package Control.
    Installing via Package Control just means you (inside Sublime):
    Ctrl+Shift+P
    type ‘pc install’, Enter
    type ‘LSP’, Enter
    repeat for LSP-pyright
  • (Optional but recommended) Install the LSP-file-watcher-chokidar via Package Control to enable functionality to notify the server about new files.
  • Restart Sublime.
Configure Sublime/LSP

In Sublime
click Preferences>PackageSettings>LSP>Servers>LSP-pyright
a new sublime window will open
on the right tab (LSP-pyright.sublime-settings)
copy paste this with your project path:

{
   "settings": {
      "LSP": {
         "LSP-pyright": {
            "settings": {
               "python.analysis.extraPaths": ["yourPC\\Unreal Projects\\Project\\Intermediate\\PythonStub"]
            }
         }
      }
   }
}

and you’re done!

0 Likes