def test_snippets_completions(data_regression): from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls.impl.robot_workspace import RobotDocument from robotframework_ls.impl import snippets_completions doc = RobotDocument("unused", source="""for""") completions = snippets_completions.complete(CompletionContext(doc)) data_regression.check(completions)
def _threaded_document_completion( self, rf_api_client: IRobotFrameworkApiClient, doc_uri: str, line: int, col: int, monitor: IMonitor, ) -> list: from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls.impl import section_completions from robotframework_ls.impl import snippets_completions from robocorp_ls_core.client_base import wait_for_message_matchers ws = self.workspace if not ws: log.critical("Workspace must be set before returning completions.") return [] document = ws.get_document(doc_uri, accept_from_file=True) if document is None: log.critical("Unable to find document (%s) for completions." % (doc_uri, )) return [] ctx = CompletionContext(document, line, col, config=self.config) completions = [] # Asynchronous completion. message_matchers: List[Optional[IIdMessageMatcher]] = [] message_matchers.append( rf_api_client.request_complete_all(doc_uri, line, col)) # These run locally (no need to get from the server). completions.extend(section_completions.complete(ctx)) completions.extend(snippets_completions.complete(ctx)) accepted_message_matchers = wait_for_message_matchers( message_matchers, monitor, rf_api_client.request_cancel, DEFAULT_COMPLETIONS_TIMEOUT, ) for message_matcher in accepted_message_matchers: msg = message_matcher.msg if msg is not None: result = msg.get("result") if result: completions.extend(result) return completions
def threaded_monaco_completions_from_code_full( self, prefix: str, full_code: str, position: PositionTypedDict, uri: str, indent: str, monitor: Optional[IMonitor] = None, ): from robotframework_ls.impl.robot_workspace import RobotDocument from robotframework_ls.impl.completion_context import CompletionContext from robocorp_ls_core.workspace import Document from robotframework_ls.impl import section_completions from robotframework_ls.impl import snippets_completions from robotframework_ls.server_api.monaco_conversions import ( convert_to_monaco_completion, ) from robotframework_ls.impl.completion_context import CompletionType d = Document(uri, prefix) last_line, _last_col = d.get_last_line_col() line = last_line + position["line"] col = position["character"] col += len(indent) document = RobotDocument(uri, full_code) completion_context = CompletionContext( document, line, col, config=self.config, monitor=monitor, workspace=self.workspace, ) completion_context.type = CompletionType.shell completions = self._complete_from_completion_context(completion_context) completions.extend(section_completions.complete(completion_context)) completions.extend(snippets_completions.complete(completion_context)) return { "suggestions": [ convert_to_monaco_completion( c, line_delta=last_line, col_delta=len(indent), uri=uri ) for c in completions ] }
def m_text_document__completion(self, **kwargs): from robotframework_ls.impl.completion_context import CompletionContext from robotframework_ls.impl import section_completions from robotframework_ls.impl import snippets_completions doc_uri = kwargs["textDocument"]["uri"] # Note: 0-based line, col = kwargs["position"]["line"], kwargs["position"]["character"] document = self.workspace.get_document(doc_uri, accept_from_file=True) if document is None: log.critical("Unable to find document (%s) for completions." % (doc_uri, )) return [] api = self._server_manager.get_regular_api(doc_uri) ctx = CompletionContext(document, line, col, config=self.config) completions = [] # Asynchronous completion. message_matchers = [] message_matchers.append(api.request_complete_all(doc_uri, line, col)) # These run locally (no need to get from the server). completions.extend(section_completions.complete(ctx)) completions.extend(snippets_completions.complete(ctx)) accepted_message_matchers = self._wait_for_message_matchers( message_matchers) for message_matcher in accepted_message_matchers: msg = message_matcher.msg if msg is not None: result = msg.get("result") if result: completions.extend(result) return completions