aws-iam-language-server 0.0.29 → 0.0.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-iam-language-server",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "bin": "./src/server.js",
6
6
  "publisher": "MichaelBarney",
@@ -13,10 +13,14 @@ export function completeResourceValue(location, context) {
13
13
  const statementActions = statement?.Action ?? statement?.NotAction ?? [];
14
14
  const expandedActions = statementActions.flatMap(expandActionPattern);
15
15
  const resources = ServiceReference.getResourcesForActions(expandedActions);
16
+ const seenArns = new Set();
16
17
  for (const resource of resources) {
17
18
  for (const arn of resource.arnFormats) {
18
19
  if (location.partial && !arn.toLowerCase().startsWith(location.partial.toLowerCase()))
19
20
  continue;
21
+ if (seenArns.has(arn))
22
+ continue;
23
+ seenArns.add(arn);
20
24
  items.push({
21
25
  label: arn,
22
26
  sortText: `0-${arn}`,
@@ -126,6 +130,7 @@ export function completeResourceValue(location, context) {
126
130
  const region = parts[3];
127
131
  const account = parts[4];
128
132
  const resources = ServiceReference.getResourcesForActions(expandActionPattern(`${service}:*`));
133
+ const seenLabels = new Set();
129
134
  for (const resource of resources) {
130
135
  for (const arn of resource.arnFormats) {
131
136
  const patternParts = splitArn(arn);
@@ -141,6 +146,9 @@ export function completeResourceValue(location, context) {
141
146
  .replace(`\${Account}`, parts[4]);
142
147
  if (location.partial && !label.toLowerCase().startsWith(location.partial.toLowerCase()))
143
148
  continue;
149
+ if (seenLabels.has(label))
150
+ continue;
151
+ seenLabels.add(label);
144
152
  items.push({
145
153
  label,
146
154
  kind: CompletionItemKind.Enum,
@@ -141,10 +141,13 @@ export class TreeYaml extends TreeBase {
141
141
  }
142
142
  return entries;
143
143
  }
144
+ #getPairValueNode(pair) {
145
+ return pair.namedChildren.find((child, i) => i > 0 && child.type !== 'comment') ?? null;
146
+ }
144
147
  #readPairStatementValues(pair) {
145
- if (pair.namedChildren.length < 2)
148
+ const valueNode = this.#getPairValueNode(pair);
149
+ if (!valueNode)
146
150
  return [];
147
- const valueNode = pair.namedChildren[1];
148
151
  // Direct flow_node scalar
149
152
  if (valueNode.type === 'flow_node') {
150
153
  return this.#flowNodeToStatementValue(valueNode);
@@ -188,14 +191,15 @@ export class TreeYaml extends TreeBase {
188
191
  return [{ text, range: nodeRange(flowNode) }];
189
192
  }
190
193
  #getPairValueRange(pair) {
191
- if (pair.namedChildren.length < 2) {
194
+ const valueNode = this.#getPairValueNode(pair);
195
+ if (!valueNode) {
192
196
  // No value — zero-width range at key end
193
197
  return {
194
198
  start: { line: pair.endPosition.row, character: pair.endPosition.column },
195
199
  end: { line: pair.endPosition.row, character: pair.endPosition.column },
196
200
  };
197
201
  }
198
- return nodeRange(pair.namedChildren[1]);
202
+ return nodeRange(valueNode);
199
203
  }
200
204
  /**
201
205
  * Traverse the tree from root, collecting every block_mapping that sits inside
@@ -608,9 +612,9 @@ export class TreeYaml extends TreeBase {
608
612
  * Find a block_mapping in a pair's value, unwrapping block_node if present.
609
613
  */
610
614
  #findValueBlockMapping(pair) {
611
- if (pair.namedChildren.length < 2)
615
+ let value = this.#getPairValueNode(pair);
616
+ if (!value)
612
617
  return null;
613
- let value = pair.namedChildren[1];
614
618
  if (value.type === 'block_node')
615
619
  value = value.namedChildren[0] ?? null;
616
620
  return value?.type === 'block_mapping' ? value : null;
@@ -619,9 +623,9 @@ export class TreeYaml extends TreeBase {
619
623
  * Find a block_sequence in a pair's value, unwrapping block_node if present.
620
624
  */
621
625
  #findValueBlockSequence(pair) {
622
- if (pair.namedChildren.length < 2)
626
+ let value = this.#getPairValueNode(pair);
627
+ if (!value)
623
628
  return null;
624
- let value = pair.namedChildren[1];
625
629
  if (value.type === 'block_node')
626
630
  value = value.namedChildren[0] ?? null;
627
631
  return value?.type === 'block_sequence' ? value : null;
@@ -984,9 +988,9 @@ export class TreeYaml extends TreeBase {
984
988
  * Read string values from a mapping pair's value (scalar, block sequence, or flow sequence).
985
989
  */
986
990
  #readPairStringValues(pair) {
987
- if (pair.namedChildren.length < 2)
991
+ const valueNode = this.#getPairValueNode(pair);
992
+ if (!valueNode)
988
993
  return [];
989
- const valueNode = pair.namedChildren[1];
990
994
  // Direct flow_node scalar
991
995
  if (valueNode.type === 'flow_node') {
992
996
  const text = this.#getScalarText(valueNode);