コード例 #1
0
def test_variables_resolved_on_completion_integrated(
    language_server_tcp: ILanguageServerClient, workspace_dir, data_regression, cases
):
    from robocorp_ls_core.workspace import Document

    language_server = language_server_tcp
    language_server.initialize(workspace_dir, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """*** Settings ***
Library           ${ROOT}/directory/my_library.py


*** Keywords ***
Some Keyword
    In Lib"""
    language_server.change_doc(uri, 2, contents)

    # Note: for libraries, if we found it, we keep it in memory (so, even though
    # we removed the entry, it'll still be accessible).
    language_server_tcp.settings(
        {
            "settings": {
                "robot": {"variables": {"ROOT": cases.get_path("case_same_basename")}}
            }
        }
    )

    doc = Document("", source=contents)
    line, col = doc.get_last_line_col()
    completions = language_server.get_completions(uri, line, col)
    data_regression.check(completions)
コード例 #2
0
def test_variables_completions_integrated(
    language_server_tcp: ILanguageServerClient, ws_root_path, data_regression
):
    from robocorp_ls_core.workspace import Document

    language_server = language_server_tcp
    language_server.initialize(ws_root_path, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """
*** Variables ***
${NAME}         Robot Framework
${VERSION}      2.0
${ROBOT}        ${NAME} ${VERSION}

*** Test Cases ***
List Variable
    Log    ${NAME}
    Should Contain    ${"""
    language_server.change_doc(uri, 2, contents)

    doc = Document("", source=contents)
    line, col = doc.get_last_line_col()
    completions = language_server.get_completions(uri, line, col)
    del completions["id"]
    data_regression.check(completions, "variable_completions")

    # Note: for libraries, if we found it, we keep it in memory (so, even though
    # we removed the entry, it'll still be accessible).
    language_server_tcp.settings({"settings": {"robot": {"variables": {"myvar1": 10}}}})

    completions = language_server.get_completions(uri, line, col)
    labels = [x["label"] for x in completions["result"]]
    assert "${myvar1}" in labels
コード例 #3
0
def test_find_definition_keywords(language_server: ILanguageServerClient,
                                  cases, workspace_dir):
    from robocorp_ls_core import uris

    cases.copy_to("case2", workspace_dir)

    language_server.initialize(workspace_dir, process_id=os.getpid())
    case2_robot = os.path.join(workspace_dir, "case2.robot")
    assert os.path.exists(case2_robot)
    uri = uris.from_fs_path(case2_robot)

    language_server.open_doc(uri, 1, text=None)
    ret = language_server.find_definitions(uri, 7, 6)
    result = ret["result"]
    assert len(result) == 1
    check = next(iter(result))
    assert check["uri"].endswith("case2.robot")
    assert check["range"] == {
        "start": {
            "line": 1,
            "character": 0
        },
        "end": {
            "line": 4,
            "character": 5
        },
    }
コード例 #4
0
def test_completions_after_library(
    language_server_tcp: ILanguageServerClient, ws_root_path, data_regression, cases
):
    from robocorp_ls_core.workspace import Document

    case1_path = cases.get_path("case1")

    language_server = language_server_tcp
    language_server.initialize(ws_root_path, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """
*** Settings ***
Library    """
    language_server.change_doc(uri, 2, contents)

    language_server_tcp.settings({"settings": {"robot": {"pythonpath": [case1_path]}}})

    def request_completion():
        doc = Document("", source=contents)
        line, col = doc.get_last_line_col()
        completions = language_server.get_completions(uri, line, col)
        del completions["id"]
        return completions

    assert not request_completion()["result"]
コード例 #5
0
def test_keyword_completions_integrated_pythonpath_library(
        language_server_tcp: ILanguageServerClient, ws_root_path,
        data_regression, cases):
    from robocorp_ls_core.workspace import Document

    case1_path = cases.get_path("case1")

    language_server = language_server_tcp
    language_server.initialize(ws_root_path, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """
*** Settings ***
Library    case1_library

*** Test Cases ***
Check It
    Verify Mod"""
    language_server.change_doc(uri, 2, contents)

    language_server_tcp.settings(
        {"settings": {
            "robot": {
                "pythonpath": [case1_path]
            }
        }})

    def request_completion():
        doc = Document("", source=contents)
        line, col = doc.get_last_line_col()
        completions = language_server.get_completions(uri, line, col)
        del completions["id"]
        return completions

    data_regression.check(request_completion())

    # Note: for libraries, if we found it, we keep it in memory (so, even though
    # we removed the entry, it'll still be accessible).
    language_server_tcp.settings({"settings": {"robot": {"pythonpath": []}}})

    data_regression.check(request_completion())