def m_text_document__signature_help(self, **kwargs):
        """
        "params": {
            "textDocument": {
                "uri": "file:///x%3A/vscode-robot/local_test/Basic/resources/keywords.robot"
            },
            "position": {"line": 7, "character": 22},
            "context": {
                "isRetrigger": False,
                "triggerCharacter": " ",
                "triggerKind": 2,
            },
        },
        """
        doc_uri = kwargs["textDocument"]["uri"]
        # Note: 0-based
        line, col = kwargs["position"]["line"], kwargs["position"]["character"]

        rf_api_client = self._server_manager.get_regular_rf_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(self._signature_help, rf_api_client, doc_uri, line,
                           col)
            func = require_monitor(func)
            return func

        log.info("Unable to get signature (no api available).")
        return []
    def m_workspace__symbol(self, query: Optional[str] = None) -> Any:
        api_client = self._server_manager.get_workspace_symbols_api_client()
        if api_client is not None:
            ret = partial(self._threaded_workspace_symbol, api_client, query)
            ret = require_monitor(ret)
            return ret

        log.info("Unable to search workspace symbols (no api available).")
        return None  # Unable to get the api.
 def m_semantic_tokens_from_code_full(
     self, prefix: str = "", full_code: str = "", indent: str = ""
 ):
     func = partial(
         self.threaded_semantic_tokens_from_code_full,
         prefix=prefix,
         full_code=full_code,
         indent=indent,
     )
     func = require_monitor(func)
     return func
    def m_text_document__completion(self, **kwargs):
        doc_uri = kwargs["textDocument"]["uri"]
        # Note: 0-based
        line, col = kwargs["position"]["line"], kwargs["position"]["character"]

        rf_api_client = self._server_manager.get_regular_rf_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(self._threaded_document_completion, rf_api_client,
                           doc_uri, line, col)
            func = require_monitor(func)
            return func

        log.info("Unable to get completions (no api available).")
        return []
    def m_text_document__definition(self, **kwargs):
        doc_uri = kwargs["textDocument"]["uri"]
        # Note: 0-based
        line, col = kwargs["position"]["line"], kwargs["position"]["character"]

        rf_api_client = self._server_manager.get_regular_rf_api_client(doc_uri)
        if rf_api_client is not None:
            ret = partial(self._threaded_document_definition, rf_api_client,
                          doc_uri, line, col)
            ret = require_monitor(ret)
            return ret

        log.info("Unable to find definition (no api available).")
        return None  # Unable to get the api.
    def m_lint(self, doc_uri):
        if not self._check_min_version((3, 2)):
            from robocorp_ls_core.lsp import Error

            msg = (
                "robotframework version (%s) too old for linting.\n"
                "Please install a newer version and restart the language server."
                % (self.m_version(), ))
            log.info(msg)
            return [Error(msg, (0, 0), (1, 0)).to_lsp_diagnostic()]

        func = partial(self._threaded_lint, doc_uri)
        func = require_monitor(func)
        return func
    def m_workspace__symbol(self, query: Optional[str] = None) -> Any:
        api = self._server_manager.get_others_api_client("")
        if api is None:
            log.info("Unable to search workspace symbols (no api available).")
            return None

        func = partial(
            self._async_api_request_no_doc,
            api,
            "request_workspace_symbols",
            query=query,
        )
        func = require_monitor(func)
        return func
    def m_text_document__document_symbol(self, **kwargs):
        doc_uri = kwargs["textDocument"]["uri"]

        rf_api_client = self._server_manager.get_others_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(
                self._async_api_request,
                rf_api_client,
                "request_document_symbol",
                doc_uri=doc_uri,
            )
            func = require_monitor(func)
            return func

        log.info("Unable to get document symbol (no api available).")
        return []
    def m_text_document__semantic_tokens__full(self, textDocument=None):
        doc_uri = textDocument["uri"]
        api = self._server_manager.get_others_api_client(doc_uri)
        if api is None:
            log.info(
                "Unable to get api client when computing semantic tokens (full)."
            )
            return {"resultId": None, "data": []}

        func = partial(
            self._async_api_request_no_doc,
            api,
            "request_semantic_tokens_full",
            text_document=textDocument,
        )
        func = require_monitor(func)
        return func
Exemple #10
0
 def m_monaco_completions_from_code_full(
     self,
     prefix: str = "",
     full_code: str = "",
     position=PositionTypedDict,
     uri: str = "",
     indent: str = "",
 ):
     func = partial(
         self.threaded_monaco_completions_from_code_full,
         prefix=prefix,
         full_code=full_code,
         position=position,
         uri=uri,
         indent=indent,
     )
     func = require_monitor(func)
     return func
    def m_text_document__hover(self, **kwargs):
        doc_uri = kwargs["textDocument"]["uri"]
        # Note: 0-based
        line, col = kwargs["position"]["line"], kwargs["position"]["character"]
        rf_api_client = self._server_manager.get_regular_rf_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(
                self._async_api_request,
                rf_api_client,
                "request_hover",
                doc_uri=doc_uri,
                line=line,
                col=col,
            )
            func = require_monitor(func)
            return func

        log.info("Unable to compute hover (no api available).")
        return []
    def m_text_document__code_lens(self, *args, **kwargs) -> Optional[list]:
        """
        "params": {
            "textDocument": {
                "uri": "file:///x%3A/vscode-robot/local_test/Basic/resources/keywords.robot"
            }
        },
        """

        doc_uri = kwargs["textDocument"]["uri"]

        rf_api_client = self._server_manager.get_regular_rf_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(self._code_lens, rf_api_client, doc_uri)
            func = require_monitor(func)
            return func

        log.info("Unable to get folding range (no api available).")
        return []
    def m_text_document__folding_range(self, **kwargs):
        """
        "params": {
            "textDocument": {
                "uri": "file:///x%3A/vscode-robot/local_test/Basic/resources/keywords.robot"
            },
        },
        """
        doc_uri = kwargs["textDocument"]["uri"]

        rf_api_client = self._server_manager.get_others_api_client(doc_uri)
        if rf_api_client is not None:
            func = partial(
                self._async_api_request,
                rf_api_client,
                "request_folding_range",
                doc_uri=doc_uri,
            )
            func = require_monitor(func)
            return func

        log.info("Unable to get folding range (no api available).")
        return []
    def m_code_lens__resolve(self, **kwargs):
        code_lens: CodeLensTypedDict = kwargs

        code_lens_command = code_lens.get("command")
        data = code_lens.get("data")
        if code_lens_command is None and isinstance(data, dict):
            # For the interactive shell we need to resolve the arguments.
            uri = data.get("uri")

            rf_api_client = self._server_manager.get_others_api_client(uri)
            if rf_api_client is not None:
                func = partial(
                    self._async_api_request_no_doc,
                    rf_api_client,
                    "request_resolve_code_lens",
                    code_lens=code_lens,
                )
                func = require_monitor(func)
                return func

            log.info("Unable to resolve code lens (no api available).")

        return code_lens
Exemple #15
0
 def m_text_document__semantic_tokens__full(self, textDocument=None):
     func = partial(self.threaded_semantic_tokens_full, textDocument=textDocument)
     func = require_monitor(func)
     return func
Exemple #16
0
 def m_workspace_symbols(self, query: Optional[str] = None):
     func = partial(self._threaded_workspace_symbols, query)
     func = require_monitor(func)
     return func
Exemple #17
0
 def m_hover(self, doc_uri: str, line: int, col: int):
     func = partial(self._threaded_hover, doc_uri, line, col)
     func = require_monitor(func)
     return func
Exemple #18
0
 def m_list_tests(self, doc_uri: str):
     func = partial(self._threaded_list_tests, doc_uri)
     func = require_monitor(func)
     return func
Exemple #19
0
 def m_document_symbol(self, doc_uri: str):
     func = partial(self._threaded_document_symbol, doc_uri)
     func = require_monitor(func)
     return func
Exemple #20
0
 def m_resolve_code_lens(self, **code_lens: CodeLensTypedDict):
     func = partial(self._threaded_resolve_code_lens, code_lens)
     func = require_monitor(func)
     return func
Exemple #21
0
 def m_code_lens(self, doc_uri: str):
     func = partial(self._threaded_code_lens, doc_uri)
     func = require_monitor(func)
     return func
Exemple #22
0
 def m_folding_range(self, doc_uri: str):
     func = partial(self._threaded_folding_range, doc_uri)
     func = require_monitor(func)
     return func
Exemple #23
0
 def m_signature_help(self, doc_uri: str, line: int, col: int):
     func = partial(self._threaded_signature_help, doc_uri, line, col)
     func = require_monitor(func)
     return func
Exemple #24
0
 def m_code_format(self, text_document, options):
     func = partial(self._threaded_code_format, text_document, options)
     func = require_monitor(func)
     return func
Exemple #25
0
 def m_find_definition(self, doc_uri, line, col):
     func = partial(self._threaded_find_definition, doc_uri, line, col)
     func = require_monitor(func)
     return func
Exemple #26
0
 def m_complete_all(self, doc_uri, line, col):
     func = partial(self._threaded_complete_all, doc_uri, line, col)
     func = require_monitor(func)
     return func
    def m_workspace__execute_command(self, command=None, arguments=()) -> Any:
        if command == "robot.addPluginsDir":
            directory: str = arguments[0]
            assert os.path.isdir(
                directory), f"Expected: {directory} to be a directory."
            self._pm.load_plugins_from(Path(directory))
            return True

        elif command == "robot.getInternalInfo":
            in_memory_docs = []
            workspace = self.workspace
            if workspace:
                for doc in workspace.iter_documents():
                    in_memory_docs.append({"uri": doc.uri})
            return {
                "settings": self.config.get_full_settings(),
                "inMemoryDocs": in_memory_docs,
                "processId": os.getpid(),
            }

        elif command == "robot.resolveInterpreter":
            try:
                from robocorp_ls_core import uris
                from robotframework_ls.ep_resolve_interpreter import (
                    EPResolveInterpreter, )
                from robotframework_ls.ep_resolve_interpreter import IInterpreterInfo

                target_robot: str = arguments[0]

                for ep in self._pm.get_implementations(EPResolveInterpreter):
                    interpreter_info: IInterpreterInfo = ep.get_interpreter_info_for_doc_uri(
                        uris.from_fs_path(target_robot))
                    if interpreter_info is not None:
                        return {
                            "pythonExe":
                            interpreter_info.get_python_exe(),
                            "environ":
                            interpreter_info.get_environ(),
                            "additionalPythonpathEntries":
                            interpreter_info.get_additional_pythonpath_entries(
                            ),
                        }
            except:
                log.exception(
                    f"Error resolving interpreter. Args: {arguments}")

        elif command == "robot.getLanguageServerVersion":
            return __version__

        elif command.startswith("robot.internal.rfinteractive."):
            return rf_interactive_integration.execute_command(
                command, self, self._rf_interpreters_manager, arguments)

        elif command == "robot.listTests":
            doc_uri = arguments[0]["uri"]

            rf_api_client = self._server_manager.get_others_api_client(doc_uri)
            if rf_api_client is not None:
                func = partial(
                    self._async_api_request,
                    rf_api_client,
                    "request_list_tests",
                    doc_uri=doc_uri,
                )
                func = require_monitor(func)
                return func

            log.info("Unable to list tests (no api available).")
            return []