Skip to content

Commit 47e39f4

Browse files
committed
[autocomplete] More accurate path to node in ASTManager
Fixes: #426 Do not suggest anythin in string nodes
1 parent b2041d6 commit 47e39f4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/scripts/services/ast-manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,22 @@ SwaggerEditor.service('ASTManager', function ASTManager() {
189189
// and end columns we found the node
190190
if (start.line === line && end.line === line &&
191191
start.column <= row && end.column >= row) {
192+
192193
result = path;
193194

195+
return result;
196+
194197
// if this node is a map, loop through and recurse both keys and value
195198
} else if (current.tag === MAP_TAG) {
199+
196200
current.value.forEach(function (keyValuePair) {
197201
recurse(path, keyValuePair[0]); // key
198202
recurse(path.concat(keyValuePair[0].value), keyValuePair[1]); // value
199203
});
200204

201205
// if this node is a sequence, loop through values and recurse
202206
} else if (current.tag === SEQ_TAG) {
207+
203208
current.value.forEach(function (value, index) {
204209
recurse(path.concat(index), value);
205210
});

app/scripts/services/autocomplete.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ SwaggerEditor.service('Autocomplete', function ($rootScope, snippets,
6060
* in the YAML document
6161
*/
6262
function getPathForPosition(pos) {
63-
// pos.column is 1 more because the character is already inserted
64-
var path = ASTManager.pathForPosition(pos.row, pos.column - 1);
63+
64+
// we are subtracting 2 from row.column because:
65+
// 1. the position object is 1 base index, but ASTManager works with 0 base
66+
// indexes
67+
// 2. the already inserted character should not be counted for getting the
68+
// position. We want the path up to node that we're editing, not the the
69+
// node we're adding (if any)
70+
var path = ASTManager.pathForPosition(pos.row, pos.column - 2);
6571

6672
return path;
6773
}

0 commit comments

Comments
 (0)