omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.88k stars 98 forks source link

Does OmegaConf keep information about the ordered map of the raw configuration? #1173

Open noklam opened 2 months ago

noklam commented 2 months ago

Pseudocode:

from omegaconf import OmegaConf

conf = OmegaConf.load("xxxx.yml")
conf.lc

>>> line: 10, col: 5

For example, this is supported with yaml https://yaml.readthedocs.io/en/latest/detail/. Obviously it won't work for the Python API. I wonder how could this be supported or could I extend OmegaConf myself. Does OmegaConf preserve the tree during resolution? It would be super useful for me as I am trying to build some sort of LSP IDE feature on top of it so navigation/go to definition would be easier.

I know for DictConfig there is a _parent attribute, is there a way that I can extend the config resolution method so that these metadata can be kept.

odelalleau commented 2 months ago

I think you could extend the DictConfig and ListConfig constructors so that when you create the config in https://github.com/omry/omegaconf/blob/ed9601045f2342f87604a5c5b6029aa4fff4c0da/omegaconf/omegaconf.py#L832 you can pass this information when available, which could then be stored in the metadata (you'd also have to add this to the ContainerMetadata class).