split IDE docs into separate file; recommend VS Code

This commit is contained in:
Damien Elmes 2022-01-24 19:46:09 +10:00
parent 369223ce8b
commit 78ac1fe3cc
2 changed files with 58 additions and 36 deletions

View file

@ -194,43 +194,9 @@ build --disk_cache=~/.cache/bazel/disk
It will grow with each changed build, and needs to be manually removed It will grow with each changed build, and needs to be manually removed
when you wish to free up space. when you wish to free up space.
## Python editing ## IDEs
PyCharm or IntelliJ IDEA seems to give the best Python editing experience. Make sure Please see [this separate page](./editing.md) for setting up an editor/IDE.
you build/run Anki first, as code completion depends on the build process to generate
a bunch of files.
After telling PyCharm to create a new virtual environment for your project, locate
pip in the virtual environment, and run `pip install -r pip/requirements.txt` to install
all of Anki's dependencies into the environment, so that code completion works for them.
Then run `pip install pyqt6 pyqt6-webengine` to install PyQt.
Visual Studio Code + the Python extension does support code completion, but Pylance
doesn't do a great job understanding the type annotations.
## Rust editing
Currently Visual Studio Code + Rust Analyzer seems to be the best option out
there. Once Rust Analyzer is installed, you'll want to enable the options to
expand proc macros and build scripts, and run cargo check on startup. Adding
`+nightly` as an extra arg to rustfmt will get you nicer automatic formatting
of `use` statements.
The Bazel build products will make RA start up slowly out of the box. For a much
nicer experience, add each of the `bazel-*` folders to Rust Analyzer's excludeDirs
settings, and node_modules. Wildcards don't work unfortunately. Then adjust
VS Code's "watcher exclude", and add `\*\*/bazel-*`.
After running `code .` from the project root, it may take a minute or two to be
ready.
## TypeScript editing
Visual Studio Code seems to give the best experience. Use `code ts` or `code .`
from the project root to start it up.
IntelliJ IDEA works reasonably well, but doesn't seem to do as good a job at offering
useful completions for things like translation strings.
## Audio ## Audio

56
docs/editing.md Normal file
View file

@ -0,0 +1,56 @@
# Editing/IDEs
Visual Studio Code is recommended, since it provides decent support for all the languages
Anki uses. If you open the root of this repo in VS Code, it will suggest some extensions
for you to install.
For editing Python, PyCharm/IntelliJ's type checking/completion is a bit nicer than
VS Code, but VS Code has improved considerably in a short span of time.
There are a few steps you'll want to take before you start using an IDE.
## Initial Setup
### Python Environment
For code completion of external Python modules, you'll need to create a Python
venv and install Anki's dependencies into it. For example:
```
$ python3.9 -m venv ~/pyenv
$ ~/pyenv/bin/pip install -r python/requirements.txt
$ ~/pyenv/bin/pip install pyqt6 pyqt6-webengine
```
After doing so, you can set your editor's Python path to ~/pyenv/bin/python, eg
in VS Code, ctrl/cmd+shift+p, then 'python: select interpreter'.
### Rust
If you're planning to edit Rust code, install [Rustup](https://rustup.rs/), then
run 'rustup install nightly'.
### Build First
Code completion partly depends on files that are generated as part of the
regular build process, so for things to work correctly, use './run' or
'scripts/build' prior to using code completion.
## PyCharm/IntelliJ
If you decide to use PyCharm instead of VS Code, there are somethings to be aware of.
### Slowdowns
The build process links a large file tree into .bazel in the repo dir. JetBrains
products will try to monitor this folder for changes, and index the files inside
it, which will lead to bad performance. Excluding the folder in the project
settings is [not sufficient unfortunately](https://youtrack.jetbrains.com/issue/IDEA-73309).
A workaround is to add .bazel and node_modules to the IDE-global ignores:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000721750-Excluding-directories-globally
### Pylib References
You'll need to use File>Project Structure to tell IntelliJ that pylib/ is a sources root, so it knows
references to 'anki' in aqt are valid.