code: def apply_completion(self, completion):
          
          assert isinstance(completion, Completion)
  
          # If there was already a completion active, cancel that one.
          if self.complete_state:
              self.go_to_completion(None)
          self.complete_state = None
  
          # Insert text from the given completion.
          self.delete_before_cursor(-completion.start_position)
          self.insert_text(completion.text)
docs: Insert a given completion.