Directive

CodeLinks provides src-trace directive and it can be used in the following ways:

.. src-trace:: example_with_file
   :project: project_config
   :file: example.cpp

or

.. src-trace:: example_with_directory
   :project: project_config
   :directory: ./example

src-trace directive has the following options:

  • project: the project config specified in conf.py or toml file to be used for source tracing.

  • file: the source file to be traced.

  • directory: the source files in the directory to be traced recursively.

Regarding the file and directory options:

  • they are optional and mutually exclusive.

  • the given paths are relative to src_dir defined in the source tracing configuration

  • if not given, the whole project will be examined.

Example

With the following configuration for a demo source code project dcdc,

conf.py
src_trace_config_from_toml = "src_trace.toml"
src_trace.toml
[src_trace]
# Configuration for source tracing
set_local_url = true            # Set to true to enable local code html and URL generation
local_url_field = "local-url"   # Need's field name for local URL
set_remote_url = true           # Set to true to enable remote url to be generated
remote_url_field = "remote-url" # Need's field name for remote URL

[src_trace.projects.dcdc]
# Configuration for source tracing project "dcdc"
src_dir = "../tests/data/dcdc"                                                                    # Relative path from conf.py to the source directory
remote_url_pattern = "https://github.com/useblocks/sphinx-codelinks/blob/{commit}/{path}#L{line}" # URL pattern for remote source code

[src_trace.projects.dcdc.oneline_comment_style]
# Configuration for oneline comment style
start_sequence = "[["  # Start sequence for oneline comments
end_sequence = "]]"    # End sequence for the online comments; default is newline character
field_split_char = "," # Character to split fields in the comment
# Fields that are defined in the oneline comment style
needs_fields = [
  { "name" = "id", "type" = "str" },
  { "name" = "title", "type" = "str" },
  { "name" = "type", "type" = "str", "default" = "impl" },
  { "name" = "links", "type" = "list[str]", "default" = [
  ] },
]

src-trace directive can be used with file option:

.. src-trace:: dcdc demo_1
   :project: dcdc
   :file: ./charge/demo_1.cpp

The needs defined in source code are extracted and rendered to:

Src-Trace: dcdc demo_1 ST_EE933
project: dcdc
Implementation: processAssemble function IMPL_processAssemble
Implementation: main function IMPL_main_demo1

src-trace directive can be used with directory option:

.. src-trace:: dcdc charge
   :project: dcdc
   :directory: ./discharge

The needs defined in source code are extracted and rendered to:

Src-Trace: dcdc charge ST_71972
project: dcdc
Implementation: displayUI() func, so that it displays UI IMPL_displayUI
Implementation: back up data IMPL_backupData
Implementation: main func in demo_3.cpp IMPL_main_demo_3

Note

local-url is not working on the website as it only supports local browse

To have a more customized configuration of CodeLinks, please refer to configuration.