volar-service-typescript 0.0.31 → 0.0.32
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 +4 -17
- package/index.js +12 -546
- package/lib/configs/getFormatCodeSettings.d.ts +2 -3
- package/lib/configs/getUserPreferences.d.ts +1 -1
- package/lib/plugins/directiveComment.d.ts +3 -0
- package/lib/plugins/directiveComment.js +65 -0
- package/lib/plugins/docCommentTemplate.d.ts +3 -0
- package/lib/{features/completions/jsDoc.js → plugins/docCommentTemplate.js} +42 -30
- package/lib/plugins/semantic.d.ts +23 -0
- package/lib/plugins/semantic.js +706 -0
- package/lib/plugins/syntactic.d.ts +7 -0
- package/lib/plugins/syntactic.js +92 -0
- package/lib/{features → semanticFeatures}/codeAction.d.ts +3 -2
- package/lib/{features → semanticFeatures}/codeAction.js +14 -17
- package/lib/{features → semanticFeatures}/codeActionResolve.d.ts +1 -1
- package/lib/{features → semanticFeatures}/codeActionResolve.js +7 -7
- package/lib/semanticFeatures/semanticTokens.d.ts +5 -0
- package/lib/{features → semanticFeatures}/semanticTokens.js +4 -8
- package/lib/{types.d.ts → semanticFeatures/types.d.ts} +1 -2
- package/lib/shared.d.ts +1 -0
- package/lib/shared.js +5 -1
- package/lib/syntacticLanguageService.d.ts +7 -0
- package/lib/syntacticLanguageService.js +38 -0
- package/lib/utils/lspConverters.d.ts +27 -0
- package/lib/utils/lspConverters.js +782 -0
- package/lib/utils/previewer.d.ts +5 -11
- package/lib/utils/previewer.js +30 -35
- package/package.json +4 -6
- package/lib/features/callHierarchy.d.ts +0 -8
- package/lib/features/callHierarchy.js +0 -102
- package/lib/features/completions/basic.d.ts +0 -17
- package/lib/features/completions/basic.js +0 -326
- package/lib/features/completions/directiveComment.d.ts +0 -4
- package/lib/features/completions/directiveComment.js +0 -54
- package/lib/features/completions/jsDoc.d.ts +0 -4
- package/lib/features/completions/resolve.d.ts +0 -6
- package/lib/features/completions/resolve.js +0 -146
- package/lib/features/definition.d.ts +0 -4
- package/lib/features/definition.js +0 -20
- package/lib/features/diagnostics.d.ts +0 -11
- package/lib/features/diagnostics.js +0 -120
- package/lib/features/documentHighlight.d.ts +0 -4
- package/lib/features/documentHighlight.js +0 -32
- package/lib/features/documentSymbol.d.ts +0 -4
- package/lib/features/documentSymbol.js +0 -94
- package/lib/features/fileReferences.d.ts +0 -4
- package/lib/features/fileReferences.js +0 -19
- package/lib/features/fileRename.d.ts +0 -4
- package/lib/features/fileRename.js +0 -25
- package/lib/features/foldingRanges.d.ts +0 -4
- package/lib/features/foldingRanges.js +0 -55
- package/lib/features/formatting.d.ts +0 -8
- package/lib/features/formatting.js +0 -55
- package/lib/features/hover.d.ts +0 -4
- package/lib/features/hover.js +0 -43
- package/lib/features/implementation.d.ts +0 -4
- package/lib/features/implementation.js +0 -20
- package/lib/features/inlayHints.d.ts +0 -4
- package/lib/features/inlayHints.js +0 -34
- package/lib/features/prepareRename.d.ts +0 -9
- package/lib/features/prepareRename.js +0 -27
- package/lib/features/references.d.ts +0 -4
- package/lib/features/references.js +0 -35
- package/lib/features/rename.d.ts +0 -6
- package/lib/features/rename.js +0 -116
- package/lib/features/selectionRanges.d.ts +0 -4
- package/lib/features/selectionRanges.js +0 -32
- package/lib/features/semanticTokens.d.ts +0 -4
- package/lib/features/signatureHelp.d.ts +0 -4
- package/lib/features/signatureHelp.js +0 -63
- package/lib/features/typeDefinition.d.ts +0 -4
- package/lib/features/typeDefinition.js +0 -20
- package/lib/features/workspaceSymbol.d.ts +0 -4
- package/lib/features/workspaceSymbol.js +0 -63
- package/lib/utils/transforms.d.ts +0 -15
- package/lib/utils/transforms.js +0 -85
- /package/lib/{types.js → semanticFeatures/types.js} +0 -0
package/index.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export
|
|
5
|
-
export interface Provide {
|
|
6
|
-
'typescript/typescript': () => typeof import('typescript');
|
|
7
|
-
'typescript/languageService': () => ts.LanguageService;
|
|
8
|
-
'typescript/languageServiceHost': () => ts.LanguageServiceHost;
|
|
9
|
-
'typescript/syntacticLanguageService': () => ts.LanguageService;
|
|
10
|
-
'typescript/syntacticLanguageServiceHost': () => ts.LanguageServiceHost;
|
|
11
|
-
}
|
|
12
|
-
export declare function create(ts: typeof import('typescript'), { isFormattingEnabled, isValidationEnabled, isSuggestionsEnabled, isAutoClosingTagsEnabled, }?: {
|
|
13
|
-
isFormattingEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
14
|
-
isValidationEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
15
|
-
isSuggestionsEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
16
|
-
isAutoClosingTagsEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
17
|
-
}): ServicePlugin;
|
|
1
|
+
export { Provide } from './lib/plugins/semantic';
|
|
2
|
+
import { create as createSemanticServicePlugin } from './lib/plugins/semantic';
|
|
3
|
+
import { create as createSyntacticServicePlugin } from './lib/plugins/syntactic';
|
|
4
|
+
export declare function create(ts: typeof import('typescript'), options: Parameters<typeof createSemanticServicePlugin>[1] & Parameters<typeof createSyntacticServicePlugin>[1]): import("@volar/language-service").ServicePlugin[];
|
|
18
5
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,552 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.create = void 0;
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const diagnostics = require("./lib/features/diagnostics");
|
|
31
|
-
const documentHighlight = require("./lib/features/documentHighlight");
|
|
32
|
-
const documentSymbol = require("./lib/features/documentSymbol");
|
|
33
|
-
const fileReferences = require("./lib/features/fileReferences");
|
|
34
|
-
const fileRename = require("./lib/features/fileRename");
|
|
35
|
-
const foldingRanges = require("./lib/features/foldingRanges");
|
|
36
|
-
const formatting = require("./lib/features/formatting");
|
|
37
|
-
const hover = require("./lib/features/hover");
|
|
38
|
-
const implementation = require("./lib/features/implementation");
|
|
39
|
-
const inlayHints = require("./lib/features/inlayHints");
|
|
40
|
-
const prepareRename = require("./lib/features/prepareRename");
|
|
41
|
-
const references = require("./lib/features/references");
|
|
42
|
-
const rename = require("./lib/features/rename");
|
|
43
|
-
const selectionRanges = require("./lib/features/selectionRanges");
|
|
44
|
-
const semanticTokens = require("./lib/features/semanticTokens");
|
|
45
|
-
const signatureHelp = require("./lib/features/signatureHelp");
|
|
46
|
-
const typeDefinitions = require("./lib/features/typeDefinition");
|
|
47
|
-
const workspaceSymbols = require("./lib/features/workspaceSymbol");
|
|
48
|
-
__exportStar(require("@volar/typescript"), exports);
|
|
49
|
-
;
|
|
50
|
-
function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
51
|
-
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable') ?? true;
|
|
52
|
-
}, isValidationEnabled = async (document, context) => {
|
|
53
|
-
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.validate.enable') ?? true;
|
|
54
|
-
}, isSuggestionsEnabled = async (document, context) => {
|
|
55
|
-
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.enabled') ?? true;
|
|
56
|
-
}, isAutoClosingTagsEnabled = async (document, context) => {
|
|
57
|
-
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.autoClosingTags') ?? true;
|
|
58
|
-
}, } = {}) {
|
|
59
|
-
const basicTriggerCharacters = getBasicTriggerCharacters(ts.version);
|
|
60
|
-
const jsDocTriggerCharacter = '*';
|
|
61
|
-
const directiveCommentTriggerCharacter = '@';
|
|
62
|
-
return {
|
|
63
|
-
name: 'typescript',
|
|
64
|
-
triggerCharacters: [
|
|
65
|
-
...basicTriggerCharacters,
|
|
66
|
-
jsDocTriggerCharacter,
|
|
67
|
-
directiveCommentTriggerCharacter,
|
|
68
|
-
],
|
|
69
|
-
signatureHelpTriggerCharacters: ['(', ',', '<'],
|
|
70
|
-
signatureHelpRetriggerCharacters: [')'],
|
|
71
|
-
// https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
|
|
72
|
-
autoFormatTriggerCharacters: [';', '}', '\n'],
|
|
73
|
-
create(context) {
|
|
74
|
-
const syntacticServiceHost = {
|
|
75
|
-
getProjectVersion: () => syntacticHostCtx.projectVersion.toString(),
|
|
76
|
-
getScriptFileNames: () => [syntacticHostCtx.fileName],
|
|
77
|
-
getScriptVersion: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.fileVersion.toString() : '',
|
|
78
|
-
getScriptSnapshot: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.snapshot : undefined,
|
|
79
|
-
getCompilationSettings: () => ({}),
|
|
80
|
-
getCurrentDirectory: () => '',
|
|
81
|
-
getDefaultLibFileName: () => '',
|
|
82
|
-
readFile: () => undefined,
|
|
83
|
-
fileExists: fileName => fileName === syntacticHostCtx.fileName,
|
|
84
|
-
};
|
|
85
|
-
const syntacticCtx = {
|
|
86
|
-
...context,
|
|
87
|
-
languageServiceHost: syntacticServiceHost,
|
|
88
|
-
languageService: ts.createLanguageService(syntacticServiceHost, undefined, 2),
|
|
89
|
-
ts,
|
|
90
|
-
uriToFileName: uri => {
|
|
91
|
-
if (uri !== syntacticHostCtx.document?.uri) {
|
|
92
|
-
throw new Error(`uriToFileName: uri not found: ${uri}`);
|
|
93
|
-
}
|
|
94
|
-
return syntacticHostCtx.fileName;
|
|
95
|
-
},
|
|
96
|
-
fileNameToUri: fileName => {
|
|
97
|
-
if (fileName !== syntacticHostCtx.fileName) {
|
|
98
|
-
throw new Error(`fileNameToUri: fileName not found: ${fileName}`);
|
|
99
|
-
}
|
|
100
|
-
return syntacticHostCtx.document.uri;
|
|
101
|
-
},
|
|
102
|
-
getTextDocument(uri) {
|
|
103
|
-
if (uri !== syntacticHostCtx.document?.uri) {
|
|
104
|
-
throw new Error(`getTextDocument: uri not found: ${uri}`);
|
|
105
|
-
}
|
|
106
|
-
return syntacticHostCtx.document;
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
const findDocumentSymbols = documentSymbol.register(syntacticCtx);
|
|
110
|
-
const doFormatting = formatting.register(syntacticCtx);
|
|
111
|
-
const getFoldingRanges = foldingRanges.register(syntacticCtx);
|
|
112
|
-
const syntacticService = {
|
|
113
|
-
provide: {
|
|
114
|
-
'typescript/typescript': () => ts,
|
|
115
|
-
'typescript/languageService': () => syntacticCtx.languageService,
|
|
116
|
-
'typescript/languageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
117
|
-
'typescript/syntacticLanguageService': () => syntacticCtx.languageService,
|
|
118
|
-
'typescript/syntacticLanguageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
119
|
-
},
|
|
120
|
-
async provideAutoInsertionEdit(document, position, lastChange) {
|
|
121
|
-
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
122
|
-
&& lastChange.text.endsWith('>')
|
|
123
|
-
&& await isAutoClosingTagsEnabled(document, context)) {
|
|
124
|
-
const ctx = prepareSyntacticService(document);
|
|
125
|
-
const close = syntacticCtx.languageService.getJsxClosingTagAtPosition(ctx.fileName, document.offsetAt(position));
|
|
126
|
-
if (close) {
|
|
127
|
-
return '$0' + close.newText;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
provideFoldingRanges(document) {
|
|
132
|
-
if (!(0, shared_1.isTsDocument)(document))
|
|
133
|
-
return;
|
|
134
|
-
prepareSyntacticService(document);
|
|
135
|
-
return getFoldingRanges(document.uri);
|
|
136
|
-
},
|
|
137
|
-
provideDocumentSymbols(document) {
|
|
138
|
-
if (!(0, shared_1.isTsDocument)(document))
|
|
139
|
-
return;
|
|
140
|
-
prepareSyntacticService(document);
|
|
141
|
-
return findDocumentSymbols(document.uri);
|
|
142
|
-
},
|
|
143
|
-
async provideDocumentFormattingEdits(document, range, options, codeOptions) {
|
|
144
|
-
if (!(0, shared_1.isTsDocument)(document))
|
|
145
|
-
return;
|
|
146
|
-
if (!await isFormattingEnabled(document, context))
|
|
147
|
-
return;
|
|
148
|
-
prepareSyntacticService(document);
|
|
149
|
-
return await doFormatting.onRange(document, range, options, codeOptions);
|
|
150
|
-
},
|
|
151
|
-
async provideOnTypeFormattingEdits(document, position, key, options, codeOptions) {
|
|
152
|
-
if (!(0, shared_1.isTsDocument)(document))
|
|
153
|
-
return;
|
|
154
|
-
if (!await isFormattingEnabled(document, context))
|
|
155
|
-
return;
|
|
156
|
-
prepareSyntacticService(document);
|
|
157
|
-
return doFormatting.onType(document, options, codeOptions, position, key);
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
const syntacticHostCtx = {
|
|
161
|
-
projectVersion: -1,
|
|
162
|
-
document: undefined,
|
|
163
|
-
documentVersion: undefined,
|
|
164
|
-
fileName: '',
|
|
165
|
-
fileVersion: 0,
|
|
166
|
-
snapshot: ts.ScriptSnapshot.fromString(''),
|
|
167
|
-
};
|
|
168
|
-
if (!context.language.typescript) {
|
|
169
|
-
return syntacticService;
|
|
170
|
-
}
|
|
171
|
-
const { sys, languageServiceHost } = context.language.typescript;
|
|
172
|
-
const created = tsFaster.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, (0, typescript_1.getDocumentRegistry)(ts, sys.useCaseSensitiveFileNames, languageServiceHost.getCurrentDirectory())));
|
|
173
|
-
const { languageService } = created;
|
|
174
|
-
if (created.setPreferences && context.env.getConfiguration) {
|
|
175
|
-
updatePreferences();
|
|
176
|
-
context.env.onDidChangeConfiguration?.(updatePreferences);
|
|
177
|
-
async function updatePreferences() {
|
|
178
|
-
const preferences = await context.env.getConfiguration?.('typescript.preferences');
|
|
179
|
-
if (preferences) {
|
|
180
|
-
created.setPreferences?.(preferences);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (created.projectUpdated) {
|
|
185
|
-
const sourceScriptNames = new Set();
|
|
186
|
-
const normalizeFileName = sys.useCaseSensitiveFileNames
|
|
187
|
-
? (id) => id
|
|
188
|
-
: (id) => id.toLowerCase();
|
|
189
|
-
updateSourceScriptFileNames();
|
|
190
|
-
context.env.onDidChangeWatchedFiles?.((params) => {
|
|
191
|
-
const someFileCreateOrDeiete = params.changes.some(change => change.type !== 2);
|
|
192
|
-
if (someFileCreateOrDeiete) {
|
|
193
|
-
updateSourceScriptFileNames();
|
|
194
|
-
}
|
|
195
|
-
for (const change of params.changes) {
|
|
196
|
-
const fileName = context.env.typescript.uriToFileName(change.uri);
|
|
197
|
-
if (sourceScriptNames.has(normalizeFileName(fileName))) {
|
|
198
|
-
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
function updateSourceScriptFileNames() {
|
|
203
|
-
sourceScriptNames.clear();
|
|
204
|
-
for (const fileName of languageServiceHost.getScriptFileNames()) {
|
|
205
|
-
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
206
|
-
const sourceFile = context.language.files.get(uri);
|
|
207
|
-
if (sourceFile?.generated) {
|
|
208
|
-
const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code);
|
|
209
|
-
if (tsCode) {
|
|
210
|
-
sourceScriptNames.add(normalizeFileName(fileName));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
else if (sourceFile) {
|
|
214
|
-
sourceScriptNames.add(normalizeFileName(fileName));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const semanticCtx = {
|
|
220
|
-
...context,
|
|
221
|
-
languageServiceHost,
|
|
222
|
-
languageService,
|
|
223
|
-
ts,
|
|
224
|
-
uriToFileName(uri) {
|
|
225
|
-
const virtualScript = getVirtualScriptByUri(uri);
|
|
226
|
-
if (virtualScript) {
|
|
227
|
-
return virtualScript.fileName;
|
|
228
|
-
}
|
|
229
|
-
return context.env.typescript.uriToFileName(uri);
|
|
230
|
-
},
|
|
231
|
-
fileNameToUri(fileName) {
|
|
232
|
-
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
233
|
-
const sourceFile = context.language.files.get(uri);
|
|
234
|
-
const extraScript = context.language.typescript.getExtraScript(fileName);
|
|
235
|
-
let virtualCode = extraScript?.code;
|
|
236
|
-
if (!virtualCode && sourceFile?.generated?.languagePlugin.typescript) {
|
|
237
|
-
const mainScript = sourceFile.generated.languagePlugin.typescript.getScript(sourceFile.generated.code);
|
|
238
|
-
if (mainScript) {
|
|
239
|
-
virtualCode = mainScript.code;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (virtualCode) {
|
|
243
|
-
const sourceFile = context.language.files.getByVirtualCode(virtualCode);
|
|
244
|
-
return context.documents.getVirtualCodeUri(sourceFile.id, virtualCode.id);
|
|
245
|
-
}
|
|
246
|
-
return uri;
|
|
247
|
-
},
|
|
248
|
-
getTextDocument(uri) {
|
|
249
|
-
const virtualCode = context.documents.getVirtualCodeByUri(uri)[0];
|
|
250
|
-
if (virtualCode) {
|
|
251
|
-
return context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot);
|
|
252
|
-
}
|
|
253
|
-
const sourceFile = context.language.files.get(uri);
|
|
254
|
-
if (sourceFile) {
|
|
255
|
-
return context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
const findDefinition = definitions.register(semanticCtx);
|
|
260
|
-
const findTypeDefinition = typeDefinitions.register(semanticCtx);
|
|
261
|
-
const findReferences = references.register(semanticCtx);
|
|
262
|
-
const findFileReferences = fileReferences.register(semanticCtx);
|
|
263
|
-
const findImplementations = implementation.register(semanticCtx);
|
|
264
|
-
const doPrepareRename = prepareRename.register(semanticCtx);
|
|
265
|
-
const doRename = rename.register(semanticCtx);
|
|
266
|
-
const getEditsForFileRename = fileRename.register(semanticCtx);
|
|
267
|
-
const getCodeActions = codeActions.register(semanticCtx);
|
|
268
|
-
const doCodeActionResolve = codeActionResolve.register(semanticCtx);
|
|
269
|
-
const getInlayHints = inlayHints.register(semanticCtx);
|
|
270
|
-
const findDocumentHighlights = documentHighlight.register(semanticCtx);
|
|
271
|
-
const findWorkspaceSymbols = workspaceSymbols.register(semanticCtx);
|
|
272
|
-
const doComplete = completions.register(semanticCtx);
|
|
273
|
-
const doCompletionResolve = completionResolve.register(semanticCtx);
|
|
274
|
-
const doDirectiveCommentComplete = directiveCommentCompletions.register(semanticCtx);
|
|
275
|
-
const doJsDocComplete = jsDocCompletions.register(semanticCtx);
|
|
276
|
-
const doHover = hover.register(semanticCtx);
|
|
277
|
-
const getSignatureHelp = signatureHelp.register(semanticCtx);
|
|
278
|
-
const getSelectionRanges = selectionRanges.register(semanticCtx);
|
|
279
|
-
const doValidation = diagnostics.register(semanticCtx);
|
|
280
|
-
const getDocumentSemanticTokens = semanticTokens.register(semanticCtx);
|
|
281
|
-
const callHierarchy = _callHierarchy.register(semanticCtx);
|
|
282
|
-
return {
|
|
283
|
-
...syntacticService,
|
|
284
|
-
provide: {
|
|
285
|
-
...syntacticService.provide,
|
|
286
|
-
'typescript/languageService': () => languageService,
|
|
287
|
-
'typescript/languageServiceHost': () => languageServiceHost,
|
|
288
|
-
},
|
|
289
|
-
dispose() {
|
|
290
|
-
languageService.dispose();
|
|
291
|
-
},
|
|
292
|
-
async provideCompletionItems(document, position, completeContext, token) {
|
|
293
|
-
if (!isSemanticDocument(document))
|
|
294
|
-
return;
|
|
295
|
-
if (!await isSuggestionsEnabled(document, context))
|
|
296
|
-
return;
|
|
297
|
-
return await worker(token, async () => {
|
|
298
|
-
let result = {
|
|
299
|
-
isIncomplete: false,
|
|
300
|
-
items: [],
|
|
301
|
-
};
|
|
302
|
-
if (!completeContext || completeContext.triggerKind !== 2 || (completeContext.triggerCharacter && basicTriggerCharacters.includes(completeContext.triggerCharacter))) {
|
|
303
|
-
const completeOptions = {
|
|
304
|
-
triggerCharacter: completeContext.triggerCharacter,
|
|
305
|
-
triggerKind: completeContext.triggerKind,
|
|
306
|
-
};
|
|
307
|
-
const basicResult = await doComplete(document.uri, position, completeOptions);
|
|
308
|
-
if (basicResult) {
|
|
309
|
-
result = basicResult;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
if (!completeContext || completeContext.triggerKind !== 2 || completeContext.triggerCharacter === jsDocTriggerCharacter) {
|
|
313
|
-
const jsdocResult = await doJsDocComplete(document.uri, position);
|
|
314
|
-
if (jsdocResult) {
|
|
315
|
-
result.items.push(jsdocResult);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (!completeContext || completeContext.triggerKind !== 2 || completeContext.triggerCharacter === directiveCommentTriggerCharacter) {
|
|
319
|
-
const directiveCommentResult = await doDirectiveCommentComplete(document.uri, position);
|
|
320
|
-
if (directiveCommentResult) {
|
|
321
|
-
result.items = result.items.concat(directiveCommentResult);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return result;
|
|
325
|
-
});
|
|
326
|
-
},
|
|
327
|
-
resolveCompletionItem(item, token) {
|
|
328
|
-
return worker(token, () => {
|
|
329
|
-
return doCompletionResolve(item);
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
provideRenameRange(document, position, token) {
|
|
333
|
-
if (!isSemanticDocument(document))
|
|
334
|
-
return;
|
|
335
|
-
return worker(token, () => {
|
|
336
|
-
return doPrepareRename(document.uri, position);
|
|
337
|
-
});
|
|
338
|
-
},
|
|
339
|
-
provideRenameEdits(document, position, newName, token) {
|
|
340
|
-
if (!isSemanticDocument(document, true))
|
|
341
|
-
return;
|
|
342
|
-
return worker(token, () => {
|
|
343
|
-
return doRename(document.uri, position, newName);
|
|
344
|
-
});
|
|
345
|
-
},
|
|
346
|
-
provideCodeActions(document, range, context, token) {
|
|
347
|
-
if (!isSemanticDocument(document))
|
|
348
|
-
return;
|
|
349
|
-
return worker(token, () => {
|
|
350
|
-
return getCodeActions(document.uri, range, context);
|
|
351
|
-
});
|
|
352
|
-
},
|
|
353
|
-
resolveCodeAction(codeAction, token) {
|
|
354
|
-
return worker(token, () => {
|
|
355
|
-
return doCodeActionResolve(codeAction);
|
|
356
|
-
});
|
|
357
|
-
},
|
|
358
|
-
provideInlayHints(document, range, token) {
|
|
359
|
-
if (!isSemanticDocument(document))
|
|
360
|
-
return;
|
|
361
|
-
return worker(token, () => {
|
|
362
|
-
return getInlayHints(document.uri, range);
|
|
363
|
-
});
|
|
364
|
-
},
|
|
365
|
-
provideCallHierarchyItems(document, position, token) {
|
|
366
|
-
if (!isSemanticDocument(document))
|
|
367
|
-
return;
|
|
368
|
-
return worker(token, () => {
|
|
369
|
-
return callHierarchy.doPrepare(document.uri, position);
|
|
370
|
-
});
|
|
371
|
-
},
|
|
372
|
-
provideCallHierarchyIncomingCalls(item, token) {
|
|
373
|
-
return worker(token, () => {
|
|
374
|
-
return callHierarchy.getIncomingCalls(item);
|
|
375
|
-
});
|
|
376
|
-
},
|
|
377
|
-
provideCallHierarchyOutgoingCalls(item, token) {
|
|
378
|
-
return worker(token, () => {
|
|
379
|
-
return callHierarchy.getOutgoingCalls(item);
|
|
380
|
-
});
|
|
381
|
-
},
|
|
382
|
-
provideDefinition(document, position, token) {
|
|
383
|
-
if (!isSemanticDocument(document))
|
|
384
|
-
return;
|
|
385
|
-
return worker(token, () => {
|
|
386
|
-
return findDefinition(document.uri, position);
|
|
387
|
-
});
|
|
388
|
-
},
|
|
389
|
-
provideTypeDefinition(document, position, token) {
|
|
390
|
-
if (!isSemanticDocument(document))
|
|
391
|
-
return;
|
|
392
|
-
return worker(token, () => {
|
|
393
|
-
return findTypeDefinition(document.uri, position);
|
|
394
|
-
});
|
|
395
|
-
},
|
|
396
|
-
async provideDiagnostics(document, token) {
|
|
397
|
-
if (!isSemanticDocument(document))
|
|
398
|
-
return;
|
|
399
|
-
if (!await isValidationEnabled(document, context))
|
|
400
|
-
return;
|
|
401
|
-
return await worker(token, () => {
|
|
402
|
-
return doValidation(document.uri, { syntactic: true, suggestion: true });
|
|
403
|
-
});
|
|
404
|
-
},
|
|
405
|
-
async provideSemanticDiagnostics(document, token) {
|
|
406
|
-
if (!isSemanticDocument(document))
|
|
407
|
-
return;
|
|
408
|
-
if (!await isValidationEnabled(document, context))
|
|
409
|
-
return;
|
|
410
|
-
return worker(token, () => {
|
|
411
|
-
return doValidation(document.uri, { semantic: true, declaration: true });
|
|
412
|
-
});
|
|
413
|
-
},
|
|
414
|
-
provideHover(document, position, token) {
|
|
415
|
-
if (!isSemanticDocument(document))
|
|
416
|
-
return;
|
|
417
|
-
return worker(token, () => {
|
|
418
|
-
return doHover(document.uri, position);
|
|
419
|
-
});
|
|
420
|
-
},
|
|
421
|
-
provideImplementation(document, position, token) {
|
|
422
|
-
if (!isSemanticDocument(document))
|
|
423
|
-
return;
|
|
424
|
-
return worker(token, () => {
|
|
425
|
-
return findImplementations(document.uri, position);
|
|
426
|
-
});
|
|
427
|
-
},
|
|
428
|
-
provideReferences(document, position, referenceContext, token) {
|
|
429
|
-
if (!isSemanticDocument(document, true))
|
|
430
|
-
return;
|
|
431
|
-
return worker(token, () => {
|
|
432
|
-
return findReferences(document.uri, position, referenceContext);
|
|
433
|
-
});
|
|
434
|
-
},
|
|
435
|
-
provideFileReferences(document, token) {
|
|
436
|
-
if (!isSemanticDocument(document, true))
|
|
437
|
-
return;
|
|
438
|
-
return worker(token, () => {
|
|
439
|
-
return findFileReferences(document.uri);
|
|
440
|
-
});
|
|
441
|
-
},
|
|
442
|
-
provideDocumentHighlights(document, position, token) {
|
|
443
|
-
if (!isSemanticDocument(document))
|
|
444
|
-
return;
|
|
445
|
-
return worker(token, () => {
|
|
446
|
-
return findDocumentHighlights(document.uri, position);
|
|
447
|
-
});
|
|
448
|
-
},
|
|
449
|
-
provideDocumentSemanticTokens(document, range, legend, token) {
|
|
450
|
-
if (!isSemanticDocument(document))
|
|
451
|
-
return;
|
|
452
|
-
return worker(token, () => {
|
|
453
|
-
return getDocumentSemanticTokens(document.uri, range, legend);
|
|
454
|
-
});
|
|
455
|
-
},
|
|
456
|
-
provideWorkspaceSymbols(query, token) {
|
|
457
|
-
return worker(token, () => {
|
|
458
|
-
return findWorkspaceSymbols(query);
|
|
459
|
-
});
|
|
460
|
-
},
|
|
461
|
-
provideFileRenameEdits(oldUri, newUri, token) {
|
|
462
|
-
return worker(token, () => {
|
|
463
|
-
return getEditsForFileRename(oldUri, newUri);
|
|
464
|
-
});
|
|
465
|
-
},
|
|
466
|
-
provideSelectionRanges(document, positions, token) {
|
|
467
|
-
if (!isSemanticDocument(document))
|
|
468
|
-
return;
|
|
469
|
-
return worker(token, () => {
|
|
470
|
-
return getSelectionRanges(document.uri, positions);
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
provideSignatureHelp(document, position, context, token) {
|
|
474
|
-
if (!isSemanticDocument(document))
|
|
475
|
-
return;
|
|
476
|
-
return worker(token, () => {
|
|
477
|
-
return getSignatureHelp(document.uri, position, context);
|
|
478
|
-
});
|
|
479
|
-
},
|
|
480
|
-
};
|
|
481
|
-
function isSemanticDocument(document, withJson = false) {
|
|
482
|
-
const virtualScript = getVirtualScriptByUri(document.uri);
|
|
483
|
-
if (virtualScript) {
|
|
484
|
-
return true;
|
|
485
|
-
}
|
|
486
|
-
if (withJson && (0, shared_1.isJsonDocument)(document)) {
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
return (0, shared_1.isTsDocument)(document);
|
|
490
|
-
}
|
|
491
|
-
function getVirtualScriptByUri(uri) {
|
|
492
|
-
const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(uri);
|
|
493
|
-
if (virtualCode && sourceFile.generated?.languagePlugin.typescript) {
|
|
494
|
-
const { getScript, getExtraScripts } = sourceFile.generated?.languagePlugin.typescript;
|
|
495
|
-
const sourceFileName = context.env.typescript.uriToFileName(sourceFile.id);
|
|
496
|
-
if (getScript(sourceFile.generated.code)?.code === virtualCode) {
|
|
497
|
-
return {
|
|
498
|
-
fileName: sourceFileName,
|
|
499
|
-
code: virtualCode,
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
for (const extraScript of getExtraScripts?.(sourceFileName, sourceFile.generated.code) ?? []) {
|
|
503
|
-
if (extraScript.code === virtualCode) {
|
|
504
|
-
return extraScript;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
async function worker(token, callback) {
|
|
510
|
-
let oldSysVersion = await sys.sync?.();
|
|
511
|
-
let result = await callback();
|
|
512
|
-
let newSysVersion = await sys.sync?.();
|
|
513
|
-
while (newSysVersion !== oldSysVersion && !token.isCancellationRequested) {
|
|
514
|
-
oldSysVersion = newSysVersion;
|
|
515
|
-
result = await callback();
|
|
516
|
-
newSysVersion = await sys.sync?.();
|
|
517
|
-
}
|
|
518
|
-
return result;
|
|
519
|
-
}
|
|
520
|
-
function prepareSyntacticService(document) {
|
|
521
|
-
if (syntacticHostCtx.document !== document || syntacticHostCtx.documentVersion !== document.version) {
|
|
522
|
-
syntacticHostCtx.document = document;
|
|
523
|
-
syntacticHostCtx.fileName = '/tmp.' +
|
|
524
|
-
document.languageId === 'javascript' ? 'js' :
|
|
525
|
-
document.languageId === 'typescriptreact' ? 'tsx' :
|
|
526
|
-
document.languageId === 'javascriptreact' ? 'jsx' :
|
|
527
|
-
'ts';
|
|
528
|
-
syntacticHostCtx.fileVersion++;
|
|
529
|
-
syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
530
|
-
syntacticHostCtx.projectVersion++;
|
|
531
|
-
}
|
|
532
|
-
return syntacticHostCtx;
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
};
|
|
4
|
+
var semantic_1 = require("./lib/plugins/semantic");
|
|
5
|
+
const directiveComment_1 = require("./lib/plugins/directiveComment");
|
|
6
|
+
const docCommentTemplate_1 = require("./lib/plugins/docCommentTemplate");
|
|
7
|
+
const semantic_2 = require("./lib/plugins/semantic");
|
|
8
|
+
const syntactic_1 = require("./lib/plugins/syntactic");
|
|
9
|
+
function create(ts, options) {
|
|
10
|
+
return [
|
|
11
|
+
(0, semantic_2.create)(ts, options),
|
|
12
|
+
(0, syntactic_1.create)(ts, options),
|
|
13
|
+
(0, docCommentTemplate_1.create)(ts),
|
|
14
|
+
(0, directiveComment_1.create)(),
|
|
15
|
+
];
|
|
536
16
|
}
|
|
537
17
|
exports.create = create;
|
|
538
|
-
function getBasicTriggerCharacters(tsVersion) {
|
|
539
|
-
const triggerCharacters = ['.', '"', '\'', '`', '/', '<'];
|
|
540
|
-
// https://github.com/microsoft/vscode/blob/8e65ae28d5fb8b3c931135da1a41edb9c80ae46f/extensions/typescript-language-features/src/languageFeatures/completions.ts#L811-L833
|
|
541
|
-
if (semver.lt(tsVersion, '3.1.0') || semver.gte(tsVersion, '3.2.0')) {
|
|
542
|
-
triggerCharacters.push('@');
|
|
543
|
-
}
|
|
544
|
-
if (semver.gte(tsVersion, '3.8.1')) {
|
|
545
|
-
triggerCharacters.push('#');
|
|
546
|
-
}
|
|
547
|
-
if (semver.gte(tsVersion, '4.3.0')) {
|
|
548
|
-
triggerCharacters.push(' ');
|
|
549
|
-
}
|
|
550
|
-
return triggerCharacters;
|
|
551
|
-
}
|
|
552
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { FormattingOptions } from '@volar/language-service';
|
|
1
|
+
import type { FormattingOptions, ServiceContext } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
|
|
5
|
-
export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
|
|
4
|
+
export declare function getFormatCodeSettings(ctx: ServiceContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
|
|
6
5
|
//# sourceMappingURL=getFormatCodeSettings.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
-
import type { SharedContext } from '../types';
|
|
3
|
+
import type { SharedContext } from '../semanticFeatures/types';
|
|
4
4
|
export declare function getUserPreferences(ctx: SharedContext, document: TextDocument): Promise<ts.UserPreferences>;
|
|
5
5
|
//# sourceMappingURL=getUserPreferences.d.ts.map
|