vscode-json-languageservice 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 5.3.1 / 2023-02-24
2
+ ================
3
+ * Fixing bugs in the sort feature
4
+
1
5
  5.3.0 / 2023-02-15
2
6
  ================
3
7
  * new API `LanguageService.sort` for sorting all properties in a JSON document
@@ -33,8 +33,12 @@ class FilePatternAssociation {
33
33
  }
34
34
  }
35
35
  ;
36
- if (folderUri && !folderUri.endsWith('/')) {
37
- this.folderUri = folderUri + '/';
36
+ if (folderUri) {
37
+ folderUri = normalizeResourceForMatching(folderUri);
38
+ if (!folderUri.endsWith('/')) {
39
+ folderUri = folderUri + '/';
40
+ }
41
+ this.folderUri = folderUri;
38
42
  }
39
43
  }
40
44
  catch (e) {
@@ -37,19 +37,24 @@ export class PropertyTree {
37
37
  }
38
38
  }
39
39
  function compareProperties(propertyTree1, propertyTree2) {
40
- if (propertyTree1.propertyName < propertyTree2.propertyName) {
40
+ const propertyName1 = propertyTree1.propertyName.toLowerCase();
41
+ const propertyName2 = propertyTree2.propertyName.toLowerCase();
42
+ if (propertyName1 < propertyName2) {
41
43
  return -1;
42
44
  }
43
- else if (propertyTree1.propertyName > propertyTree2.propertyName) {
45
+ else if (propertyName1 > propertyName2) {
44
46
  return 1;
45
47
  }
46
48
  return 0;
47
49
  }
48
50
  function binarySearchOnPropertyArray(propertyTreeArray, propertyTree, compare_fn) {
49
- if (propertyTree.propertyName < propertyTreeArray[0].propertyName) {
51
+ const propertyName = propertyTree.propertyName.toLowerCase();
52
+ const firstPropertyInArrayName = propertyTreeArray[0].propertyName.toLowerCase();
53
+ const lastPropertyInArrayName = propertyTreeArray[propertyTreeArray.length - 1].propertyName.toLowerCase();
54
+ if (propertyName < firstPropertyInArrayName) {
50
55
  return 0;
51
56
  }
52
- if (propertyTree.propertyName > propertyTreeArray[propertyTreeArray.length - 1].propertyName) {
57
+ if (propertyName > lastPropertyInArrayName) {
53
58
  return propertyTreeArray.length;
54
59
  }
55
60
  let m = 0;
@@ -136,6 +136,7 @@ function findJsoncPropertyTree(formattedDocument) {
136
136
  childProperty.noKeyName = true;
137
137
  lastProperty = currentProperty;
138
138
  currentProperty = currentTree.addChildProperty(childProperty);
139
+ currentTree = currentProperty;
139
140
  }
140
141
  currentContainerStack.push(Container.Array);
141
142
  currentProperty.type = Container.Array;
@@ -335,7 +336,13 @@ function updateSortingQueue(queue, propertyTree, beginningLineNumber) {
335
336
  queue.push(new SortingRange(beginningLineNumber, propertyTree.childrenProperties));
336
337
  }
337
338
  else if (propertyTree.type === Container.Array) {
338
- for (const subObject of propertyTree.childrenProperties) {
339
+ updateSortingQueueForArrayProperties(queue, propertyTree, beginningLineNumber);
340
+ }
341
+ }
342
+ function updateSortingQueueForArrayProperties(queue, propertyTree, beginningLineNumber) {
343
+ for (const subObject of propertyTree.childrenProperties) {
344
+ // If the child property of the array is an object, then you can sort the properties within this object
345
+ if (subObject.type === Container.Object) {
339
346
  let minimumBeginningLineNumber = Infinity;
340
347
  for (const childProperty of subObject.childrenProperties) {
341
348
  if (childProperty.beginningLineNumber < minimumBeginningLineNumber) {
@@ -345,6 +352,10 @@ function updateSortingQueue(queue, propertyTree, beginningLineNumber) {
345
352
  const diff = minimumBeginningLineNumber - subObject.beginningLineNumber;
346
353
  queue.push(new SortingRange(beginningLineNumber + subObject.beginningLineNumber - propertyTree.beginningLineNumber + diff, subObject.childrenProperties));
347
354
  }
355
+ // If the child property of the array is an array, then you need to recurse on the children properties, until you find an object to sort
356
+ if (subObject.type === Container.Array) {
357
+ updateSortingQueueForArrayProperties(queue, subObject, beginningLineNumber + subObject.beginningLineNumber - propertyTree.beginningLineNumber);
358
+ }
348
359
  }
349
360
  }
350
361
  class SortingRange {
@@ -45,8 +45,12 @@
45
45
  }
46
46
  }
47
47
  ;
48
- if (folderUri && !folderUri.endsWith('/')) {
49
- this.folderUri = folderUri + '/';
48
+ if (folderUri) {
49
+ folderUri = normalizeResourceForMatching(folderUri);
50
+ if (!folderUri.endsWith('/')) {
51
+ folderUri = folderUri + '/';
52
+ }
53
+ this.folderUri = folderUri;
50
54
  }
51
55
  }
52
56
  catch (e) {
@@ -50,19 +50,24 @@
50
50
  }
51
51
  exports.PropertyTree = PropertyTree;
52
52
  function compareProperties(propertyTree1, propertyTree2) {
53
- if (propertyTree1.propertyName < propertyTree2.propertyName) {
53
+ const propertyName1 = propertyTree1.propertyName.toLowerCase();
54
+ const propertyName2 = propertyTree2.propertyName.toLowerCase();
55
+ if (propertyName1 < propertyName2) {
54
56
  return -1;
55
57
  }
56
- else if (propertyTree1.propertyName > propertyTree2.propertyName) {
58
+ else if (propertyName1 > propertyName2) {
57
59
  return 1;
58
60
  }
59
61
  return 0;
60
62
  }
61
63
  function binarySearchOnPropertyArray(propertyTreeArray, propertyTree, compare_fn) {
62
- if (propertyTree.propertyName < propertyTreeArray[0].propertyName) {
64
+ const propertyName = propertyTree.propertyName.toLowerCase();
65
+ const firstPropertyInArrayName = propertyTreeArray[0].propertyName.toLowerCase();
66
+ const lastPropertyInArrayName = propertyTreeArray[propertyTreeArray.length - 1].propertyName.toLowerCase();
67
+ if (propertyName < firstPropertyInArrayName) {
63
68
  return 0;
64
69
  }
65
- if (propertyTree.propertyName > propertyTreeArray[propertyTreeArray.length - 1].propertyName) {
70
+ if (propertyName > lastPropertyInArrayName) {
66
71
  return propertyTreeArray.length;
67
72
  }
68
73
  let m = 0;
@@ -149,6 +149,7 @@
149
149
  childProperty.noKeyName = true;
150
150
  lastProperty = currentProperty;
151
151
  currentProperty = currentTree.addChildProperty(childProperty);
152
+ currentTree = currentProperty;
152
153
  }
153
154
  currentContainerStack.push(propertyTree_1.Container.Array);
154
155
  currentProperty.type = propertyTree_1.Container.Array;
@@ -348,7 +349,13 @@
348
349
  queue.push(new SortingRange(beginningLineNumber, propertyTree.childrenProperties));
349
350
  }
350
351
  else if (propertyTree.type === propertyTree_1.Container.Array) {
351
- for (const subObject of propertyTree.childrenProperties) {
352
+ updateSortingQueueForArrayProperties(queue, propertyTree, beginningLineNumber);
353
+ }
354
+ }
355
+ function updateSortingQueueForArrayProperties(queue, propertyTree, beginningLineNumber) {
356
+ for (const subObject of propertyTree.childrenProperties) {
357
+ // If the child property of the array is an object, then you can sort the properties within this object
358
+ if (subObject.type === propertyTree_1.Container.Object) {
352
359
  let minimumBeginningLineNumber = Infinity;
353
360
  for (const childProperty of subObject.childrenProperties) {
354
361
  if (childProperty.beginningLineNumber < minimumBeginningLineNumber) {
@@ -358,6 +365,10 @@
358
365
  const diff = minimumBeginningLineNumber - subObject.beginningLineNumber;
359
366
  queue.push(new SortingRange(beginningLineNumber + subObject.beginningLineNumber - propertyTree.beginningLineNumber + diff, subObject.childrenProperties));
360
367
  }
368
+ // If the child property of the array is an array, then you need to recurse on the children properties, until you find an object to sort
369
+ if (subObject.type === propertyTree_1.Container.Array) {
370
+ updateSortingQueueForArrayProperties(queue, subObject, beginningLineNumber + subObject.beginningLineNumber - propertyTree.beginningLineNumber);
371
+ }
361
372
  }
362
373
  }
363
374
  class SortingRange {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",