volar-service-typescript 0.0.25 → 0.0.27-patch.1
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/index.d.ts +0 -1
- package/index.js +103 -76
- package/lib/configs/getUserPreferences.js +1 -1
- package/lib/features/callHierarchy.js +10 -10
- package/lib/features/codeAction.js +4 -4
- package/lib/features/codeActionResolve.js +3 -3
- package/lib/features/completions/basic.js +2 -2
- package/lib/features/completions/jsDoc.js +2 -2
- package/lib/features/completions/resolve.js +3 -3
- package/lib/features/definition.js +2 -2
- package/lib/features/diagnostics.js +5 -5
- package/lib/features/documentHighlight.js +2 -2
- package/lib/features/documentSymbol.js +2 -2
- package/lib/features/fileReferences.js +2 -2
- package/lib/features/fileRename.js +3 -3
- package/lib/features/foldingRanges.js +2 -2
- package/lib/features/formatting.js +5 -5
- package/lib/features/hover.js +3 -3
- package/lib/features/implementation.js +2 -2
- package/lib/features/inlayHints.js +3 -3
- package/lib/features/prepareRename.js +2 -2
- package/lib/features/references.js +2 -2
- package/lib/features/rename.js +8 -8
- package/lib/features/selectionRanges.js +2 -2
- package/lib/features/semanticTokens.js +5 -5
- package/lib/features/signatureHelp.js +2 -2
- package/lib/features/typeDefinition.js +2 -2
- package/lib/features/workspaceSymbol.js +2 -2
- package/lib/types.d.ts +4 -4
- package/lib/utils/previewer.js +1 -1
- package/lib/utils/transforms.js +3 -3
- package/package.json +4 -5
- package/lib/protocol.d.ts +0 -2
- package/lib/protocol.js +0 -3
package/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
export * from '@volar/typescript';
|
|
4
4
|
export interface Provide {
|
|
5
5
|
'typescript/typescript': () => typeof import('typescript');
|
|
6
|
-
'typescript/sys': () => ts.System;
|
|
7
6
|
'typescript/languageService': () => ts.LanguageService;
|
|
8
7
|
'typescript/languageServiceHost': () => ts.LanguageServiceHost;
|
|
9
8
|
'typescript/syntacticLanguageService': () => ts.LanguageService;
|
package/index.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.create = void 0;
|
|
18
18
|
const semver = require("semver");
|
|
19
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
20
19
|
const shared_1 = require("./lib/shared");
|
|
20
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
21
21
|
const typescript_1 = require("@volar/typescript");
|
|
22
22
|
const tsFaster = require("typescript-auto-import-cache");
|
|
23
23
|
const _callHierarchy = require("./lib/features/callHierarchy");
|
|
@@ -77,30 +77,26 @@ function create(ts) {
|
|
|
77
77
|
};
|
|
78
78
|
const syntacticCtx = {
|
|
79
79
|
...context,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
languageService: ts.createLanguageService(syntacticServiceHost, undefined, 2),
|
|
83
|
-
},
|
|
80
|
+
languageServiceHost: syntacticServiceHost,
|
|
81
|
+
languageService: ts.createLanguageService(syntacticServiceHost, undefined, 2),
|
|
84
82
|
ts,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (virtualFile) {
|
|
89
|
-
return context.documents.get(uri, virtualFile.languageId, virtualFile.snapshot);
|
|
83
|
+
uriToFileName: uri => {
|
|
84
|
+
if (uri !== syntacticHostCtx.document?.uri) {
|
|
85
|
+
throw new Error(`uriToFileName: uri not found: ${uri}`);
|
|
90
86
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
return syntacticHostCtx.fileName;
|
|
88
|
+
},
|
|
89
|
+
fileNameToUri: fileName => {
|
|
90
|
+
if (fileName !== syntacticHostCtx.fileName) {
|
|
91
|
+
throw new Error(`fileNameToUri: fileName not found: ${fileName}`);
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
documents.set(snapshot, document);
|
|
101
|
-
}
|
|
102
|
-
return document;
|
|
93
|
+
return syntacticHostCtx.document.uri;
|
|
94
|
+
},
|
|
95
|
+
getTextDocument(uri) {
|
|
96
|
+
if (uri !== syntacticHostCtx.document?.uri) {
|
|
97
|
+
throw new Error(`getTextDocument: uri not found: ${uri}`);
|
|
103
98
|
}
|
|
99
|
+
return syntacticHostCtx.document;
|
|
104
100
|
},
|
|
105
101
|
};
|
|
106
102
|
const findDocumentSymbols = documentSymbol.register(syntacticCtx);
|
|
@@ -109,19 +105,18 @@ function create(ts) {
|
|
|
109
105
|
const syntacticService = {
|
|
110
106
|
provide: {
|
|
111
107
|
'typescript/typescript': () => ts,
|
|
112
|
-
'typescript/
|
|
113
|
-
'typescript/
|
|
114
|
-
'typescript/
|
|
115
|
-
'typescript/
|
|
116
|
-
'typescript/syntacticLanguageServiceHost': () => syntacticCtx.typescript.languageServiceHost,
|
|
108
|
+
'typescript/languageService': () => syntacticCtx.languageService,
|
|
109
|
+
'typescript/languageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
110
|
+
'typescript/syntacticLanguageService': () => syntacticCtx.languageService,
|
|
111
|
+
'typescript/syntacticLanguageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
117
112
|
},
|
|
118
113
|
provideAutoInsertionEdit(document, position, lastChange) {
|
|
119
114
|
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
120
115
|
&& lastChange.text.endsWith('>')) {
|
|
121
116
|
const config = context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.autoClosingTags') ?? true;
|
|
122
117
|
if (config) {
|
|
123
|
-
prepareSyntacticService(document);
|
|
124
|
-
const close = syntacticCtx.
|
|
118
|
+
const ctx = prepareSyntacticService(document);
|
|
119
|
+
const close = syntacticCtx.languageService.getJsxClosingTagAtPosition(ctx.fileName, document.offsetAt(position));
|
|
125
120
|
if (close) {
|
|
126
121
|
return '$0' + close.newText;
|
|
127
122
|
}
|
|
@@ -163,7 +158,8 @@ function create(ts) {
|
|
|
163
158
|
provideFormattingIndentSensitiveLines(document) {
|
|
164
159
|
if (!(0, shared_1.isTsDocument)(document))
|
|
165
160
|
return;
|
|
166
|
-
const
|
|
161
|
+
const ctx = prepareSyntacticService(document);
|
|
162
|
+
const sourceFile = ts.createSourceFile(ctx.fileName, document.getText(), ts.ScriptTarget.ESNext);
|
|
167
163
|
if (sourceFile) {
|
|
168
164
|
const lines = [];
|
|
169
165
|
sourceFile.forEachChild(function walk(node) {
|
|
@@ -192,7 +188,7 @@ function create(ts) {
|
|
|
192
188
|
if (!context.language.typescript) {
|
|
193
189
|
return syntacticService;
|
|
194
190
|
}
|
|
195
|
-
const { sys, languageServiceHost
|
|
191
|
+
const { sys, languageServiceHost } = context.language.typescript;
|
|
196
192
|
const created = tsFaster.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, (0, typescript_1.getDocumentRegistry)(ts, sys.useCaseSensitiveFileNames, languageServiceHost.getCurrentDirectory())));
|
|
197
193
|
const { languageService } = created;
|
|
198
194
|
if (created.setPreferences && context.env.getConfiguration) {
|
|
@@ -217,7 +213,7 @@ function create(ts) {
|
|
|
217
213
|
updateSourceScriptFileNames();
|
|
218
214
|
}
|
|
219
215
|
for (const change of params.changes) {
|
|
220
|
-
const fileName = context.env.uriToFileName(change.uri);
|
|
216
|
+
const fileName = context.env.typescript.uriToFileName(change.uri);
|
|
221
217
|
if (sourceScriptNames.has(normalizeFileName(fileName))) {
|
|
222
218
|
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
|
|
223
219
|
}
|
|
@@ -226,34 +222,52 @@ function create(ts) {
|
|
|
226
222
|
function updateSourceScriptFileNames() {
|
|
227
223
|
sourceScriptNames.clear();
|
|
228
224
|
for (const fileName of languageServiceHost.getScriptFileNames()) {
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
226
|
+
const sourceFile = context.language.files.get(uri);
|
|
227
|
+
if (sourceFile?.generated) {
|
|
228
|
+
const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code);
|
|
229
|
+
if (tsCode) {
|
|
230
|
+
sourceScriptNames.add(normalizeFileName(fileName));
|
|
231
|
+
}
|
|
233
232
|
}
|
|
234
|
-
|
|
235
|
-
if (sourceFile && !sourceFile.virtualFile) {
|
|
233
|
+
else if (sourceFile) {
|
|
236
234
|
sourceScriptNames.add(normalizeFileName(fileName));
|
|
237
|
-
continue;
|
|
238
235
|
}
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
|
-
const documents = new WeakMap();
|
|
243
239
|
const semanticCtx = {
|
|
244
|
-
...
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
...context,
|
|
241
|
+
languageServiceHost,
|
|
242
|
+
languageService,
|
|
243
|
+
ts,
|
|
244
|
+
uriToFileName: uri => {
|
|
245
|
+
const [_virtualCode, file] = context.documents.getVirtualCodeByUri(uri);
|
|
246
|
+
if (file) {
|
|
247
|
+
return context.env.typescript.uriToFileName(file.id);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return context.env.typescript.uriToFileName(uri);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
fileNameToUri: fileName => {
|
|
254
|
+
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
255
|
+
const file = context.language.files.get(uri);
|
|
256
|
+
if (file?.generated) {
|
|
257
|
+
const script = file.generated.languagePlugin.typescript?.getScript(file.generated.code);
|
|
258
|
+
if (script) {
|
|
259
|
+
return context.documents.getVirtualCodeUri(uri, script.code.id);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return uri;
|
|
248
263
|
},
|
|
249
264
|
getTextDocument(uri) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return context.documents.get(uri, virtualFile.languageId, virtualFile.snapshot);
|
|
265
|
+
const virtualCode = context.documents.getVirtualCodeByUri(uri)[0];
|
|
266
|
+
if (virtualCode) {
|
|
267
|
+
return context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot);
|
|
254
268
|
}
|
|
255
|
-
const sourceFile = context.language.files.
|
|
256
|
-
if (sourceFile
|
|
269
|
+
const sourceFile = context.language.files.get(uri);
|
|
270
|
+
if (sourceFile) {
|
|
257
271
|
return context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
258
272
|
}
|
|
259
273
|
},
|
|
@@ -292,7 +306,7 @@ function create(ts) {
|
|
|
292
306
|
languageService.dispose();
|
|
293
307
|
},
|
|
294
308
|
async provideCompletionItems(document, position, completeContext, token) {
|
|
295
|
-
if (!(
|
|
309
|
+
if (!isSemanticDocument(document))
|
|
296
310
|
return;
|
|
297
311
|
const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.enabled') ?? true;
|
|
298
312
|
if (!enable) {
|
|
@@ -334,21 +348,21 @@ function create(ts) {
|
|
|
334
348
|
});
|
|
335
349
|
},
|
|
336
350
|
provideRenameRange(document, position, token) {
|
|
337
|
-
if (!(
|
|
351
|
+
if (!isSemanticDocument(document))
|
|
338
352
|
return;
|
|
339
353
|
return worker(token, () => {
|
|
340
354
|
return doPrepareRename(document.uri, position);
|
|
341
355
|
});
|
|
342
356
|
},
|
|
343
357
|
provideRenameEdits(document, position, newName, token) {
|
|
344
|
-
if (!(
|
|
358
|
+
if (!isSemanticDocument(document, true))
|
|
345
359
|
return;
|
|
346
360
|
return worker(token, () => {
|
|
347
361
|
return doRename(document.uri, position, newName);
|
|
348
362
|
});
|
|
349
363
|
},
|
|
350
364
|
provideCodeActions(document, range, context, token) {
|
|
351
|
-
if (!(
|
|
365
|
+
if (!isSemanticDocument(document))
|
|
352
366
|
return;
|
|
353
367
|
return worker(token, () => {
|
|
354
368
|
return getCodeActions(document.uri, range, context);
|
|
@@ -360,14 +374,14 @@ function create(ts) {
|
|
|
360
374
|
});
|
|
361
375
|
},
|
|
362
376
|
provideInlayHints(document, range, token) {
|
|
363
|
-
if (!(
|
|
377
|
+
if (!isSemanticDocument(document))
|
|
364
378
|
return;
|
|
365
379
|
return worker(token, () => {
|
|
366
380
|
return getInlayHints(document.uri, range);
|
|
367
381
|
});
|
|
368
382
|
},
|
|
369
383
|
provideCallHierarchyItems(document, position, token) {
|
|
370
|
-
if (!(
|
|
384
|
+
if (!isSemanticDocument(document))
|
|
371
385
|
return;
|
|
372
386
|
return worker(token, () => {
|
|
373
387
|
return callHierarchy.doPrepare(document.uri, position);
|
|
@@ -384,21 +398,21 @@ function create(ts) {
|
|
|
384
398
|
});
|
|
385
399
|
},
|
|
386
400
|
provideDefinition(document, position, token) {
|
|
387
|
-
if (!(
|
|
401
|
+
if (!isSemanticDocument(document))
|
|
388
402
|
return;
|
|
389
403
|
return worker(token, () => {
|
|
390
404
|
return findDefinition(document.uri, position);
|
|
391
405
|
});
|
|
392
406
|
},
|
|
393
407
|
provideTypeDefinition(document, position, token) {
|
|
394
|
-
if (!(
|
|
408
|
+
if (!isSemanticDocument(document))
|
|
395
409
|
return;
|
|
396
410
|
return worker(token, () => {
|
|
397
411
|
return findTypeDefinition(document.uri, position);
|
|
398
412
|
});
|
|
399
413
|
},
|
|
400
414
|
async provideDiagnostics(document, token) {
|
|
401
|
-
if (!(
|
|
415
|
+
if (!isSemanticDocument(document))
|
|
402
416
|
return;
|
|
403
417
|
const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.validate.enable') ?? true;
|
|
404
418
|
if (!enable) {
|
|
@@ -409,49 +423,49 @@ function create(ts) {
|
|
|
409
423
|
});
|
|
410
424
|
},
|
|
411
425
|
provideSemanticDiagnostics(document, token) {
|
|
412
|
-
if (!(
|
|
426
|
+
if (!isSemanticDocument(document))
|
|
413
427
|
return;
|
|
414
428
|
return worker(token, () => {
|
|
415
429
|
return doValidation(document.uri, { semantic: true, declaration: true });
|
|
416
430
|
});
|
|
417
431
|
},
|
|
418
432
|
provideHover(document, position, token) {
|
|
419
|
-
if (!(
|
|
433
|
+
if (!isSemanticDocument(document))
|
|
420
434
|
return;
|
|
421
435
|
return worker(token, () => {
|
|
422
436
|
return doHover(document.uri, position);
|
|
423
437
|
});
|
|
424
438
|
},
|
|
425
439
|
provideImplementation(document, position, token) {
|
|
426
|
-
if (!(
|
|
440
|
+
if (!isSemanticDocument(document))
|
|
427
441
|
return;
|
|
428
442
|
return worker(token, () => {
|
|
429
443
|
return findImplementations(document.uri, position);
|
|
430
444
|
});
|
|
431
445
|
},
|
|
432
446
|
provideReferences(document, position, referenceContext, token) {
|
|
433
|
-
if (!(
|
|
447
|
+
if (!isSemanticDocument(document, true))
|
|
434
448
|
return;
|
|
435
449
|
return worker(token, () => {
|
|
436
450
|
return findReferences(document.uri, position, referenceContext);
|
|
437
451
|
});
|
|
438
452
|
},
|
|
439
453
|
provideFileReferences(document, token) {
|
|
440
|
-
if (!(
|
|
454
|
+
if (!isSemanticDocument(document, true))
|
|
441
455
|
return;
|
|
442
456
|
return worker(token, () => {
|
|
443
457
|
return findFileReferences(document.uri);
|
|
444
458
|
});
|
|
445
459
|
},
|
|
446
460
|
provideDocumentHighlights(document, position, token) {
|
|
447
|
-
if (!(
|
|
461
|
+
if (!isSemanticDocument(document))
|
|
448
462
|
return;
|
|
449
463
|
return worker(token, () => {
|
|
450
464
|
return findDocumentHighlights(document.uri, position);
|
|
451
465
|
});
|
|
452
466
|
},
|
|
453
467
|
provideDocumentSemanticTokens(document, range, legend, token) {
|
|
454
|
-
if (!(
|
|
468
|
+
if (!isSemanticDocument(document))
|
|
455
469
|
return;
|
|
456
470
|
return worker(token, () => {
|
|
457
471
|
return getDocumentSemanticTokens(document.uri, range, legend);
|
|
@@ -468,39 +482,52 @@ function create(ts) {
|
|
|
468
482
|
});
|
|
469
483
|
},
|
|
470
484
|
provideSelectionRanges(document, positions, token) {
|
|
471
|
-
if (!(
|
|
485
|
+
if (!isSemanticDocument(document))
|
|
472
486
|
return;
|
|
473
487
|
return worker(token, () => {
|
|
474
488
|
return getSelectionRanges(document.uri, positions);
|
|
475
489
|
});
|
|
476
490
|
},
|
|
477
491
|
provideSignatureHelp(document, position, context, token) {
|
|
478
|
-
if (!(
|
|
492
|
+
if (!isSemanticDocument(document))
|
|
479
493
|
return;
|
|
480
494
|
return worker(token, () => {
|
|
481
495
|
return getSignatureHelp(document.uri, position, context);
|
|
482
496
|
});
|
|
483
497
|
},
|
|
484
498
|
};
|
|
499
|
+
function isSemanticDocument(document, withJson = false) {
|
|
500
|
+
const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(document.uri);
|
|
501
|
+
if (virtualCode) {
|
|
502
|
+
return sourceFile.generated?.languagePlugin.typescript?.getScript(sourceFile.generated.code)?.code === virtualCode;
|
|
503
|
+
}
|
|
504
|
+
else if (withJson) {
|
|
505
|
+
return (0, shared_1.isTsDocument)(document) || (0, shared_1.isJsonDocument)(document);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
return (0, shared_1.isTsDocument)(document);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
485
511
|
async function worker(token, callback) {
|
|
486
|
-
let oldSysVersion = await
|
|
512
|
+
let oldSysVersion = await sys.sync?.();
|
|
487
513
|
let result = await callback();
|
|
488
|
-
let newSysVersion = await
|
|
514
|
+
let newSysVersion = await sys.sync?.();
|
|
489
515
|
while (newSysVersion !== oldSysVersion && !token.isCancellationRequested) {
|
|
490
516
|
oldSysVersion = newSysVersion;
|
|
491
517
|
result = await callback();
|
|
492
|
-
newSysVersion = await
|
|
518
|
+
newSysVersion = await sys.sync?.();
|
|
493
519
|
}
|
|
494
520
|
return result;
|
|
495
521
|
}
|
|
496
522
|
function prepareSyntacticService(document) {
|
|
497
|
-
if (syntacticHostCtx.document
|
|
498
|
-
|
|
523
|
+
if (syntacticHostCtx.document !== document || syntacticHostCtx.fileVersion !== document.version) {
|
|
524
|
+
syntacticHostCtx.document = document;
|
|
525
|
+
syntacticHostCtx.fileName = vscode_uri_1.URI.parse(document.uri).fsPath.replace(/\\/g, '/');
|
|
526
|
+
syntacticHostCtx.fileVersion = document.version;
|
|
527
|
+
syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
528
|
+
syntacticHostCtx.projectVersion++;
|
|
499
529
|
}
|
|
500
|
-
syntacticHostCtx
|
|
501
|
-
syntacticHostCtx.fileVersion = document.version;
|
|
502
|
-
syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
503
|
-
syntacticHostCtx.projectVersion++;
|
|
530
|
+
return syntacticHostCtx;
|
|
504
531
|
}
|
|
505
532
|
},
|
|
506
533
|
};
|
|
@@ -22,7 +22,7 @@ async function getUserPreferences(ctx, document) {
|
|
|
22
22
|
includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
|
|
23
23
|
includeCompletionsWithClassMemberSnippets: config.suggest?.classMemberSnippets?.enabled ?? true,
|
|
24
24
|
includeCompletionsWithObjectLiteralMethodSnippets: config.suggest?.objectLiteralMethodSnippets?.enabled ?? true,
|
|
25
|
-
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.
|
|
25
|
+
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.languageServiceHost.getCurrentDirectory()),
|
|
26
26
|
useLabelDetailsInCompletionEntries: true,
|
|
27
27
|
allowIncompleteCompletions: true,
|
|
28
28
|
displayPartsForJSDoc: true,
|
|
@@ -11,9 +11,9 @@ function register(ctx) {
|
|
|
11
11
|
const document = ctx.getTextDocument(uri);
|
|
12
12
|
if (!document)
|
|
13
13
|
return [];
|
|
14
|
-
const fileName = ctx.
|
|
14
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
15
15
|
const offset = document.offsetAt(position);
|
|
16
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.prepareCallHierarchy(fileName, offset));
|
|
17
17
|
if (!calls)
|
|
18
18
|
return [];
|
|
19
19
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -23,9 +23,9 @@ function register(ctx) {
|
|
|
23
23
|
const document = ctx.getTextDocument(item.uri);
|
|
24
24
|
if (!document)
|
|
25
25
|
return [];
|
|
26
|
-
const fileName = ctx.
|
|
26
|
+
const fileName = ctx.uriToFileName(item.uri);
|
|
27
27
|
const offset = document.offsetAt(item.selectionRange.start);
|
|
28
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
28
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
|
|
29
29
|
if (!calls)
|
|
30
30
|
return [];
|
|
31
31
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -35,9 +35,9 @@ function register(ctx) {
|
|
|
35
35
|
const document = ctx.getTextDocument(item.uri);
|
|
36
36
|
if (!document)
|
|
37
37
|
return [];
|
|
38
|
-
const fileName = ctx.
|
|
38
|
+
const fileName = ctx.uriToFileName(item.uri);
|
|
39
39
|
const offset = document.offsetAt(item.selectionRange.start);
|
|
40
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
40
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
|
|
41
41
|
if (!calls)
|
|
42
42
|
return [];
|
|
43
43
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -52,8 +52,8 @@ function register(ctx) {
|
|
|
52
52
|
return item.kind === PConst.Kind.script || item.kind === PConst.Kind.module && item.selectionSpan.start === 0;
|
|
53
53
|
}
|
|
54
54
|
function fromProtocolCallHierarchyItem(item) {
|
|
55
|
-
const rootPath = ctx.
|
|
56
|
-
const document = ctx.getTextDocument(ctx.
|
|
55
|
+
const rootPath = ctx.languageService.getProgram()?.getCompilerOptions().rootDir ?? '';
|
|
56
|
+
const document = ctx.getTextDocument(ctx.fileNameToUri(item.file)); // TODO
|
|
57
57
|
const useFileName = isSourceFileItem(item);
|
|
58
58
|
const name = useFileName ? path.basename(item.file) : item.name;
|
|
59
59
|
const detail = useFileName ? path.relative(rootPath, path.dirname(item.file)) : item.containerName ?? '';
|
|
@@ -61,7 +61,7 @@ function register(ctx) {
|
|
|
61
61
|
kind: typeConverters.SymbolKind.fromProtocolScriptElementKind(item.kind),
|
|
62
62
|
name,
|
|
63
63
|
detail,
|
|
64
|
-
uri: ctx.
|
|
64
|
+
uri: ctx.fileNameToUri(item.file),
|
|
65
65
|
range: {
|
|
66
66
|
start: document.positionAt(item.span.start),
|
|
67
67
|
end: document.positionAt(item.span.start + item.span.length),
|
|
@@ -78,7 +78,7 @@ function register(ctx) {
|
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
80
|
function fromProtocolCallHierarchyIncomingCall(item) {
|
|
81
|
-
const document = ctx.getTextDocument(ctx.
|
|
81
|
+
const document = ctx.getTextDocument(ctx.fileNameToUri(item.from.file));
|
|
82
82
|
return {
|
|
83
83
|
from: fromProtocolCallHierarchyItem(item.from),
|
|
84
84
|
fromRanges: item.fromSpans.map(fromSpan => ({
|
|
@@ -22,14 +22,14 @@ function register(ctx) {
|
|
|
22
22
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
23
23
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
24
24
|
]);
|
|
25
|
-
const fileName = ctx.
|
|
25
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
26
26
|
const start = document.offsetAt(range.start);
|
|
27
27
|
const end = document.offsetAt(range.end);
|
|
28
28
|
let result = [];
|
|
29
29
|
const onlyQuickFix = matchOnlyKind(`${'quickfix'}.ts`);
|
|
30
30
|
if (!context.only || onlyQuickFix) {
|
|
31
31
|
for (const error of context.diagnostics) {
|
|
32
|
-
const codeFixes = (0, shared_1.safeCall)(() => ctx.
|
|
32
|
+
const codeFixes = (0, shared_1.safeCall)(() => ctx.languageService.getCodeFixesAtPosition(fileName, document.offsetAt(error.range.start), document.offsetAt(error.range.end), [Number(error.code)], formatOptions, preferences)) ?? [];
|
|
33
33
|
for (const codeFix of codeFixes) {
|
|
34
34
|
result = result.concat(transformCodeFix(codeFix, [error], onlyQuickFix ?? ''));
|
|
35
35
|
}
|
|
@@ -38,7 +38,7 @@ function register(ctx) {
|
|
|
38
38
|
if (context.only) {
|
|
39
39
|
for (const only of context.only) {
|
|
40
40
|
if (only.split('.')[0] === 'refactor') {
|
|
41
|
-
const refactors = (0, shared_1.safeCall)(() => ctx.
|
|
41
|
+
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, only)) ?? [];
|
|
42
42
|
for (const refactor of refactors) {
|
|
43
43
|
result = result.concat(transformRefactor(refactor));
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ function register(ctx) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
const refactors = (0, shared_1.safeCall)(() => ctx.
|
|
49
|
+
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, undefined)) ?? [];
|
|
50
50
|
for (const refactor of refactors) {
|
|
51
51
|
result = result.concat(transformRefactor(refactor));
|
|
52
52
|
}
|
|
@@ -27,13 +27,13 @@ function register(ctx) {
|
|
|
27
27
|
}
|
|
28
28
|
exports.register = register;
|
|
29
29
|
function resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
30
|
-
const fixes = data.fixIds.map(fixId => (0, shared_1.safeCall)(() => ctx.
|
|
30
|
+
const fixes = data.fixIds.map(fixId => (0, shared_1.safeCall)(() => ctx.languageService.getCombinedCodeFix({ type: 'file', fileName: data.fileName }, fixId, formatOptions, preferences)));
|
|
31
31
|
const changes = fixes.map(fix => fix?.changes ?? []).flat();
|
|
32
32
|
codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes, ctx);
|
|
33
33
|
}
|
|
34
34
|
exports.resolveFixAllCodeAction = resolveFixAllCodeAction;
|
|
35
35
|
function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences) {
|
|
36
|
-
const editInfo = (0, shared_1.safeCall)(() => ctx.
|
|
36
|
+
const editInfo = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForRefactor(data.fileName, formatOptions, data.range, data.refactorName, data.actionName, preferences));
|
|
37
37
|
if (!editInfo) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -44,7 +44,7 @@ function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOption
|
|
|
44
44
|
}
|
|
45
45
|
exports.resolveRefactorCodeAction = resolveRefactorCodeAction;
|
|
46
46
|
function resolveOrganizeImportsCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
47
|
-
const changes = (0, shared_1.safeCall)(() => ctx.
|
|
47
|
+
const changes = (0, shared_1.safeCall)(() => ctx.languageService.organizeImports({ type: 'file', fileName: data.fileName }, formatOptions, preferences));
|
|
48
48
|
codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes ?? [], ctx);
|
|
49
49
|
}
|
|
50
50
|
exports.resolveOrganizeImportsCodeAction = resolveOrganizeImportsCodeAction;
|
|
@@ -15,9 +15,9 @@ function register(ctx) {
|
|
|
15
15
|
if (!document)
|
|
16
16
|
return;
|
|
17
17
|
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
18
|
-
const fileName = ctx.
|
|
18
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
19
19
|
const offset = document.offsetAt(position);
|
|
20
|
-
const completionContext = (0, shared_1.safeCall)(() => ctx.
|
|
20
|
+
const completionContext = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionsAtPosition(fileName, offset, {
|
|
21
21
|
...preferences,
|
|
22
22
|
...options,
|
|
23
23
|
}));
|
|
@@ -12,9 +12,9 @@ function register(ctx) {
|
|
|
12
12
|
return;
|
|
13
13
|
if (!isPotentiallyValidDocCompletionPosition(document, position))
|
|
14
14
|
return;
|
|
15
|
-
const fileName = ctx.
|
|
15
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
16
16
|
const offset = document.offsetAt(position);
|
|
17
|
-
const docCommentTemplate = ctx.
|
|
17
|
+
const docCommentTemplate = ctx.languageService.getDocCommentTemplateAtPosition(fileName, offset);
|
|
18
18
|
if (!docCommentTemplate)
|
|
19
19
|
return;
|
|
20
20
|
let insertText;
|
|
@@ -26,7 +26,7 @@ function register(ctx) {
|
|
|
26
26
|
]) : [{}, {}];
|
|
27
27
|
let details;
|
|
28
28
|
try {
|
|
29
|
-
details = ctx.
|
|
29
|
+
details = ctx.languageService.getCompletionEntryDetails(fileName, offset, data.originalItem.name, formatOptions, data.originalItem.source, preferences, data.originalItem.data);
|
|
30
30
|
}
|
|
31
31
|
catch (err) {
|
|
32
32
|
item.detail = `[TS Error]\n${err}\n${JSON.stringify(err, undefined, 2)}`;
|
|
@@ -76,7 +76,7 @@ function register(ctx) {
|
|
|
76
76
|
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls') ?? false;
|
|
77
77
|
const useCodeSnippet = useCodeSnippetsOnMethodSuggest && (item.kind === 3 || item.kind === 2);
|
|
78
78
|
if (useCodeSnippet) {
|
|
79
|
-
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.
|
|
79
|
+
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.languageService, fileName, offset, document);
|
|
80
80
|
if (shouldCompleteFunction) {
|
|
81
81
|
const { snippet, parameterCount } = (0, snippetForFunctionCall_1.snippetForFunctionCall)({
|
|
82
82
|
insertText: item.insertText ?? item.textEdit?.newText, // insertText is dropped by LSP in some case: https://github.com/microsoft/vscode-languageserver-node/blob/9b742021fb04ad081aa3676a9eecf4fa612084b4/client/src/common/codeConverter.ts#L659-L664
|
|
@@ -104,7 +104,7 @@ function register(ctx) {
|
|
|
104
104
|
}
|
|
105
105
|
return item;
|
|
106
106
|
function toResource(path) {
|
|
107
|
-
return ctx.
|
|
107
|
+
return ctx.fileNameToUri(path);
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
}
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const info = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getDefinitionAndBoundSpan(fileName, offset));
|
|
14
14
|
if (!info)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.boundSpanToLocationLinks)(info, document, ctx);
|
|
@@ -8,21 +8,21 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const program = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const program = ctx.languageService.getProgram();
|
|
13
13
|
const sourceFile = program?.getSourceFile(fileName);
|
|
14
14
|
if (!program || !sourceFile)
|
|
15
15
|
return [];
|
|
16
16
|
const token = {
|
|
17
17
|
isCancellationRequested() {
|
|
18
|
-
return ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false;
|
|
18
|
+
return ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false;
|
|
19
19
|
},
|
|
20
20
|
throwIfCancellationRequested() { },
|
|
21
21
|
};
|
|
22
22
|
let errors = (0, shared_1.safeCall)(() => [
|
|
23
23
|
...options.semantic ? program.getSemanticDiagnostics(sourceFile, token) : [],
|
|
24
24
|
...options.syntactic ? program.getSyntacticDiagnostics(sourceFile, token) : [],
|
|
25
|
-
...options.suggestion ? ctx.
|
|
25
|
+
...options.suggestion ? ctx.languageService.getSuggestionDiagnostics(fileName) : [],
|
|
26
26
|
]) ?? [];
|
|
27
27
|
if (options.declaration && getEmitDeclarations(program.getCompilerOptions())) {
|
|
28
28
|
errors = errors.concat(program.getDeclarationDiagnostics(sourceFile, token));
|
|
@@ -70,7 +70,7 @@ function register(ctx) {
|
|
|
70
70
|
return;
|
|
71
71
|
let document;
|
|
72
72
|
if (diag.file) {
|
|
73
|
-
document = ctx.getTextDocument(ctx.
|
|
73
|
+
document = ctx.getTextDocument(ctx.fileNameToUri(diag.file.fileName));
|
|
74
74
|
}
|
|
75
75
|
if (!document)
|
|
76
76
|
return;
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const highlights = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const highlights = (0, shared_1.safeCall)(() => ctx.languageService.getDocumentHighlights(fileName, offset, [fileName]));
|
|
14
14
|
if (!highlights)
|
|
15
15
|
return [];
|
|
16
16
|
const results = [];
|
|
@@ -29,8 +29,8 @@ function register(ctx) {
|
|
|
29
29
|
const document = ctx.getTextDocument(uri);
|
|
30
30
|
if (!document)
|
|
31
31
|
return [];
|
|
32
|
-
const fileName = ctx.
|
|
33
|
-
const barItems = (0, shared_1.safeCall)(() => ctx.
|
|
32
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
33
|
+
const barItems = (0, shared_1.safeCall)(() => ctx.languageService.getNavigationTree(fileName));
|
|
34
34
|
if (!barItems)
|
|
35
35
|
return [];
|
|
36
36
|
// The root represents the file. Ignore this when showing in the UI
|
|
@@ -8,8 +8,8 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getFileReferences(fileName));
|
|
13
13
|
if (!entries)
|
|
14
14
|
return [];
|
|
15
15
|
return (0, transforms_1.entriesToLocations)([...entries], ctx);
|
|
@@ -12,9 +12,9 @@ function register(ctx) {
|
|
|
12
12
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
13
13
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
14
14
|
]) : [{}, {}];
|
|
15
|
-
const fileToRename = ctx.
|
|
16
|
-
const newFilePath = ctx.
|
|
17
|
-
const response = (0, shared_1.safeCall)(() => ctx.
|
|
15
|
+
const fileToRename = ctx.uriToFileName(oldUri);
|
|
16
|
+
const newFilePath = ctx.uriToFileName(newUri);
|
|
17
|
+
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
|
|
18
18
|
if (!response?.length)
|
|
19
19
|
return;
|
|
20
20
|
const edits = (0, rename_1.fileTextChangesToWorkspaceEdit)(response, ctx);
|
|
@@ -8,8 +8,8 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const outliningSpans = (0, shared_1.safeCall)(() => ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const outliningSpans = (0, shared_1.safeCall)(() => ctx.languageService.getOutliningSpans(fileName));
|
|
13
13
|
if (!outliningSpans)
|
|
14
14
|
return [];
|
|
15
15
|
const foldingRanges = [];
|
|
@@ -6,14 +6,14 @@ const shared_1 = require("../shared");
|
|
|
6
6
|
function register(ctx) {
|
|
7
7
|
return {
|
|
8
8
|
onRange: async (document, range, options) => {
|
|
9
|
-
const fileName = ctx.
|
|
9
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
10
10
|
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
11
11
|
if (typeof (tsOptions.indentSize) === "boolean" || typeof (tsOptions.indentSize) === "string") {
|
|
12
12
|
tsOptions.indentSize = undefined;
|
|
13
13
|
}
|
|
14
14
|
const scriptEdits = range
|
|
15
|
-
? (0, shared_1.safeCall)(() => ctx.
|
|
16
|
-
: (0, shared_1.safeCall)(() => ctx.
|
|
15
|
+
? (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsForRange(fileName, document.offsetAt(range.start), document.offsetAt(range.end), tsOptions))
|
|
16
|
+
: (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsForDocument(fileName, tsOptions));
|
|
17
17
|
if (!scriptEdits)
|
|
18
18
|
return [];
|
|
19
19
|
const result = [];
|
|
@@ -29,9 +29,9 @@ function register(ctx) {
|
|
|
29
29
|
return result;
|
|
30
30
|
},
|
|
31
31
|
onType: async (document, options, position, key) => {
|
|
32
|
-
const fileName = ctx.
|
|
32
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
33
33
|
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
34
|
-
const scriptEdits = (0, shared_1.safeCall)(() => ctx.
|
|
34
|
+
const scriptEdits = (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsAfterKeystroke(fileName, document.offsetAt(position), key, tsOptions));
|
|
35
35
|
if (!scriptEdits)
|
|
36
36
|
return [];
|
|
37
37
|
const result = [];
|
package/lib/features/hover.js
CHANGED
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
const document = ctx.getTextDocument(uri);
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const info = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getQuickInfoAtPosition(fileName, offset));
|
|
15
15
|
if (!info)
|
|
16
16
|
return;
|
|
17
17
|
const parts = [];
|
|
@@ -35,7 +35,7 @@ function register(ctx) {
|
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
37
|
function toResource(path) {
|
|
38
|
-
return ctx.
|
|
38
|
+
return ctx.fileNameToUri(path);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getImplementationAtPosition(fileName, offset));
|
|
14
14
|
if (!entries)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.entriesToLocationLinks)([...entries], ctx);
|
|
@@ -10,11 +10,11 @@ function register(ctx) {
|
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
12
|
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
13
|
-
const fileName = ctx.
|
|
13
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
14
14
|
const start = document.offsetAt(range.start);
|
|
15
15
|
const end = document.offsetAt(range.end);
|
|
16
|
-
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.
|
|
17
|
-
? ctx.
|
|
16
|
+
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.languageService
|
|
17
|
+
? ctx.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
|
|
18
18
|
: []) ?? [];
|
|
19
19
|
return inlayHints.map(inlayHint => {
|
|
20
20
|
const result = {
|
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
const document = ctx.getTextDocument(uri);
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const renameInfo = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, exports.renameInfoOptions));
|
|
15
15
|
if (!renameInfo)
|
|
16
16
|
return;
|
|
17
17
|
if (!renameInfo.canRename) {
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const references = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const references = (0, shared_1.safeCall)(() => ctx.languageService.findReferences(fileName, offset));
|
|
14
14
|
if (!references)
|
|
15
15
|
return [];
|
|
16
16
|
const result = [];
|
package/lib/features/rename.js
CHANGED
|
@@ -11,9 +11,9 @@ function register(ctx) {
|
|
|
11
11
|
const document = ctx.getTextDocument(uri);
|
|
12
12
|
if (!document)
|
|
13
13
|
return;
|
|
14
|
-
const fileName = ctx.
|
|
14
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
15
15
|
const offset = document.offsetAt(position);
|
|
16
|
-
const renameInfo = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, prepareRename_1.renameInfoOptions));
|
|
17
17
|
if (!renameInfo?.canRename)
|
|
18
18
|
return;
|
|
19
19
|
if (renameInfo.fileToRename) {
|
|
@@ -24,7 +24,7 @@ function register(ctx) {
|
|
|
24
24
|
return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
|
|
25
25
|
}
|
|
26
26
|
const { providePrefixAndSuffixTextForRename } = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
27
|
-
const entries = ctx.
|
|
27
|
+
const entries = ctx.languageService.findRenameLocations(fileName, offset, false, false, providePrefixAndSuffixTextForRename);
|
|
28
28
|
if (!entries)
|
|
29
29
|
return;
|
|
30
30
|
const locations = locationsToWorkspaceEdit(newName, entries, ctx);
|
|
@@ -37,15 +37,15 @@ function register(ctx) {
|
|
|
37
37
|
}
|
|
38
38
|
const dirname = path.dirname(fileToRename);
|
|
39
39
|
const newFilePath = path.join(dirname, newName);
|
|
40
|
-
const response = ctx.
|
|
40
|
+
const response = ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences);
|
|
41
41
|
const edits = fileTextChangesToWorkspaceEdit(response, ctx);
|
|
42
42
|
if (!edits.documentChanges) {
|
|
43
43
|
edits.documentChanges = [];
|
|
44
44
|
}
|
|
45
45
|
edits.documentChanges.push({
|
|
46
46
|
kind: 'rename',
|
|
47
|
-
oldUri: ctx.
|
|
48
|
-
newUri: ctx.
|
|
47
|
+
oldUri: ctx.fileNameToUri(fileToRename),
|
|
48
|
+
newUri: ctx.fileNameToUri(newFilePath),
|
|
49
49
|
});
|
|
50
50
|
return edits;
|
|
51
51
|
}
|
|
@@ -57,7 +57,7 @@ function fileTextChangesToWorkspaceEdit(changes, ctx) {
|
|
|
57
57
|
if (!workspaceEdit.documentChanges) {
|
|
58
58
|
workspaceEdit.documentChanges = [];
|
|
59
59
|
}
|
|
60
|
-
const uri = ctx.
|
|
60
|
+
const uri = ctx.fileNameToUri(change.fileName);
|
|
61
61
|
let doc = ctx.getTextDocument(uri);
|
|
62
62
|
if (change.isNewFile) {
|
|
63
63
|
workspaceEdit.documentChanges.push({ kind: 'create', uri });
|
|
@@ -91,7 +91,7 @@ function locationsToWorkspaceEdit(newText, locations, ctx) {
|
|
|
91
91
|
if (!workspaceEdit.changes) {
|
|
92
92
|
workspaceEdit.changes = {};
|
|
93
93
|
}
|
|
94
|
-
const uri = ctx.
|
|
94
|
+
const uri = ctx.fileNameToUri(location.fileName);
|
|
95
95
|
const doc = ctx.getTextDocument(uri);
|
|
96
96
|
if (!doc)
|
|
97
97
|
continue;
|
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
return [];
|
|
10
10
|
const result = [];
|
|
11
11
|
for (const position of positions) {
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const range = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const range = (0, shared_1.safeCall)(() => ctx.languageService.getSmartSelectionRange(fileName, offset));
|
|
15
15
|
if (!range)
|
|
16
16
|
continue;
|
|
17
17
|
result.push(transformSelectionRange(range, document));
|
|
@@ -8,17 +8,17 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return;
|
|
11
|
-
const file = ctx.
|
|
11
|
+
const file = ctx.uriToFileName(uri);
|
|
12
12
|
const start = range ? document.offsetAt(range.start) : 0;
|
|
13
13
|
const length = range ? (document.offsetAt(range.end) - start) : document.getText().length;
|
|
14
|
-
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
14
|
+
if (ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
15
15
|
return;
|
|
16
|
-
const response2 = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const response2 = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSyntacticClassifications(file, { start, length }));
|
|
17
17
|
if (!response2)
|
|
18
18
|
return;
|
|
19
|
-
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
19
|
+
if (ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
20
20
|
return;
|
|
21
|
-
const response1 = (0, shared_1.safeCall)(() => ctx.
|
|
21
|
+
const response1 = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSemanticClassifications(file, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty));
|
|
22
22
|
if (!response1)
|
|
23
23
|
return;
|
|
24
24
|
let tokenModifiersTable = [];
|
|
@@ -26,9 +26,9 @@ function register(ctx) {
|
|
|
26
26
|
triggerCharacter: context.triggerCharacter,
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
const fileName = ctx.
|
|
29
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
30
30
|
const offset = document.offsetAt(position);
|
|
31
|
-
const helpItems = (0, shared_1.safeCall)(() => ctx.
|
|
31
|
+
const helpItems = (0, shared_1.safeCall)(() => ctx.languageService.getSignatureHelpItems(fileName, offset, options));
|
|
32
32
|
if (!helpItems)
|
|
33
33
|
return;
|
|
34
34
|
return {
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getTypeDefinitionAtPosition(fileName, offset));
|
|
14
14
|
if (!entries)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.entriesToLocationLinks)([...entries], ctx);
|
|
@@ -22,7 +22,7 @@ function getSymbolKind(item) {
|
|
|
22
22
|
}
|
|
23
23
|
function register(ctx) {
|
|
24
24
|
return (query) => {
|
|
25
|
-
const items = (0, shared_1.safeCall)(() => ctx.
|
|
25
|
+
const items = (0, shared_1.safeCall)(() => ctx.languageService.getNavigateToItems(query));
|
|
26
26
|
if (!items)
|
|
27
27
|
return [];
|
|
28
28
|
return items
|
|
@@ -31,7 +31,7 @@ function register(ctx) {
|
|
|
31
31
|
.filter((v) => !!v);
|
|
32
32
|
function toWorkspaceSymbol(item) {
|
|
33
33
|
const label = getLabel(item);
|
|
34
|
-
const uri = ctx.
|
|
34
|
+
const uri = ctx.fileNameToUri(item.fileName);
|
|
35
35
|
const document = ctx.getTextDocument(uri);
|
|
36
36
|
if (document) {
|
|
37
37
|
const range = {
|
package/lib/types.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { ServiceContext } from '@volar/language-service';
|
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export type SharedContext = ServiceContext & {
|
|
5
|
-
typescript: {
|
|
6
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
-
languageService: ts.LanguageService;
|
|
8
|
-
};
|
|
9
5
|
ts: typeof import('typescript');
|
|
6
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
+
languageService: ts.LanguageService;
|
|
10
8
|
getTextDocument: (uri: string) => TextDocument | undefined;
|
|
9
|
+
uriToFileName: (uri: string) => string;
|
|
10
|
+
fileNameToUri: (fileName: string) => string;
|
|
11
11
|
};
|
|
12
12
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/utils/previewer.js
CHANGED
|
@@ -105,7 +105,7 @@ function convertLinkTags(parts, filePathConverter, ctx) {
|
|
|
105
105
|
let target = currentLink.target;
|
|
106
106
|
if (typeof currentLink.target === 'object' && 'fileName' in currentLink.target) {
|
|
107
107
|
const _target = currentLink.target;
|
|
108
|
-
const fileDoc = ctx.getTextDocument(ctx.
|
|
108
|
+
const fileDoc = ctx.getTextDocument(ctx.uriToFileName(_target.fileName));
|
|
109
109
|
if (fileDoc) {
|
|
110
110
|
const start = fileDoc.positionAt(_target.textSpan.start);
|
|
111
111
|
const end = fileDoc.positionAt(_target.textSpan.start + _target.textSpan.length);
|
package/lib/utils/transforms.js
CHANGED
|
@@ -8,7 +8,7 @@ function entriesToLocations(entries, ctx) {
|
|
|
8
8
|
}
|
|
9
9
|
exports.entriesToLocations = entriesToLocations;
|
|
10
10
|
function entryToLocation(entry, ctx) {
|
|
11
|
-
const entryUri = ctx.
|
|
11
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
12
12
|
const doc = ctx.getTextDocument(entryUri);
|
|
13
13
|
if (!doc)
|
|
14
14
|
return;
|
|
@@ -23,7 +23,7 @@ exports.entryToLocation = entryToLocation;
|
|
|
23
23
|
function entriesToLocationLinks(entries, ctx) {
|
|
24
24
|
const locations = [];
|
|
25
25
|
for (const entry of entries) {
|
|
26
|
-
const entryUri = ctx.
|
|
26
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
27
27
|
const doc = ctx.getTextDocument(entryUri);
|
|
28
28
|
if (!doc)
|
|
29
29
|
continue;
|
|
@@ -59,7 +59,7 @@ function boundSpanToLocationLinks(info, originalDoc, ctx) {
|
|
|
59
59
|
end: originalDoc.positionAt(info.textSpan.start + info.textSpan.length),
|
|
60
60
|
};
|
|
61
61
|
for (const entry of info.definitions) {
|
|
62
|
-
const entryUri = ctx.
|
|
62
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
63
63
|
const doc = ctx.getTextDocument(entryUri);
|
|
64
64
|
if (!doc)
|
|
65
65
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27-patch.1",
|
|
4
4
|
"description": "Integrate TypeScript into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -37,13 +37,12 @@
|
|
|
37
37
|
"vscode-uri": "^3.0.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@volar/language-service": "
|
|
41
|
-
"@volar/typescript": "
|
|
40
|
+
"@volar/language-service": "~2.0.0",
|
|
41
|
+
"@volar/typescript": "~2.0.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
44
|
"@volar/language-service": {
|
|
45
45
|
"optional": true
|
|
46
46
|
}
|
|
47
|
-
}
|
|
48
|
-
"gitHead": "d8838f4288d4836a8829a458855f557d58732963"
|
|
47
|
+
}
|
|
49
48
|
}
|
package/lib/protocol.d.ts
DELETED
package/lib/protocol.js
DELETED