@intlayer/lsp 8.11.4 → 9.0.0
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/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/esm/callers/index.mjs +12 -0
- package/dist/esm/callers/index.mjs.map +1 -0
- package/dist/esm/callers/patterns.mjs +37 -0
- package/dist/esm/callers/patterns.mjs.map +1 -0
- package/dist/esm/dictionaryUtils.mjs +84 -0
- package/dist/esm/dictionaryUtils.mjs.map +1 -0
- package/dist/esm/findFieldInFile.mjs +22 -125
- package/dist/esm/findFieldInFile.mjs.map +1 -1
- package/dist/esm/findKeyAtOffset.mjs +20 -24
- package/dist/esm/findKeyAtOffset.mjs.map +1 -1
- package/dist/esm/findKeyInContentFile.mjs +259 -40
- package/dist/esm/findKeyInContentFile.mjs.map +1 -1
- package/dist/esm/findTCallAtOffset.mjs +33 -0
- package/dist/esm/findTCallAtOffset.mjs.map +1 -0
- package/dist/esm/findUsageFieldAtOffset.mjs +12 -51
- package/dist/esm/findUsageFieldAtOffset.mjs.map +1 -1
- package/dist/esm/index.mjs +343 -172
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/oxcUtils.mjs +99 -29
- package/dist/esm/oxcUtils.mjs.map +1 -1
- package/dist/esm/usageAnalyzer.mjs +695 -0
- package/dist/esm/usageAnalyzer.mjs.map +1 -0
- package/dist/esm/utils.mjs +12 -1
- package/dist/types/callers/index.d.ts +5 -0
- package/dist/types/callers/index.d.ts.map +1 -0
- package/dist/types/callers/patterns.d.ts +30 -0
- package/dist/types/callers/patterns.d.ts.map +1 -0
- package/dist/types/dictionaryUtils.d.ts +11 -0
- package/dist/types/dictionaryUtils.d.ts.map +1 -0
- package/dist/types/findFieldInFile.d.ts +19 -22
- package/dist/types/findFieldInFile.d.ts.map +1 -1
- package/dist/types/findKeyAtOffset.d.ts +15 -12
- package/dist/types/findKeyAtOffset.d.ts.map +1 -1
- package/dist/types/findKeyInContentFile.d.ts +23 -21
- package/dist/types/findKeyInContentFile.d.ts.map +1 -1
- package/dist/types/findTCallAtOffset.d.ts +24 -0
- package/dist/types/findTCallAtOffset.d.ts.map +1 -0
- package/dist/types/findUsageFieldAtOffset.d.ts +14 -13
- package/dist/types/findUsageFieldAtOffset.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/oxcUtils.d.ts +44 -15
- package/dist/types/oxcUtils.d.ts.map +1 -1
- package/dist/types/usageAnalyzer.d.ts +141 -0
- package/dist/types/usageAnalyzer.d.ts.map +1 -0
- package/dist/types/utils.d.ts +15 -1
- package/package.json +11 -24
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { OxcNode } from "./oxcUtils.js";
|
|
2
|
+
//#region src/usageAnalyzer.d.ts
|
|
3
|
+
/** How a message usage appears in source code. */
|
|
4
|
+
type MessageUsageKind = "call" | "member" | "destructure" | "jsx" | "tagged-template" | "namespace";
|
|
5
|
+
/**
|
|
6
|
+
* One resolved translation usage inside a source file: which dictionary and
|
|
7
|
+
* field it reads, and the text span it occupies.
|
|
8
|
+
*/
|
|
9
|
+
type MessageUsage = {
|
|
10
|
+
/** The intlayer dictionary key the usage reads from. */
|
|
11
|
+
dictionaryKey: string;
|
|
12
|
+
/**
|
|
13
|
+
* Path of content fields from the dictionary root. Empty for
|
|
14
|
+
* dictionary-level usages (`namespace` kind, or a bare content variable).
|
|
15
|
+
*/
|
|
16
|
+
fieldPath: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Spans of each `fieldPath` segment, aligned by index, when the segments
|
|
19
|
+
* are addressable in source (member chains). Used to trim the path to the
|
|
20
|
+
* segment under the cursor.
|
|
21
|
+
*/
|
|
22
|
+
fieldSpans?: {
|
|
23
|
+
start: number;
|
|
24
|
+
end: number;
|
|
25
|
+
}[];
|
|
26
|
+
/** Start offset of the usage expression. */
|
|
27
|
+
start: number;
|
|
28
|
+
/** End offset of the usage expression. */
|
|
29
|
+
end: number;
|
|
30
|
+
kind: MessageUsageKind;
|
|
31
|
+
/** The caller that produced the usage, e.g. `'useTranslations'`. */
|
|
32
|
+
callerName: string;
|
|
33
|
+
/** The library the caller belongs to, e.g. `'next-intl'` or `'intlayer'`. */
|
|
34
|
+
library: string;
|
|
35
|
+
/** Module specifier the caller was imported from, when resolvable. */
|
|
36
|
+
moduleSource?: string;
|
|
37
|
+
/**
|
|
38
|
+
* `true` for `member` usages that are a bare reference to a bound variable
|
|
39
|
+
* (`{greet}` in JSX after `const { greet } = useIntlayer(…)`) — the field
|
|
40
|
+
* name itself is not spelled at the usage site. Excluded from
|
|
41
|
+
* find-references results but kept for decorations and hover.
|
|
42
|
+
*/
|
|
43
|
+
isBareReference?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Analyse a source file and return every resolvable translation usage:
|
|
47
|
+
* base-intlayer content access and all compat-library forms (translation
|
|
48
|
+
* functions, self calls, JSX message components, tagged templates).
|
|
49
|
+
*
|
|
50
|
+
* Pure and self-contained (oxc parse only) — shared by the LSP handlers and
|
|
51
|
+
* the VS Code extension providers/decorations.
|
|
52
|
+
*
|
|
53
|
+
* @param text - Full source text (a script: TS/TSX or an extracted SFC block).
|
|
54
|
+
* @returns Usages ordered by start offset.
|
|
55
|
+
*/
|
|
56
|
+
declare const collectMessageUsages: (text: string) => MessageUsage[];
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the dictionary key declared by a single call-expression node when
|
|
59
|
+
* it matches any registered non-self caller (`useIntlayer("key")`,
|
|
60
|
+
* `useI18n({ namespace })`, …). Used for on-the-fly checks where the full
|
|
61
|
+
* file analysis is not needed (e.g. completion context).
|
|
62
|
+
*
|
|
63
|
+
* @param callNode - A candidate CallExpression node.
|
|
64
|
+
*/
|
|
65
|
+
declare const matchCallNamespace: (callNode: OxcNode) => string | null;
|
|
66
|
+
/**
|
|
67
|
+
* A call site declaring which dictionary a caller reads
|
|
68
|
+
* (`useIntlayer("home")`, `useI18n({ namespace: 'home' })`), with the spans
|
|
69
|
+
* needed to anchor diagnostics and cursor checks.
|
|
70
|
+
*/
|
|
71
|
+
type NamespaceReference = {
|
|
72
|
+
dictionaryKey: string;
|
|
73
|
+
callerName: string;
|
|
74
|
+
library: string;
|
|
75
|
+
/** Span of the whole call expression. */
|
|
76
|
+
callStart: number;
|
|
77
|
+
callEnd: number;
|
|
78
|
+
/** Span of the matched callee name (identifier or method property). */
|
|
79
|
+
calleeStart: number;
|
|
80
|
+
calleeEnd: number;
|
|
81
|
+
/** Span of the namespace argument (string literal or option value). */
|
|
82
|
+
namespaceStart: number;
|
|
83
|
+
namespaceEnd: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Collect every call site with an addressable namespace argument (positional
|
|
87
|
+
* or options property) resolving to a static string. Powers the
|
|
88
|
+
* unknown-dictionary diagnostics and `findKeyAtOffset`.
|
|
89
|
+
*
|
|
90
|
+
* Self callers (`formatMessage`, lingui `t`/`_`) don't declare a namespace at
|
|
91
|
+
* the call site and are excluded.
|
|
92
|
+
*
|
|
93
|
+
* @param text - Full source text.
|
|
94
|
+
*/
|
|
95
|
+
declare const collectNamespaceReferences: (text: string) => NamespaceReference[];
|
|
96
|
+
/**
|
|
97
|
+
* A source variable bound to a dictionary by a caller declaration:
|
|
98
|
+
* dictionary content (or a field subtree of it) for `content` callers, or a
|
|
99
|
+
* translation function for `return-value` / `destructured-t` callers.
|
|
100
|
+
*/
|
|
101
|
+
type CallerVariableBinding = {
|
|
102
|
+
/** Local variable name. */
|
|
103
|
+
variableName: string;
|
|
104
|
+
/** The dictionary the variable reads from. */
|
|
105
|
+
dictionaryKey: string;
|
|
106
|
+
/**
|
|
107
|
+
* Field path from the dictionary root the variable points at (content
|
|
108
|
+
* bindings), or the key prefix applied to every call (translator bindings).
|
|
109
|
+
*/
|
|
110
|
+
basePath: string[];
|
|
111
|
+
/** Whether the variable holds content or a translation function. */
|
|
112
|
+
bindingKind: "content" | "translator";
|
|
113
|
+
/** The caller that created the binding. */
|
|
114
|
+
callerName: string;
|
|
115
|
+
library: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Collect every variable bound to a dictionary in the file. Used by consumers
|
|
119
|
+
* that scan non-script regions (Vue/Angular templates) for references to
|
|
120
|
+
* those variables, or that need to know which dictionaries a file consumes.
|
|
121
|
+
*
|
|
122
|
+
* @param text - Full source text (a script: TS/TSX or an extracted SFC block).
|
|
123
|
+
*/
|
|
124
|
+
declare const collectCallerBindings: (text: string) => CallerVariableBinding[];
|
|
125
|
+
/**
|
|
126
|
+
* Find the most specific translation usage at `offset`.
|
|
127
|
+
*
|
|
128
|
+
* For member chains the field path is trimmed to the segment under the
|
|
129
|
+
* cursor: hovering `section` in `content.section.title` yields
|
|
130
|
+
* `['section']`, not the full chain.
|
|
131
|
+
*
|
|
132
|
+
* Dictionary-level `namespace` usages are only returned when no field-level
|
|
133
|
+
* usage matches the offset.
|
|
134
|
+
*
|
|
135
|
+
* @param text - Full source text.
|
|
136
|
+
* @param offset - Cursor offset in `text`.
|
|
137
|
+
*/
|
|
138
|
+
declare const findMessageUsageAtOffset: (text: string, offset: number) => MessageUsage | null;
|
|
139
|
+
//#endregion
|
|
140
|
+
export { CallerVariableBinding, MessageUsage, MessageUsageKind, NamespaceReference, collectCallerBindings, collectMessageUsages, collectNamespaceReferences, findMessageUsageAtOffset, matchCallNamespace };
|
|
141
|
+
//# sourceMappingURL=usageAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usageAnalyzer.d.ts","names":[],"sources":["../../src/usageAnalyzer.ts"],"mappings":";;;KAwBY;;;;;KAkBA;;EAEV;;;;;EAKA;;;;;;EAMA;IAAe;IAAe;;;EAE9B;;EAEA;EACA,MAAM;;EAEN;;EAEA;;EAEA;;;;;;;EAOA;;;;;;;;;;;;;cA47BW,uBAAwB,iBAAe;;;;;;;;;cAkCvC,qBAAsB,UAAU;;;;;;KAgCjC;EACV;EACA;EACA;;EAEA;EACA;;EAEA;EACA;;EAEA;EACA;;;;;;;;;;;;cAwCW,6BACX,iBACC;;;;;;KA8DS;;EAEV;;EAEA;;;;;EAKA;;EAEA;;EAEA;EACA;;;;;;;;;cAUW,wBACX,iBACC;;;;;;;;;;;;;;cA0DU,2BACX,cACA,mBACC"}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
import { index_d_exports } from "./callers/index.js";
|
|
2
|
+
import { buildCallerWithKeyPattern, buildKeyUsagePatterns, getCallerNamesAlternation } from "./callers/patterns.js";
|
|
1
3
|
import { escapeRegularExpression, findFieldRangesInFile, offsetToRange } from "./findFieldInFile.js";
|
|
2
4
|
import { findKeyAtOffset } from "./findKeyAtOffset.js";
|
|
3
5
|
import { findContentFieldAtOffset, findKeyInContentFile } from "./findKeyInContentFile.js";
|
|
6
|
+
import { findTCallAtOffset } from "./findTCallAtOffset.js";
|
|
4
7
|
import { findUsageFieldAtOffset } from "./findUsageFieldAtOffset.js";
|
|
5
|
-
|
|
8
|
+
import { OxcNode, buildParentMap, getFirstStringArg, getObjectPropertyNode, getObjectPropertyString, getPropertyKeyName, getStaticStringValue, getStringArgAt, isStringLiteralNode, nodeContainsOffset, nodeEnd, nodeStart, parseText, walkAst } from "./oxcUtils.js";
|
|
9
|
+
import { CallerVariableBinding, MessageUsage, MessageUsageKind, NamespaceReference, collectCallerBindings, collectMessageUsages, collectNamespaceReferences, findMessageUsageAtOffset, matchCallNamespace } from "./usageAnalyzer.js";
|
|
10
|
+
type ALL_CALLERS = index_d_exports.ALL_CALLERS;
|
|
11
|
+
type BASE_CALLERS = index_d_exports.BASE_CALLERS;
|
|
12
|
+
type CALLERS_BY_NAME = index_d_exports.CALLERS_BY_NAME;
|
|
13
|
+
type COMPAT_CALLERS = index_d_exports.COMPAT_CALLERS;
|
|
14
|
+
type CallerDescriptor = index_d_exports.CallerDescriptor;
|
|
15
|
+
type CallerResultShape = index_d_exports.CallerResultShape;
|
|
16
|
+
type CallerValueSource = index_d_exports.CallerValueSource;
|
|
17
|
+
type getPositionalKeyCallerNames = index_d_exports.getPositionalKeyCallerNames;
|
|
18
|
+
type isCallerActive = index_d_exports.isCallerActive;
|
|
19
|
+
export { ALL_CALLERS, BASE_CALLERS, CALLERS_BY_NAME, COMPAT_CALLERS, type CallerDescriptor, type CallerResultShape, type CallerValueSource, type CallerVariableBinding, type MessageUsage, type MessageUsageKind, type NamespaceReference, type OxcNode, buildCallerWithKeyPattern, buildKeyUsagePatterns, buildParentMap, collectCallerBindings, collectMessageUsages, collectNamespaceReferences, escapeRegularExpression, findContentFieldAtOffset, findFieldRangesInFile, findKeyAtOffset, findKeyInContentFile, findMessageUsageAtOffset, findTCallAtOffset, findUsageFieldAtOffset, getCallerNamesAlternation, getFirstStringArg, getObjectPropertyNode, getObjectPropertyString, getPositionalKeyCallerNames, getPropertyKeyName, getStaticStringValue, getStringArgAt, isCallerActive, isStringLiteralNode, matchCallNamespace, nodeContainsOffset, nodeEnd, nodeStart, offsetToRange, parseText, walkAst };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/lsp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Intlayer Language Server. Handle LSP to help IDE and AI agent to use Intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -76,45 +76,32 @@
|
|
|
76
76
|
"format:fix": "bun --bun biome format --write .",
|
|
77
77
|
"lint": "bun --bun biome lint .",
|
|
78
78
|
"lint:fix": "bun --bun biome lint --write .",
|
|
79
|
-
"manange:permissions": "bun -e \"require('fs').chmodSync('dist/esm/index.mjs', 0o755)\"",
|
|
80
|
-
"process-files": "ts-node src/transpiler/processFilesCLI.ts --dir $npm_config_dir --extension $npm_config_extension --no-node-snapshot",
|
|
81
79
|
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
82
80
|
"publish": "bun publish || true",
|
|
83
|
-
"publish:canary": "bun publish --access public --tag canary || true",
|
|
84
|
-
"publish:latest": "bun publish --access public --tag latest || true",
|
|
85
|
-
"start": "bun start:stdio",
|
|
86
|
-
"start:client": "bun dist/esm/client/sse.mjs",
|
|
87
|
-
"start:docker": "docker run --rm -p 3000:3000 --name intlayer-mcp-app intlayer-mcp",
|
|
88
|
-
"start:inspector": "npx @modelcontextprotocol/inspector bun dist/esm/server/stdio.mjs",
|
|
89
|
-
"start:inspector:sse": "npx @modelcontextprotocol/inspector bun dist/esm/server/sse.mjs",
|
|
90
|
-
"start:sse": "bun dist/esm/server/sse.mjs",
|
|
91
|
-
"start:stdio": "bun dist/esm/server/stdio.mjs",
|
|
92
81
|
"test": "bun --bun vitest run",
|
|
93
82
|
"test:watch": "bun --bun vitest",
|
|
94
83
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
95
84
|
},
|
|
96
85
|
"dependencies": {
|
|
97
|
-
"@intlayer/config": "
|
|
98
|
-
"@intlayer/
|
|
99
|
-
"@intlayer/
|
|
100
|
-
"
|
|
101
|
-
"
|
|
86
|
+
"@intlayer/config": "9.0.0",
|
|
87
|
+
"@intlayer/engine": "9.0.0",
|
|
88
|
+
"@intlayer/types": "9.0.0",
|
|
89
|
+
"@intlayer/unmerged-dictionaries-entry": "9.0.0",
|
|
90
|
+
"oxc-parser": "0.138.0",
|
|
91
|
+
"vscode-languageserver": "10.1.0",
|
|
102
92
|
"vscode-languageserver-textdocument": "1.0.12"
|
|
103
93
|
},
|
|
104
94
|
"devDependencies": {
|
|
105
|
-
"@types/node": "
|
|
95
|
+
"@types/node": "26.1.1",
|
|
106
96
|
"@utils/ts-config": "1.0.4",
|
|
107
97
|
"@utils/ts-config-types": "1.0.4",
|
|
108
98
|
"@utils/tsdown-config": "1.0.4",
|
|
109
99
|
"rimraf": "6.1.3",
|
|
110
|
-
"tsdown": "0.22.
|
|
111
|
-
"typescript": "
|
|
112
|
-
"vitest": "4.1.
|
|
100
|
+
"tsdown": "0.22.13",
|
|
101
|
+
"typescript": "7.0.2",
|
|
102
|
+
"vitest": "4.1.10"
|
|
113
103
|
},
|
|
114
104
|
"engines": {
|
|
115
105
|
"node": ">=14.18"
|
|
116
|
-
},
|
|
117
|
-
"bug": {
|
|
118
|
-
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
119
106
|
}
|
|
120
107
|
}
|