Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with breathe, various improvements, regexes, external linking #8

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
47e6549
Adapt parse_type_signature to work for inheriting classes
rogerbarton Jun 22, 2020
bc0187b
remove msdn value type links
rogerbarton Jun 22, 2020
7ef5545
change regex
rogerbarton Jun 22, 2020
8f07384
- specify setup app type
rogerbarton Jul 1, 2020
9e7edbf
fix deprecated warn API, use logger from sphinx.util
rogerbarton Jul 1, 2020
3f71401
add struct
rogerbarton Jul 1, 2020
9cd500b
fix setup sphinx extension properly
rogerbarton Jul 1, 2020
ac522b1
soft errors when parsing regex, use logger.warning instead
rogerbarton Jul 2, 2020
f3a3624
return inherited_types when parsing
rogerbarton Jul 2, 2020
2e8e219
rename domain to 'cs' from 'csharp'
rogerbarton Jul 2, 2020
6010048
try out different roles, directives and object_types
rogerbarton Jul 2, 2020
e4e85ff
Add CSharpVariable and regex
rogerbarton Jul 2, 2020
6d3b366
Fix CSharpProperty with breathe/doxygen, fallback to parsing as variable
rogerbarton Jul 2, 2020
a7efc4f
improved regex for type, var, class, named capture groups
rogerbarton Jul 2, 2020
c5302ca
Search for xref by closest str, refactor external links
rogerbarton Jul 2, 2020
e12bef2
log warning if xref is not found/resolved
rogerbarton Jul 2, 2020
4398e31
fix strange ? on types
rogerbarton Jul 2, 2020
e099de2
add more external types
rogerbarton Jul 2, 2020
3b9548a
Improve xref resolution, also works if in other namespaces
rogerbarton Jul 2, 2020
4ce0a87
Add CSharpInterface, class struct showing nicely, inheritors linked
rogerbarton Jul 3, 2020
ec57669
inhertis and generic rendering working, with xref
rogerbarton Jul 3, 2020
095605e
nolink on generics in class definition, type hints
rogerbarton Jul 3, 2020
188f656
c# events basic support
rogerbarton Jul 3, 2020
6fc933f
refactor domain dicts, object_types etc
rogerbarton Jul 3, 2020
e7075df
fix events, show default values for var/event
rogerbarton Jul 3, 2020
2bd727f
improve function regex, return type can be generic
rogerbarton Jul 3, 2020
caf64fd
add nbsp to single spaces
rogerbarton Jul 3, 2020
bbca189
Fix constructor functions, pointer/references
rogerbarton Jul 3, 2020
cfbe4bf
use sphinx nodes to display modifiers and types, helps with spacing
rogerbarton Jul 3, 2020
eca87eb
Improved external links, easy data fill in, checks if link is exists,…
rogerbarton Jul 3, 2020
63b1707
fix some enumerator test cases
rogerbarton Jul 3, 2020
3885c5e
improve param parsing, fix tests, remove value and method directive, …
rogerbarton Jul 3, 2020
0a3fa65
Fix xref false positives with endswith
rogerbarton Jul 4, 2020
815fd90
more extlinks
rogerbarton Jul 4, 2020
8c14a69
[1] move external linking to domain, cache known links
rogerbarton Jul 4, 2020
14fdafd
[2] Add external links to config, merge with defaults
rogerbarton Jul 4, 2020
389f01c
Add debug variables for more printing if desired
rogerbarton Jul 4, 2020
37ac3d9
move debug options to debug.py and CSDebug class
rogerbarton Jul 4, 2020
f8bde9f
- fix interface
rogerbarton Jul 4, 2020
e0abbe4
Add modifiers for class/struct/interface and render
rogerbarton Jul 4, 2020
1f5a579
- fix modifier spacing
rogerbarton Jul 4, 2020
d227763
fix variable regex, name stops before '='
rogerbarton Jul 4, 2020
f4ea8e9
add function generic parameters (without where : ...)
rogerbarton Jul 4, 2020
6a2525c
pass ignored types to append_type/generics
rogerbarton Jul 4, 2020
fb38af5
Add some more testcases
rogerbarton Jul 4, 2020
32bbbe8
- debug printing
rogerbarton Jul 4, 2020
297a0c8
add plain namespace object for breathe
rogerbarton Jul 4, 2020
d8bab26
-
rogerbarton Jul 4, 2020
3177c7c
-
rogerbarton Jul 4, 2020
e81b0b7
cleanup
rogerbarton Jul 4, 2020
cd7d416
inherits, generic params fixes
rogerbarton Jul 4, 2020
f6f9e40
Refactor: move external links stuff to new files, separate data file,…
rogerbarton Jul 5, 2020
eebb929
lint
rogerbarton Jul 5, 2020
59cff3c
bugfix logger
rogerbarton Jul 5, 2020
677c813
Improve tooltips/fullname for code links
rogerbarton Aug 12, 2020
8676877
Remove uncommon external types
rogerbarton Aug 12, 2020
267797b
More robust resolve_xref
rogerbarton Aug 13, 2020
c634108
- fix link name
rogerbarton Aug 13, 2020
0f9a4b7
ref for referencing any object type
rogerbarton Aug 13, 2020
f095653
Update README.md
rogerbarton Jan 13, 2021
5478436
Add inline keyword
rogerbarton Mar 27, 2021
8978b50
bump version
rogerbarton Mar 27, 2021
072f2bf
Support default value for property (#1)
xuhongxu96 Mar 27, 2021
3ee5427
Add test for breathe integration, add test build scripts
rogerbarton Mar 27, 2021
89b82d9
use re.compile for all regexes, optimize imports
rogerbarton Mar 27, 2021
868fd86
rst file:line for failed regexes, handle parsing when sig is None
rogerbarton Mar 27, 2021
813b76e
correct use of sphinx logger for printing location info
rogerbarton Mar 27, 2021
9394643
breathe test fixes
rogerbarton Mar 27, 2021
2ac3ba6
bump version
rogerbarton Mar 27, 2021
451b50a
small fix
rogerbarton Mar 27, 2021
e408a24
Merge pull request #3 from rogerbarton/dev
rogerbarton Mar 27, 2021
c83fdbf
Fix wrong index for modifier of property
xuhongxu96 Apr 1, 2021
7b4dce0
Revert "Add inline keyword"
rogerbarton Mar 27, 2021
edaefa9
Merge pull request #4 from xuhongxu96/hox/fix-prop-modifier
rogerbarton Apr 19, 2021
5d06cdc
Rework roles and roles to objtypes
rogerbarton Sep 3, 2021
eacf758
small changes to tests
rogerbarton Sep 3, 2021
6f201c1
Fix regex for nullable types
rogerbarton Feb 15, 2022
3f779a4
Fix regex for nullable types
rogerbarton Feb 15, 2022
3bedac5
- edit nullable test
rogerbarton Feb 15, 2022
0649b66
Update readme a bit
rogerbarton Feb 15, 2022
7948eab
Merge branch 'dev'
rogerbarton Feb 15, 2022
6ab864f
- readme
rogerbarton Feb 15, 2022
aecd58e
Fix regex for multi-dimensional arrays
OragonEfreet Apr 28, 2022
820d9bd
Merge pull request #9 from OragonEfreet/multidim-array-type
rogerbarton Apr 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
build
_build/
dist
test-output
*.egg-info
_doxygen/
__pycache__/
/venv/
103 changes: 93 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,106 @@
sphinx-csharp [![Build Status](https://travis-ci.org/djungelorm/sphinx-csharp.svg?branch=master)](https://travis-ci.org/djungelorm/sphinx-csharp)
=============
# sphinx-csharp

C# domain for Sphinx.
C# Domain for Sphinx with Breathe integration. Used to create ReadTheDocs style C# documentation.

Note: Work-in-progress. Only a subset of C# is currently supported.
See [vr-modeling example](https://vr-modeling.readthedocs.io/Assets/Scripts/Libigl/index.html) end-product.

Usage
-----
**Idea:**
1. Generate Doxygen xml
1. Convert this to Sphinx using breathe + sphinx-csharp
1. Apply ReadTheDocs theme
1. Write rst using the `cs` domain

## Usage

Install using pip:

```
pip install sphinx-csharp
pip install git+https://github.com/rogerbarton/sphinx-csharp.git
```

To enable the extension, add the following to your conf.py:

```python
extensions = ['sphinx_csharp.csharp']
```py
extensions = ['sphinx_csharp']
```

See [this example](https://raw.githubusercontent.com/djungelorm/sphinx-csharp/master/test/index.rst) of how to document C# code.
See https://github.com/djungelorm/sphinx-csharp/pull/8 for usage/changes from upstream and also [this rst example](https://raw.githubusercontent.com/rogerbarton/sphinx-csharp/master/test/index.rst).

### `conf.py` Options
Various options can be set in the sphinx `conf.py`. See [`__init__.py:setup()`](https://github.com/rogerbarton/sphinx-csharp/blob/master/sphinx_csharp/__init__.py) for available options. Defaults for external references are indicated or in [`extrefs_data.py`](https://github.com/rogerbarton/sphinx-csharp/blob/master/sphinx_csharp/extrefs_data.py).
See also [`csharp.py:apply_config(cls, config: Config)`](https://github.com/rogerbarton/sphinx-csharp/blob/master/sphinx_csharp/csharp.py) for exact defaults.

Here are the default values for all available options:

```py
# Are other languages used in the sphinx project, if yes add language (domain) prefix to reference labels
sphinx_csharp_multi_language = False

# Should generated external links be tested for validity
sphinx_csharp_test_links = False

# Remove these common prefixes from labels
sphinx_csharp_shorten_type_prefixes = [
'System.',
'System.IO',
...
]

# Do not create cross references for these standard/build-in types
sphinx_csharp_ignore_xref = [
'string',
'Vector2',
...
]

# How to generate external doc links, replace %s with type. Use the format
# 'package name': ('direct link to %s', 'alternate backup link or search page')
sphinx_csharp_ext_search_pages = {
'upm.xrit': ('https://docs.unity3d.com/Packages/[email protected]/api/%s.html',
'https://docs.unity3d.com/Packages/[email protected]/?%s'),
...
}

# Types that are in an external package. Use the format
# 'package name': {
# 'Namespace1': ['Type1', 'Type2'],
sphinx_csharp_ext_type_map = {
'unity': {
'': ['MonoBehaviour', 'ScriptableObject'],
'XR': ['InputDevice', 'InputDeviceCharacteristics'],
...
},
...
}

# [Advanced] Rename type before generating external link. Commonly used for generic types
sphinx_csharp_external_type_rename = {
'List': 'List-1',
'NativeArray': 'NativeArray_1',
...
}

# Debug options, these enable various verbose logging features.
sphinx_csharp_debug = False # enables all debug options
sphinx_csharp_debug_parse = False # enables all parsing options
sphinx_csharp_debug_parse_func = False
sphinx_csharp_debug_parse_var = False
sphinx_csharp_debug_parse_prop = False
sphinx_csharp_debug_parse_attr = False
sphinx_csharp_debug_parse_idxr = False
sphinx_csharp_debug_parse_type = False
sphinx_csharp_debug_xref = False
sphinx_csharp_debug_ext_links = False
```

See also [this example](https://github.com/rogerbarton/vr-modeling/blob/69885cd454935e3c5b54ef5a6b9a94da73575b20/conf.py).

### Examples and Tests

See build scripts in `test`. This is quite incomplete at the moment. The [vr-modeling example](https://vr-modeling.readthedocs.io/Assets/Scripts/Libigl/index.html) will likely be most useful as a reference.


## Common Bug Sources
- Newer C# syntax that is not supported yet, see regexes at beginning of `csharp.py` for parsing
- Incorrect xml reconstruction in breathe, see `def visit_*` in breathe `render/sphinxrenderer.py`
- e.g. `visit_variable` will create the signature that is given to `csharp.py`
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name = 'sphinx-csharp',
version = '0.1.8',
version = '0.1.12',
author = 'djungelorm',
author_email = '[email protected]',
packages = ['sphinx_csharp'],
Expand Down
21 changes: 21 additions & 0 deletions sphinx_csharp/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
from .csharp import CSharpDomain
from .debug import CSDebug
from sphinx.application import Sphinx


def setup(app: Sphinx) -> None:
""" Setup called by sphinx when the module is added to the extensions list in conf.py """

# Register domain
app.add_domain(CSharpDomain)
app.connect('config-inited', CSharpDomain.apply_config)

# Add variables available in conf.py
app.add_config_value('sphinx_csharp_test_links', False, 'env')
app.add_config_value('sphinx_csharp_multi_language', False, 'env')
app.add_config_value('sphinx_csharp_shorten_type_prefixes', None, 'env')
app.add_config_value('sphinx_csharp_ignore_xref', None, 'env')
app.add_config_value('sphinx_csharp_ext_type_map', None, 'env')
app.add_config_value('sphinx_csharp_external_type_rename', None, 'env')
app.add_config_value('sphinx_csharp_ext_search_pages', None, 'env')

CSDebug.add_config_values(app)
Loading