@intlayer/lsp 8.11.3 → 8.11.4
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/dist/esm/findFieldInFile.mjs +156 -0
- package/dist/esm/findFieldInFile.mjs.map +1 -0
- package/dist/esm/findKeyAtOffset.mjs +26 -12
- package/dist/esm/findKeyAtOffset.mjs.map +1 -1
- package/dist/esm/findKeyInContentFile.mjs +131 -0
- package/dist/esm/findKeyInContentFile.mjs.map +1 -0
- package/dist/esm/findUsageFieldAtOffset.mjs +72 -0
- package/dist/esm/findUsageFieldAtOffset.mjs.map +1 -0
- package/dist/esm/index.mjs +361 -34
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/oxcUtils.mjs +60 -0
- package/dist/esm/oxcUtils.mjs.map +1 -0
- package/dist/esm/utils.mjs +6 -0
- package/dist/types/findFieldInFile.d.ts +30 -0
- package/dist/types/findFieldInFile.d.ts.map +1 -0
- package/dist/types/findKeyAtOffset.d.ts +11 -3
- package/dist/types/findKeyAtOffset.d.ts.map +1 -1
- package/dist/types/findKeyInContentFile.d.ts +31 -0
- package/dist/types/findKeyInContentFile.d.ts.map +1 -0
- package/dist/types/findUsageFieldAtOffset.d.ts +22 -0
- package/dist/types/findUsageFieldAtOffset.d.ts.map +1 -0
- package/dist/types/oxcUtils.d.ts +24 -0
- package/dist/types/oxcUtils.d.ts.map +1 -0
- package/dist/types/utils.d.ts +5 -0
- package/package.json +11 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Range } from "vscode-languageserver/node.js";
|
|
2
|
+
|
|
3
|
+
//#region src/findFieldInFile.d.ts
|
|
4
|
+
declare const escapeRegularExpression: (content: string) => string;
|
|
5
|
+
declare const offsetToRange: (text: string, start: number, end: number) => Range;
|
|
6
|
+
/**
|
|
7
|
+
* Within a single file's text, find all positions where `fieldPath` (or legacy
|
|
8
|
+
* `fieldName`) is used as a destructured property or member access on a
|
|
9
|
+
* `useIntlayer(key)` / `getIntlayer(key)` result.
|
|
10
|
+
*
|
|
11
|
+
* Covers four patterns:
|
|
12
|
+
* 1. Direct destructure:
|
|
13
|
+
* const { field } = useIntlayer("key")
|
|
14
|
+
* 2. Nested destructure:
|
|
15
|
+
* const { parent: { child } } = useIntlayer("key")
|
|
16
|
+
* 3. Indirect variable + member access:
|
|
17
|
+
* const { parent } = useIntlayer("key")
|
|
18
|
+
* parent.child
|
|
19
|
+
* 4. Full chain member access:
|
|
20
|
+
* const content = useIntlayer("key")
|
|
21
|
+
* content.parent.child
|
|
22
|
+
*
|
|
23
|
+
* `fieldPath` (optional 5th parameter) is the preferred input; when omitted
|
|
24
|
+
* the function derives the single-element path from `escapedField`, preserving
|
|
25
|
+
* backward compatibility.
|
|
26
|
+
*/
|
|
27
|
+
declare const findFieldRangesInFile: (text: string, escapedKey: string, _fieldName: string, escapedField: string, fieldPath?: string[]) => Range[];
|
|
28
|
+
//#endregion
|
|
29
|
+
export { escapeRegularExpression, findFieldRangesInFile, offsetToRange };
|
|
30
|
+
//# sourceMappingURL=findFieldInFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findFieldInFile.d.ts","names":[],"sources":["../../src/findFieldInFile.ts"],"mappings":";;;cASa,uBAAA,GAA2B,OAAA;AAAA,cAG3B,aAAA,GACX,IAAA,UACA,KAAA,UACA,GAAA,aACC,KAAA;AAPH;;;;AAAwC;AAGxC;;;;;;;;;AAIG;AAsKH;;;;;;AA7KA,cA6Ka,qBAAA,GACX,IAAA,UACA,UAAA,UACA,UAAA,UACA,YAAA,UACA,SAAA,gBACC,KAAA"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
//#region src/findKeyAtOffset.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Scan `text` for
|
|
4
|
-
* Returns the dictionary key string, or `null`
|
|
5
|
-
* recognised call.
|
|
3
|
+
* Scan `text` for a useIntlayer / getIntlayer call whose AST span contains
|
|
4
|
+
* `offset`. Returns the dictionary key string, or `null` when the cursor is
|
|
5
|
+
* not inside any recognised call.
|
|
6
|
+
*
|
|
7
|
+
* Handles:
|
|
8
|
+
* useIntlayer("my-key")
|
|
9
|
+
* getIntlayer<Type>("my-key", locale)
|
|
10
|
+
* useIntlayer(
|
|
11
|
+
* "my-key" ← multi-line
|
|
12
|
+
* )
|
|
13
|
+
* useIntlayer(`my-key`)
|
|
6
14
|
*/
|
|
7
15
|
declare const findKeyAtOffset: (text: string, offset: number) => string | null;
|
|
8
16
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findKeyAtOffset.d.ts","names":[],"sources":["../../src/findKeyAtOffset.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"findKeyAtOffset.d.ts","names":[],"sources":["../../src/findKeyAtOffset.ts"],"mappings":";;AAoBA;;;;AAEE;;;;;;;;cAFW,eAAA,GACX,IAAA,UACA,MAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/findKeyInContentFile.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* If `offset` falls within a `key:` declaration in a content file,
|
|
4
|
+
* return the declared key string; otherwise return null.
|
|
5
|
+
* Handles quoted values (TS/JS/JSON) and bare values (YAML/Markdown frontmatter).
|
|
6
|
+
*/
|
|
7
|
+
declare const findKeyInContentFile: (text: string, offset: number) => string | null;
|
|
8
|
+
/**
|
|
9
|
+
* If `offset` falls on a content field property key inside an intlayer content
|
|
10
|
+
* file, return the dictionary key, the leaf field name, and the full field path
|
|
11
|
+
* (array of names from the content root to the clicked field).
|
|
12
|
+
*
|
|
13
|
+
* For example, in:
|
|
14
|
+
* content: { searchInput: { text: t({...}) } }
|
|
15
|
+
*
|
|
16
|
+
* Clicking on `text` returns `{ dictionaryKey, fieldName: 'text', fieldPath: ['searchInput', 'text'] }`.
|
|
17
|
+
* Clicking on `searchInput` returns `{ ..., fieldName: 'searchInput', fieldPath: ['searchInput'] }`.
|
|
18
|
+
*
|
|
19
|
+
* Locale keys inside `t({en:…, fr:…})` calls are correctly skipped.
|
|
20
|
+
*
|
|
21
|
+
* Uses Oxc AST for JS/TS/TSX/JSX files; falls back to a regex heuristic for
|
|
22
|
+
* YAML and Markdown where Oxc cannot parse.
|
|
23
|
+
*/
|
|
24
|
+
declare const findContentFieldAtOffset: (text: string, offset: number) => {
|
|
25
|
+
dictionaryKey: string;
|
|
26
|
+
fieldName: string;
|
|
27
|
+
fieldPath: string[];
|
|
28
|
+
} | null;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { findContentFieldAtOffset, findKeyInContentFile };
|
|
31
|
+
//# sourceMappingURL=findKeyInContentFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findKeyInContentFile.d.ts","names":[],"sources":["../../src/findKeyInContentFile.ts"],"mappings":";;AAYA;;;;cAAa,oBAAA,GACX,IAAA,UACA,MAAA;AA0FF;;;;;;;;;;AAG+C;;;;;;AAH/C,cAAa,wBAAA,GACX,IAAA,UACA,MAAA;EACG,aAAA;EAAuB,SAAA;EAAmB,SAAA;AAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/findUsageFieldAtOffset.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Detect when the cursor is on a field name that was obtained from a
|
|
4
|
+
* useIntlayer / getIntlayer call in the same file. Two patterns:
|
|
5
|
+
*
|
|
6
|
+
* Pattern 1 — destructuring:
|
|
7
|
+
* const { localeSwitcherLabel } = useIntlayer("locale-switcher")
|
|
8
|
+
* ^^^^^^^^^^^^^^^^^^ ← cursor here
|
|
9
|
+
*
|
|
10
|
+
* Pattern 2 — member access:
|
|
11
|
+
* const t = useIntlayer("locale-switcher")
|
|
12
|
+
* t.localeSwitcherLabel ← cursor on the property
|
|
13
|
+
*
|
|
14
|
+
* Returns { dictionaryKey, fieldName } when matched, null otherwise.
|
|
15
|
+
*/
|
|
16
|
+
declare const findUsageFieldAtOffset: (text: string, offset: number) => {
|
|
17
|
+
dictionaryKey: string;
|
|
18
|
+
fieldName: string;
|
|
19
|
+
} | null;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { findUsageFieldAtOffset };
|
|
22
|
+
//# sourceMappingURL=findUsageFieldAtOffset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findUsageFieldAtOffset.d.ts","names":[],"sources":["../../src/findUsageFieldAtOffset.ts"],"mappings":";;AAsBA;;;;;;;;;AAG4B;;;;cAHf,sBAAA,GACX,IAAA,UACA,MAAA;EACG,aAAA;EAAuB,SAAA;AAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/oxcUtils.d.ts
|
|
2
|
+
declare const INTLAYER_GETTERS: Set<string>;
|
|
3
|
+
type OxcNode = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Depth-first walk of an Oxc AST. Visitor is called for every node that has
|
|
6
|
+
* a `type` property;
|
|
7
|
+
* returning `true` prunes that subtree.
|
|
8
|
+
*/
|
|
9
|
+
declare const walkAst: (node: unknown, visitor: (node: OxcNode) => boolean | void) => void;
|
|
10
|
+
/** Extract the string value from the first argument of a call expression. */
|
|
11
|
+
declare const getFirstStringArg: (callExpressionNode: OxcNode) => string | null;
|
|
12
|
+
/** Returns true when `node` is a useIntlayer / getIntlayer CallExpression. */
|
|
13
|
+
declare const isIntlayerCall: (node: OxcNode) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Parse `text` into an Oxc program AST.
|
|
16
|
+
* Returns null when the parse completely fails (e.g. unsupported syntax).
|
|
17
|
+
* Oxc is generally resilient to partial/in-progress edits and still
|
|
18
|
+
* returns a
|
|
19
|
+
* usable AST alongside error diagnostics, so this is rare.
|
|
20
|
+
*/
|
|
21
|
+
declare const parseText: (text: string) => OxcNode | null;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { INTLAYER_GETTERS, OxcNode, getFirstStringArg, isIntlayerCall, parseText, walkAst };
|
|
24
|
+
//# sourceMappingURL=oxcUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oxcUtils.d.ts","names":[],"sources":["../../src/oxcUtils.ts"],"mappings":";cAEa,gBAAA,EAAkB,GAAA;AAAA,KAKnB,OAAA,GAAU,MAAA;;;;AALS;AAK/B;cAOa,OAAA,GACX,IAAA,WACA,OAAA,GAAU,IAAA,EAAM,OAAA;;cAsBL,iBAAA,GACX,kBAAoB,EAAA,OAAA;AAhCA;AAAA,cAmET,cAAA,GAAkB,IAAM,EAAA,OAAA;;;;;;;;cAiBxB,SAAA,GAAa,IAAA,aAAe,OAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { escapeRegularExpression, findFieldRangesInFile, offsetToRange } from "./findFieldInFile.js";
|
|
2
|
+
import { findKeyAtOffset } from "./findKeyAtOffset.js";
|
|
3
|
+
import { findContentFieldAtOffset, findKeyInContentFile } from "./findKeyInContentFile.js";
|
|
4
|
+
import { findUsageFieldAtOffset } from "./findUsageFieldAtOffset.js";
|
|
5
|
+
export { escapeRegularExpression, findContentFieldAtOffset, findFieldRangesInFile, findKeyAtOffset, findKeyInContentFile, findUsageFieldAtOffset, offsetToRange };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/lsp",
|
|
3
|
-
"version": "8.11.
|
|
3
|
+
"version": "8.11.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Intlayer Language Server. Handle LSP to help IDE and AI agent to use Intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -36,9 +36,12 @@
|
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
38
|
"types": "./dist/types/index.d.ts",
|
|
39
|
-
"require": "./dist/esm/index.mjs",
|
|
40
39
|
"import": "./dist/esm/index.mjs"
|
|
41
40
|
},
|
|
41
|
+
"./utils": {
|
|
42
|
+
"types": "./dist/types/utils.d.ts",
|
|
43
|
+
"import": "./dist/esm/utils.mjs"
|
|
44
|
+
},
|
|
42
45
|
"./package.json": "./package.json"
|
|
43
46
|
},
|
|
44
47
|
"main": "dist/esm/index.mjs",
|
|
@@ -49,6 +52,9 @@
|
|
|
49
52
|
".": [
|
|
50
53
|
"./dist/types/index.d.ts"
|
|
51
54
|
],
|
|
55
|
+
"utils": [
|
|
56
|
+
"./dist/types/utils.d.ts"
|
|
57
|
+
],
|
|
52
58
|
"package.json": [
|
|
53
59
|
"./package.json"
|
|
54
60
|
]
|
|
@@ -91,8 +97,9 @@
|
|
|
91
97
|
"@intlayer/config": "8.11.3",
|
|
92
98
|
"@intlayer/types": "8.11.3",
|
|
93
99
|
"@intlayer/unmerged-dictionaries-entry": "8.11.3",
|
|
94
|
-
"
|
|
95
|
-
"vscode-languageserver
|
|
100
|
+
"oxc-parser": "0.134.0",
|
|
101
|
+
"vscode-languageserver": "9.0.1",
|
|
102
|
+
"vscode-languageserver-textdocument": "1.0.12"
|
|
96
103
|
},
|
|
97
104
|
"devDependencies": {
|
|
98
105
|
"@types/node": "25.9.1",
|