@ripple-ts/language-server 0.2.173 → 0.2.175
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 +2 -2
- package/src/definitionPlugin.js +127 -0
- package/src/diagnosticPlugin.js +2 -2
- package/src/server.js +20 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ripple-ts/language-server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.175",
|
|
4
4
|
"description": "Language Server Protocol implementation for Ripple",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"volar-service-typescript": "0.0.65",
|
|
19
19
|
"vscode-languageserver-textdocument": "^1.0.12",
|
|
20
20
|
"vscode-uri": "^3.1.0",
|
|
21
|
-
"@ripple-ts/typescript-plugin": "0.2.
|
|
21
|
+
"@ripple-ts/typescript-plugin": "0.2.175"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": "^5.9.2"
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const { RippleVirtualCode } = require('@ripple-ts/typescript-plugin/src/language.js');
|
|
2
|
+
const { URI } = require('vscode-uri');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('@volar/language-server').LanguageServicePlugin} LanguageServicePlugin
|
|
6
|
+
* @typedef {import('@volar/language-server').LanguageServiceContext} LanguageServiceContext
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const DEBUG = process.env.RIPPLE_DEBUG === 'true';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {...unknown} args
|
|
13
|
+
*/
|
|
14
|
+
function log(...args) {
|
|
15
|
+
if (DEBUG) {
|
|
16
|
+
console.log('[Ripple Definition]', ...args);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {LanguageServicePlugin}
|
|
22
|
+
*/
|
|
23
|
+
function createDefinitionPlugin() {
|
|
24
|
+
return {
|
|
25
|
+
name: 'ripple-definition',
|
|
26
|
+
capabilities: {
|
|
27
|
+
definitionProvider: true,
|
|
28
|
+
},
|
|
29
|
+
create(/** @type {LanguageServiceContext} */ context) {
|
|
30
|
+
return {
|
|
31
|
+
/**
|
|
32
|
+
* Provide definition with component keyword support
|
|
33
|
+
* @param {import('vscode-languageserver-textdocument').TextDocument} document
|
|
34
|
+
* @param {import('@volar/language-server').Position} position
|
|
35
|
+
* @param {import('@volar/language-server').CancellationToken} token
|
|
36
|
+
*/
|
|
37
|
+
async provideDefinition(document, position, token) {
|
|
38
|
+
const uri = URI.parse(document.uri);
|
|
39
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
40
|
+
|
|
41
|
+
// Get TypeScript definition from typescript-semantic service
|
|
42
|
+
let tsDefinitions = [];
|
|
43
|
+
for (const [plugin, instance] of context.plugins) {
|
|
44
|
+
if (plugin.name === 'typescript-semantic' && instance.provideDefinition) {
|
|
45
|
+
const result = await instance.provideDefinition(document, position, token);
|
|
46
|
+
if (result) {
|
|
47
|
+
tsDefinitions.push(...(Array.isArray(result) ? result : [result]));
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If no TypeScript definitions, nothing to modify
|
|
54
|
+
// Volar will let the next ts plugin handle it
|
|
55
|
+
if (tsDefinitions.length === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If not in a Ripple embedded context, just return TypeScript results
|
|
60
|
+
if (!decoded) {
|
|
61
|
+
return tsDefinitions;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const [sourceUri, virtualCodeId] = decoded;
|
|
65
|
+
const sourceScript = context.language.scripts.get(sourceUri);
|
|
66
|
+
const virtualCode = sourceScript?.generated?.embeddedCodes.get(virtualCodeId);
|
|
67
|
+
|
|
68
|
+
if (!(virtualCode instanceof RippleVirtualCode) || !virtualCode.mappings) {
|
|
69
|
+
return tsDefinitions;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Get the range from TypeScript's definition to find the exact token
|
|
73
|
+
// This gives us the precise start and end of the token (e.g., "function")
|
|
74
|
+
const firstDefinition = tsDefinitions[0];
|
|
75
|
+
if (!firstDefinition?.originSelectionRange) {
|
|
76
|
+
return tsDefinitions;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const range = firstDefinition.originSelectionRange;
|
|
80
|
+
const rangeStart = document.offsetAt(range.start);
|
|
81
|
+
const rangeEnd = document.offsetAt(range.end);
|
|
82
|
+
|
|
83
|
+
// Find the mapping using the exact token range for O(1) lookup
|
|
84
|
+
const mapping = virtualCode.findMappingByGeneratedRange(rangeStart, rangeEnd);
|
|
85
|
+
|
|
86
|
+
if (!mapping) {
|
|
87
|
+
return tsDefinitions;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
log('Found mapping for definition at range', 'start: ', rangeStart, 'end: ', rangeEnd);
|
|
91
|
+
|
|
92
|
+
// Check if source length is greater than generated length (component -> function)
|
|
93
|
+
const customData = mapping.data.customData;
|
|
94
|
+
const sourceLength = mapping.lengths[0];
|
|
95
|
+
const generatedLength = customData.generatedLengths[0];
|
|
96
|
+
|
|
97
|
+
// If no generatedLengths, or source and generated are same length, no transformation
|
|
98
|
+
if (sourceLength <= generatedLength) {
|
|
99
|
+
return tsDefinitions;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const diffLength = sourceLength - generatedLength;
|
|
103
|
+
|
|
104
|
+
for (const definition of tsDefinitions) {
|
|
105
|
+
const tsRange = definition.originSelectionRange;
|
|
106
|
+
if (!tsRange) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
definition.originSelectionRange = {
|
|
111
|
+
start: tsRange.start,
|
|
112
|
+
end: {
|
|
113
|
+
line: tsRange.end.line,
|
|
114
|
+
character: tsRange.end.character + diffLength,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return tsDefinitions;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = {
|
|
126
|
+
createDefinitionPlugin,
|
|
127
|
+
};
|
package/src/diagnosticPlugin.js
CHANGED
|
@@ -31,7 +31,7 @@ function logError(...args) {
|
|
|
31
31
|
/**
|
|
32
32
|
* @returns {LanguageServicePlugin}
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
34
|
+
function createDiagnosticPlugin() {
|
|
35
35
|
log('Creating Ripple diagnostic plugin...');
|
|
36
36
|
|
|
37
37
|
return {
|
|
@@ -236,5 +236,5 @@ function getEmbeddedInfo(context, document) {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
module.exports = {
|
|
239
|
-
|
|
239
|
+
createDiagnosticPlugin,
|
|
240
240
|
};
|
package/src/server.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
createServer,
|
|
4
4
|
createTypeScriptProject,
|
|
5
5
|
} = require('@volar/language-server/node');
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
6
|
+
const { createDiagnosticPlugin } = require('./diagnosticPlugin.js');
|
|
7
|
+
const { createDefinitionPlugin } = require('./definitionPlugin.js');
|
|
8
|
+
const {
|
|
9
|
+
getRippleLanguagePlugin,
|
|
10
|
+
resolveConfig,
|
|
11
|
+
} = require('@ripple-ts/typescript-plugin/src/language.js');
|
|
8
12
|
const { create: createTypeScriptServices } = require('volar-service-typescript');
|
|
9
13
|
|
|
10
14
|
const DEBUG = process.env.RIPPLE_DEBUG === 'true';
|
|
@@ -86,24 +90,20 @@ function createRippleLanguageServer() {
|
|
|
86
90
|
|
|
87
91
|
const initResult = server.initialize(
|
|
88
92
|
params,
|
|
89
|
-
createTypeScriptProject(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
),
|
|
103
|
-
[
|
|
104
|
-
createRippleDiagnosticPlugin(),
|
|
105
|
-
...createTypeScriptServices(ts),
|
|
106
|
-
],
|
|
93
|
+
createTypeScriptProject(ts, undefined, ({ projectHost }) => {
|
|
94
|
+
wrapCompilerOptionsProvider(projectHost, 'getCompilationSettings');
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
languagePlugins: [rippleLanguagePlugin],
|
|
98
|
+
setup({ project }) {
|
|
99
|
+
wrapCompilerOptionsProvider(
|
|
100
|
+
project?.typescript?.languageServiceHost,
|
|
101
|
+
'getCompilationSettings',
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}),
|
|
106
|
+
[createDiagnosticPlugin(), createDefinitionPlugin(), ...createTypeScriptServices(ts)],
|
|
107
107
|
);
|
|
108
108
|
|
|
109
109
|
log('Server initialization complete');
|