ivarptr / yu-writer.site

A feature-rich, efficient text editor - Web Site
Apache License 2.0
1.2k stars 77 forks source link

编辑长代码段时,容易假死。 #410

Closed vae-0118 closed 5 years ago

vae-0118 commented 5 years ago

Platform/操作系统类型 macOS

OS version/操作系统版本 10.14.1

Application version/应用程序的版本号 0.5.3

Describe the bug/错误描述 每次编辑较长的代码引用段的时候便会假死一段时间 cpu 100%。 及编辑 代码 中的内容时。

我的源文件如下

title: 利用Sphinx创建Python文档 date: 2018-11-06 comments: true categories:

基础资料

我将用如下代码生成文档 run.py

class run():
    '''
    用于测试的类
    '''
    def start(self):
        '''
        无参数 打印Hello Word
        :return:
        '''
        print("Hello Word")

    def vae(self, info:str):
      """
      有参数 打印参数内容
      :param info:
      :return:
      """
      print(info)

stop.py

class stop():
    '''
    用于测试的类
    '''
    def end(self):
        '''
        无参数 打印Hello Word
        :return:
        '''
        print("Hello Word")

    def vae(self, info:str):
      """
      有参数 打印参数内容
      :param info:
      :return:
      """
      print(info)

生成后的效果如图所示

安装

当前目录为demo,包含run.pystop.py两个文件。

➜  Demo tree -L 2 ./
./
├── run.py
├── stop.py

创建虚拟环境并进入

➜  Demo virtualenv venv
➜  Demo source venv/bin/activate

安装 Sphinx

(venv) ➜  Demo pip install sphinx

使用

Sphinx提供默认的快速配置方案,通过命令行交互即可完成全部的配置 我的配置方案如下

(venv) ➜  Demo sphinx-quickstart
Welcome to the Sphinx 1.8.1 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Selected root path: .

You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: y

Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]:

The project name will occur in several places in the built documentation.
> Project name: Demo
> Author name(s): vae
> Project release []: 1.0.0

If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.

For a list of supported codes, see
http://sphinx-doc.org/config.html#confval-language.
> Project language [en]: zh_cn

The file name suffix for source files. Commonly, this is either ".txt"
or ".rst".  Only files with this suffix are considered documents.
> Source file suffix [.rst]:

One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]:
Indicate which of the following Sphinx extensions should be enabled:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: y
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: y
> coverage: checks for documentation coverage (y/n) [n]: y
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]: y
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: y
> viewcode: include links to the source code of documented Python objects (y/n) [n]: y
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: y
Note: imgmath and mathjax cannot be enabled at the same time. imgmath has been deselected.

A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (y/n) [y]:
> Create Windows command file? (y/n) [y]: n

Creating file ./source/conf.py.
Creating file ./source/index.rst.
Creating file ./Makefile.

Finished: An initial directory structure has been created.

You should now populate your master file ./source/index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
   make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.

配置完后,会形成如下目录结构

venv) ➜  Demo tree -L 2
.
├── Makefile
├── build
├── run.py
├── source
│   ├── _static
│   ├── _templates
│   ├── conf.py
│   └── index.rst
├── stop.py
└── venv
    ├── bin
    ├── include
    ├── lib
    └── pip-selfcheck.json

8 directories, 6 files

修改source/conf.py,增加如下内容(或者修改该文件的 15~17行)

import os
import sys
sys.path.insert(0, os.path.abspath('../'))

该配置规定了源文件的路径,我的Sphinx配置在所有源文件的第二层,所以源文件的路径是../

执行生成api文档的操作

(venv) ➜  Demo sphinx-apidoc -o source ./
File source/run.rst already exists, skipping.
File source/stop.rst already exists, skipping.
File source/modules.rst already exists, skipping.

其中-o参数为输出的文档配置的路径,这个需要和Sphinx的配置文件路径路径保持一致;最后一个参数为源文件的根目录。

执行make html生成文档

(venv) ➜  Demo make html 
正在运行的是 Sphinx v1.8.1
正在加载翻译 [zh_cn]... 完成
创建输出目录…
loading intersphinx inventory from https://docs.python.org/objects.inv...
intersphinx inventory has moved: https://docs.python.org/objects.inv -> https://docs.python.org/3/objects.inv
构建 [mo]:0 个 po 文件的目标文件已过期
构建 [html]: 4 个源文件的目标文件已过期
updating environment: 4 added, 0 changed, 0 removed
reading sources... [100%] stop
查找当前已过期的文件……没有找到
Pickle 序列化环境……完成
检查一致性……/Users/vae/work/build/Python/Demo/source/modules.rst: WARNING: document isn't included in any toctree
完成
准备文档……完成
写入输出……[ 25%] index                                                                                                                                                                               写入输出……[ 50%] modules                                                                                                                                                                             写入输出……[ 75%] run                                                                                                                                                                                 写入输出……[100%] stop
生成索引…… genindex py-modindex
highlighting module code... [100%] stop
写入附加页面…… search
复制静态文件……done
复制额外文件……完成
导出 Chinese (code: zh) 的搜索索引……完成
导出对象清单……完成
build 成功, 1 warning.

HTML 页面保存在 build/html 目录。

通过浏览器打开 build/html/index.html既为我们的文档界面。 默认界面

浏览

默认的文档不是那么美观。我们改用sphinx_rtd_theme主题

(venv) ➜  Demo pip install sphinx_rtd_theme

修改source/conf.py中的html_theme = 'alabaster'html_theme = 'sphinx_rtd_theme'

重新执行make html,生成新的配置文件。 sphinx_rtd_theme皮肤的帮助文档

hemashushu commented 5 years ago

@vae-0118 是的,这是一个已知的问题,因为涉及语法解析的算法问题,所以可能还需要较长一段时间才能解决,具体来说要等到基础功能完成后(即0.7版后)就开始着手改进软件当中的多处效率问题。谢谢反馈!

vae-0118 commented 5 years ago

@ivarptr 非常感谢你能提供如此有用的产品😊