Esempio n. 1
0
 def parse_closed_files(self, paths):
     # TODO send progress to client (will require next LSP version 3.15.0)
     passed = 0
     for path in paths:
         try:
             with open(path) as handle:
                 source = handle.read()
             # TODO check doc not in database with same mtime
             result = assess_source(source, self.app_env, doc_uri=path)
             self._db.update_doc(
                 uri=uris.from_fs_path(path),
                 # TODO use os.path.getmtime(path)?
                 mtime=datetime.datetime.utcnow(),
                 doc_symbols=result.doc_symbols,
                 positions=result.positions,
                 targets=result.targets,
                 references=result.references,
                 lints=result.linting,
             )
             self.server.log_message(
                 f"file parsed: {uris.from_fs_path(path)}")
             passed += 1
         except Exception as err:
             self.server.log_message(f"file parse failed: {path}: {err}",
                                     MessageType.Error)
     # TODO now remove removed roles/directives from database
     return passed
Esempio n. 2
0
 def get_assessment(self) -> SourceAssessResult:
     if self._assessment is None:
         # TODO partial reassessment of source, given applied changes
         self._assessment = assess_source(self.source,
                                          self.workspace.app_env,
                                          doc_uri=self.uri)
         # TODO if local, use os.path.getmtime?
         self._mtime = datetime.datetime.utcnow()
     return self._assessment
def test_section_levels(get_test_file_content, data_regression):
    content = get_test_file_content("test_sections.rst")
    app_env = create_sphinx_app()
    results = assess_source(content, app_env)
    data_regression.check(
        {
            "positions": results.positions,
            "references": results.references,
            "targets": results.targets,
            "linting": results.linting,
        }
    )
def test_basic_database(get_test_file_content, data_regression):
    content = get_test_file_content("test_basic.rst")
    app_env = create_sphinx_app(confoverrides={"extensions": ["sphinxcontrib.bibtex"]})
    results = assess_source(content, app_env)
    data_regression.check(
        {
            "positions": results.positions,
            "references": results.references,
            "targets": results.targets,
            "linting": results.linting,
        }
    )
def test_sphinx_elements(file_regression, data_regression):
    from textwrap import dedent

    source = dedent(
        """\
        .. _title:

        Title
        -----

        :ref:`title`
        :ref:`fig1`
        :ref:`tbl1`
        :eq:`eq1`
        :numref:`code1`
        :cite:`citation`
        :unknown:`abc`

        .. versionadded:: 1.0

            A note about |RST|

        .. figure:: abc.png
           :name: fig1

        .. table:: Truth table for "not"
            :widths: auto
            :name: tbl1

            =====  =====
            A      not A
            =====  =====
            False  True
            True   False
            =====  =====

        .. math::
            :nowrap:
            :label: eq1

            \\begin{eqnarray}
                y    & = & ax^2 + bx + c \\\\
                f(x) & = & x^2 + 2xy + y^2
            \\end{eqnarray}

        .. code-block:: python::
            :name: code1

            pass

        .. |RST| replace:: ReStructuredText
        """
    )
    app_env = create_sphinx_app(confoverrides={"extensions": ["sphinxcontrib.bibtex"]})
    results = assess_source(source, app_env)
    file_regression.check(results.doctree.pformat())
    data_regression.check(
        {
            "lints": results.linting,
            "positions": results.positions,
            "references": results.references,
            "pending_xrefs": results.pending_xrefs,
            "targets": results.targets,
        }
    )
def test_basic_linting(get_test_file_content, data_regression):
    content = get_test_file_content("test_basic.rst")
    app_env = create_sphinx_app(confoverrides={"extensions": ["sphinxcontrib.bibtex"]})
    results = assess_source(content, app_env)
    # TODO inline errors from docutils refers to wrong line, if after line break
    data_regression.check(results.linting)
def test_basic_doctree(get_test_file_content, file_regression):
    content = get_test_file_content("test_basic.rst")
    app_env = create_sphinx_app(confoverrides={"extensions": ["sphinxcontrib.bibtex"]})
    results = assess_source(content, app_env)
    file_regression.check(results.doctree.pformat())