initial commit for yaml support#7
Conversation
|
Also, it might be necessary to add yaml to treesitter: |
phelipetls
left a comment
There was a problem hiding this comment.
Just tested this against the YAMl document at https://learnxinyminutes.com/docs/yaml/ and I think it works well enough.
It just doesn't work for:
- sets (not sure how to get a value out of a set with
yqeither). - complex keys (probably a wontfix due to complexity).
But I think it'd be nice if it'd work for JSON inside YAML.
| if node:type() == "block_mapping_pair" then | ||
| local key_node = unpack(node:field("key")) | ||
| local key = get_node_text(key_node) | ||
|
|
||
| if key and starts_with_number(key) or contains_special_characters(key) then |
There was a problem hiding this comment.
Currently, this doesn't handle JSON inside YAML.
For instance, with my cursor on
json_map: { |"key": "value" }It returns json_map. I'd expect it to return json_map.key.
I could make it work by changing also handle the node type flow_pair
| if node:type() == "block_mapping_pair" then | |
| local key_node = unpack(node:field("key")) | |
| local key = get_node_text(key_node) | |
| if key and starts_with_number(key) or contains_special_characters(key) then | |
| if node:type() == "block_mapping_pair" or node:type() == "flow_pair" then | |
| local key_node = unpack(node:field("key")) | |
| local key = get_node_text(key_node) | |
| if key and starts_with_number(key) or contains_special_characters(key) then |
But then the result would be also unexpected, json_map[""key""] instead of json_map.key. So we should handle the node double_scalar_key separately.
The node string_scalar seems to work fine, for instance in this line:
and quotes are optional: { |key: [ 3, 2, 1, takeoff ] }| end | ||
| end | ||
|
|
||
| if node:type() == "block_sequence" then |
There was a problem hiding this comment.
It could improve this here by also handling the nodes of type flow_sequence. I didn't find something unexpected with the following change:
| if node:type() == "block_sequence" then | |
| if node:type() == "block_sequence" or node:type() == "flow_sequence" then |
For instance, in this line:
json_seq: [ 3, 2, 1, "takeoff" ]|
If this gets too complicated I opened a PR for similar functionality to enable winbar to I don't know how good yaml.nvim is when it comes to parsing, but it seems to work for my use case. |
|
Thanks @joshzcold, that's a good recommendation. YAML is much more complicated and I think the current implementation is hacky enough for JSON, so I'm not 100% comfortable extending support to YAML. |
First attempt at YAML support.
Choice of yaml or json parsing is made based on filetype which can be explicitly set, if needed:
:set filetype=yamlRelated: #1