aws-iam-language-server 0.0.19 → 0.0.20

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.19",
3
+ "version": "0.0.20",
4
4
  "type": "module",
5
5
  "bin": "./src/server.js",
6
6
  "publisher": "MichaelBarney",
@@ -1,11 +1,12 @@
1
1
  import { CompletionItemKind, MarkupKind } from 'vscode-languageserver';
2
+ import { splitArn } from "../../lib/iam-policy/arn.js";
2
3
  import { partitions } from "../../lib/iam-policy/partitions.js";
3
4
  import { formatResourceDocumentation } from "../../lib/iam-policy/reference/documentation.js";
4
5
  import { ServiceReference } from "../../lib/iam-policy/reference/services.js";
5
6
  import { expandActionPattern } from "../../lib/iam-policy/wildcard.js";
6
7
  import { partialRange } from "./index.js";
7
8
  export function completeResourceValue(location, context) {
8
- const parts = location.partial.split(':');
9
+ const parts = splitArn(location.partial);
9
10
  const range = partialRange(context.position, location.partial.length);
10
11
  const items = [];
11
12
  const statement = context.handler.getStatementContext(context.uri, context.position);
@@ -127,7 +128,7 @@ export function completeResourceValue(location, context) {
127
128
  const resources = ServiceReference.getResourcesForActions(expandActionPattern(`${service}:*`));
128
129
  for (const resource of resources) {
129
130
  for (const arn of resource.arnFormats) {
130
- const patternParts = arn.split(':');
131
+ const patternParts = splitArn(arn);
131
132
  const patternRegion = patternParts[3];
132
133
  const patternAccount = patternParts[4];
133
134
  if (region.length > 0 !== patternRegion.length > 0)
@@ -5,6 +5,11 @@ export type ArnParts = {
5
5
  account: string;
6
6
  resource: string;
7
7
  };
8
+ /**
9
+ * Split a string on `:` while preserving `${...}` placeholders intact.
10
+ * Colons inside `${...}` (e.g. `${AWS::AccountId}`) are not treated as delimiters.
11
+ */
12
+ export declare function splitArn(arn: string): string[];
8
13
  /**
9
14
  * Parse an ARN string into its structural components.
10
15
  * Returns null if the string is not a valid ARN structure (fewer than 6 colon-separated segments).
@@ -1,10 +1,39 @@
1
+ /**
2
+ * Split a string on `:` while preserving `${...}` placeholders intact.
3
+ * Colons inside `${...}` (e.g. `${AWS::AccountId}`) are not treated as delimiters.
4
+ */
5
+ export function splitArn(arn) {
6
+ const segments = [];
7
+ let current = '';
8
+ let depth = 0;
9
+ for (let i = 0; i < arn.length; i++) {
10
+ if (arn[i] === '$' && arn[i + 1] === '{') {
11
+ depth++;
12
+ current += '${';
13
+ i++;
14
+ }
15
+ else if (depth > 0 && arn[i] === '}') {
16
+ depth--;
17
+ current += '}';
18
+ }
19
+ else if (depth === 0 && arn[i] === ':') {
20
+ segments.push(current);
21
+ current = '';
22
+ }
23
+ else {
24
+ current += arn[i];
25
+ }
26
+ }
27
+ segments.push(current);
28
+ return segments;
29
+ }
1
30
  /**
2
31
  * Parse an ARN string into its structural components.
3
32
  * Returns null if the string is not a valid ARN structure (fewer than 6 colon-separated segments).
4
33
  * Everything after the 5th colon is treated as the resource portion.
5
34
  */
6
35
  export function parseArn(arn) {
7
- const segments = arn.split(':');
36
+ const segments = splitArn(arn);
8
37
  if (segments.length < 6)
9
38
  return null;
10
39
  if (segments[0] !== 'arn')