|
93 | 93 | M.get_node_value = function(node, bufnr) |
94 | 94 | local start_row, start_col, _, end_col = node:range() |
95 | 95 | local line = vim.api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1] |
96 | | - return line and string.sub(line, start_col + 1, end_col):gsub('^["\'](.*)["\']$', '%1') or nil |
| 96 | + return line and string.sub(line, start_col + 1, end_col):gsub("^[\"'](.*)[\"']$", "%1") or nil |
97 | 97 | end |
98 | 98 |
|
99 | 99 | M.read_document_variables = function() |
100 | 100 | local variables = {} |
101 | 101 | local bufnr = vim.api.nvim_get_current_buf() |
102 | 102 | local parser = vim.treesitter.get_parser(bufnr) |
103 | | - if not parser then return variables end |
| 103 | + if not parser then |
| 104 | + return variables |
| 105 | + end |
104 | 106 |
|
105 | 107 | local first_tree = parser:trees()[1] |
106 | | - if not first_tree then return variables end |
| 108 | + if not first_tree then |
| 109 | + return variables |
| 110 | + end |
107 | 111 |
|
108 | 112 | local root = first_tree:root() |
109 | | - if not root then return variables end |
| 113 | + if not root then |
| 114 | + return variables |
| 115 | + end |
110 | 116 |
|
111 | 117 | for node in root:iter_children() do |
112 | 118 | local type = node:type() |
113 | | - if type == 'header' then |
| 119 | + if type == "header" then |
114 | 120 | local name = node:named_child(0) |
115 | 121 | local value = node:named_child(1) |
116 | 122 | variables[M.get_node_value(name, bufnr)] = M.get_node_value(value, bufnr) |
117 | | - elseif type ~= 'comment' then |
| 123 | + elseif type ~= "comment" then |
118 | 124 | break |
119 | 125 | end |
120 | 126 | end |
121 | 127 | return variables |
122 | | - |
123 | 128 | end |
124 | 129 |
|
125 | 130 | M.read_variables = function() |
126 | 131 | local first = M.read_env_file() |
127 | 132 | local second = M.read_dynamic_variables() |
128 | 133 | local third = M.read_document_variables() |
129 | 134 |
|
130 | | - return vim.tbl_extend('force', first, second, third) |
| 135 | + return vim.tbl_extend("force", first, second, third) |
131 | 136 | end |
132 | 137 |
|
133 | 138 | -- replace_vars replaces the env variables fields in the provided string |
|
0 commit comments