volar-service-typescript 0.0.11 → 0.0.12

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/out/index.d.ts CHANGED
@@ -12,5 +12,5 @@ export interface Provide {
12
12
  'typescript/syntacticLanguageService': () => ts.LanguageService;
13
13
  'typescript/syntacticLanguageServiceHost': () => ts.LanguageServiceHost;
14
14
  }
15
- declare const _default: () => Service<Provide>;
16
- export default _default;
15
+ export declare function create(): Service<Provide>;
16
+ export default create;
package/out/index.js CHANGED
@@ -26,6 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.create = void 0;
29
30
  const semver = __importStar(require("semver"));
30
31
  const shared_1 = require("./shared");
31
32
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
@@ -59,457 +60,461 @@ const typescript_1 = require("@volar/typescript");
59
60
  const tsFaster = __importStar(require("typescript-auto-import-cache"));
60
61
  __exportStar(require("@volar/typescript"), exports);
61
62
  ;
62
- exports.default = () => (contextOrNull, modules) => {
63
- const jsDocTriggerCharacter = '*';
64
- const directiveCommentTriggerCharacter = '@';
65
- const triggerCharacters = {
66
- triggerCharacters: [
67
- ...getBasicTriggerCharacters('4.3.0'),
68
- jsDocTriggerCharacter,
69
- directiveCommentTriggerCharacter,
70
- ],
71
- signatureHelpTriggerCharacters: ['(', ',', '<'],
72
- signatureHelpRetriggerCharacters: [')'],
73
- // https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
74
- autoFormatTriggerCharacters: [';', '}', '\n'],
75
- };
76
- if (!contextOrNull) {
77
- return triggerCharacters;
78
- }
79
- const context = contextOrNull;
80
- if (!modules?.typescript) {
81
- console.warn('[volar-service-typescript] context.typescript not found, volar-service-typescript is disabled. Make sure you have provide tsdk in language client.');
82
- return {};
83
- }
84
- const ts = modules.typescript;
85
- const sys = (0, typescript_1.createSys)(ts, context.env);
86
- const languageServiceHost = (0, typescript_1.createLanguageServiceHost)(context, ts, sys, context.env);
87
- const created = tsFaster.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, (0, typescript_1.getDocumentRegistry)(ts, sys.useCaseSensitiveFileNames, context.host.workspacePath)));
88
- const { languageService } = created;
89
- if (created.setPreferences && context.env.getConfiguration) {
90
- updatePreferences();
91
- context.env.onDidChangeConfiguration?.(updatePreferences);
92
- async function updatePreferences() {
93
- const preferences = await context.env.getConfiguration?.('typescript.preferences');
94
- if (preferences) {
95
- created.setPreferences?.(preferences);
96
- }
63
+ const jsDocTriggerCharacter = '*';
64
+ const directiveCommentTriggerCharacter = '@';
65
+ const triggerCharacters = {
66
+ triggerCharacters: [
67
+ ...getBasicTriggerCharacters('4.3.0'),
68
+ jsDocTriggerCharacter,
69
+ directiveCommentTriggerCharacter,
70
+ ],
71
+ signatureHelpTriggerCharacters: ['(', ',', '<'],
72
+ signatureHelpRetriggerCharacters: [')'],
73
+ // https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
74
+ autoFormatTriggerCharacters: [';', '}', '\n'],
75
+ };
76
+ function create() {
77
+ return (contextOrNull, modules) => {
78
+ if (!contextOrNull) {
79
+ return triggerCharacters;
97
80
  }
98
- }
99
- if (created.projectUpdated) {
100
- let scriptFileNames = new Set(context.host.getScriptFileNames());
101
- context.env.onDidChangeWatchedFiles?.((params) => {
102
- if (params.changes.some(change => change.type !== 2)) {
103
- scriptFileNames = new Set(context.host.getScriptFileNames());
104
- }
105
- for (const change of params.changes) {
106
- if (scriptFileNames.has(context.env.uriToFileName(change.uri))) {
107
- created.projectUpdated?.(context.env.uriToFileName(context.env.rootUri.fsPath));
81
+ const context = contextOrNull;
82
+ if (!modules?.typescript) {
83
+ console.warn('[volar-service-typescript] context.typescript not found, volar-service-typescript is disabled. Make sure you have provide tsdk in language client.');
84
+ return {};
85
+ }
86
+ const ts = modules.typescript;
87
+ const sys = (0, typescript_1.createSys)(ts, context.env);
88
+ const languageServiceHost = (0, typescript_1.createLanguageServiceHost)(context, ts, sys, context.env);
89
+ const created = tsFaster.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, (0, typescript_1.getDocumentRegistry)(ts, sys.useCaseSensitiveFileNames, context.host.workspacePath)));
90
+ const { languageService } = created;
91
+ if (created.setPreferences && context.env.getConfiguration) {
92
+ updatePreferences();
93
+ context.env.onDidChangeConfiguration?.(updatePreferences);
94
+ async function updatePreferences() {
95
+ const preferences = await context.env.getConfiguration?.('typescript.preferences');
96
+ if (preferences) {
97
+ created.setPreferences?.(preferences);
108
98
  }
109
99
  }
110
- });
111
- }
112
- const basicTriggerCharacters = getBasicTriggerCharacters(ts.version);
113
- const documents = new WeakMap();
114
- const semanticCtx = {
115
- ...context,
116
- typescript: {
117
- languageServiceHost,
118
- languageService,
119
- },
120
- ts,
121
- getTextDocument(uri) {
122
- const document = context.getTextDocument(uri);
123
- if (document) {
124
- return document;
125
- }
126
- const snapshot = languageServiceHost.getScriptSnapshot(context.env.uriToFileName(uri));
127
- if (snapshot) {
128
- let document = documents.get(snapshot);
129
- if (!document) {
130
- document = vscode_languageserver_textdocument_1.TextDocument.create(uri, '', 0, snapshot.getText(0, snapshot.getLength()));
131
- documents.set(snapshot, document);
100
+ }
101
+ if (created.projectUpdated) {
102
+ let scriptFileNames = new Set(context.host.getScriptFileNames());
103
+ context.env.onDidChangeWatchedFiles?.((params) => {
104
+ if (params.changes.some(change => change.type !== 2)) {
105
+ scriptFileNames = new Set(context.host.getScriptFileNames());
132
106
  }
133
- return document;
134
- }
135
- },
136
- };
137
- const findDefinition = definitions.register(semanticCtx);
138
- const findTypeDefinition = typeDefinitions.register(semanticCtx);
139
- const findReferences = references.register(semanticCtx);
140
- const findFileReferences = fileReferences.register(semanticCtx);
141
- const findImplementations = implementation.register(semanticCtx);
142
- const doPrepareRename = prepareRename.register(semanticCtx);
143
- const doRename = rename.register(semanticCtx);
144
- const getEditsForFileRename = fileRename.register(semanticCtx);
145
- const getCodeActions = codeActions.register(semanticCtx);
146
- const doCodeActionResolve = codeActionResolve.register(semanticCtx);
147
- const getInlayHints = inlayHints.register(semanticCtx);
148
- const findDocumentHighlights = documentHighlight.register(semanticCtx);
149
- const findWorkspaceSymbols = workspaceSymbols.register(semanticCtx);
150
- const doComplete = completions.register(semanticCtx);
151
- const doCompletionResolve = completionResolve.register(semanticCtx);
152
- const doDirectiveCommentComplete = directiveCommentCompletions.register(semanticCtx);
153
- const doJsDocComplete = jsDocCompletions.register(semanticCtx);
154
- const doHover = hover.register(semanticCtx);
155
- const getSignatureHelp = signatureHelp.register(semanticCtx);
156
- const getSelectionRanges = selectionRanges.register(semanticCtx);
157
- const doValidation = diagnostics.register(semanticCtx);
158
- const getDocumentSemanticTokens = semanticTokens.register(semanticCtx);
159
- const callHierarchy = _callHierarchy.register(semanticCtx);
160
- let syntacticHostCtx = {
161
- projectVersion: 0,
162
- document: undefined,
163
- fileName: '',
164
- fileVersion: 0,
165
- snapshot: ts.ScriptSnapshot.fromString(''),
166
- };
167
- const syntacticServiceHost = {
168
- getProjectVersion: () => syntacticHostCtx.projectVersion.toString(),
169
- getScriptFileNames: () => [syntacticHostCtx.fileName],
170
- getScriptVersion: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.fileVersion.toString() : '',
171
- getScriptSnapshot: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.snapshot : undefined,
172
- getCompilationSettings: () => languageServiceHost.getCompilationSettings() ?? {},
173
- getCurrentDirectory: () => '/',
174
- getDefaultLibFileName: () => '',
175
- readFile: () => undefined,
176
- fileExists: fileName => fileName === syntacticHostCtx.fileName,
177
- };
178
- const syntacticCtx = {
179
- ...semanticCtx,
180
- typescript: {
181
- ...semanticCtx.typescript,
182
- languageServiceHost: syntacticServiceHost,
183
- languageService: ts.createLanguageService(syntacticServiceHost),
184
- },
185
- };
186
- const findDocumentSymbols = documentSymbol.register(syntacticCtx);
187
- const doFormatting = formatting.register(syntacticCtx);
188
- const getFoldingRanges = foldingRanges.register(syntacticCtx);
189
- return {
190
- dispose() {
191
- languageService.dispose();
192
- sys.dispose();
193
- },
194
- provide: {
195
- 'typescript/typescript': () => ts,
196
- 'typescript/sys': () => sys,
197
- 'typescript/sourceFile': document => {
198
- if ((0, shared_1.isTsDocument)(document)) {
199
- const sourceFile = getSemanticServiceSourceFile(document.uri);
200
- if (sourceFile) {
201
- return sourceFile;
107
+ for (const change of params.changes) {
108
+ if (scriptFileNames.has(context.env.uriToFileName(change.uri))) {
109
+ created.projectUpdated?.(context.env.uriToFileName(context.env.rootUri.fsPath));
202
110
  }
203
- prepareSyntacticService(document);
204
- return syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
205
111
  }
112
+ });
113
+ }
114
+ const basicTriggerCharacters = getBasicTriggerCharacters(ts.version);
115
+ const documents = new WeakMap();
116
+ const semanticCtx = {
117
+ ...context,
118
+ typescript: {
119
+ languageServiceHost,
120
+ languageService,
206
121
  },
207
- 'typescript/textDocument': semanticCtx.getTextDocument,
208
- 'typescript/languageService': document => {
209
- if (!document || getSemanticServiceSourceFile(document.uri)) {
210
- return semanticCtx.typescript.languageService;
122
+ ts,
123
+ getTextDocument(uri) {
124
+ const document = context.getTextDocument(uri);
125
+ if (document) {
126
+ return document;
127
+ }
128
+ const snapshot = languageServiceHost.getScriptSnapshot(context.env.uriToFileName(uri));
129
+ if (snapshot) {
130
+ let document = documents.get(snapshot);
131
+ if (!document) {
132
+ document = vscode_languageserver_textdocument_1.TextDocument.create(uri, '', 0, snapshot.getText(0, snapshot.getLength()));
133
+ documents.set(snapshot, document);
134
+ }
135
+ return document;
211
136
  }
212
- prepareSyntacticService(document);
213
- return syntacticCtx.typescript.languageService;
214
137
  },
215
- 'typescript/syntacticLanguageService': () => {
216
- return syntacticCtx.typescript.languageService;
138
+ };
139
+ const findDefinition = definitions.register(semanticCtx);
140
+ const findTypeDefinition = typeDefinitions.register(semanticCtx);
141
+ const findReferences = references.register(semanticCtx);
142
+ const findFileReferences = fileReferences.register(semanticCtx);
143
+ const findImplementations = implementation.register(semanticCtx);
144
+ const doPrepareRename = prepareRename.register(semanticCtx);
145
+ const doRename = rename.register(semanticCtx);
146
+ const getEditsForFileRename = fileRename.register(semanticCtx);
147
+ const getCodeActions = codeActions.register(semanticCtx);
148
+ const doCodeActionResolve = codeActionResolve.register(semanticCtx);
149
+ const getInlayHints = inlayHints.register(semanticCtx);
150
+ const findDocumentHighlights = documentHighlight.register(semanticCtx);
151
+ const findWorkspaceSymbols = workspaceSymbols.register(semanticCtx);
152
+ const doComplete = completions.register(semanticCtx);
153
+ const doCompletionResolve = completionResolve.register(semanticCtx);
154
+ const doDirectiveCommentComplete = directiveCommentCompletions.register(semanticCtx);
155
+ const doJsDocComplete = jsDocCompletions.register(semanticCtx);
156
+ const doHover = hover.register(semanticCtx);
157
+ const getSignatureHelp = signatureHelp.register(semanticCtx);
158
+ const getSelectionRanges = selectionRanges.register(semanticCtx);
159
+ const doValidation = diagnostics.register(semanticCtx);
160
+ const getDocumentSemanticTokens = semanticTokens.register(semanticCtx);
161
+ const callHierarchy = _callHierarchy.register(semanticCtx);
162
+ let syntacticHostCtx = {
163
+ projectVersion: 0,
164
+ document: undefined,
165
+ fileName: '',
166
+ fileVersion: 0,
167
+ snapshot: ts.ScriptSnapshot.fromString(''),
168
+ };
169
+ const syntacticServiceHost = {
170
+ getProjectVersion: () => syntacticHostCtx.projectVersion.toString(),
171
+ getScriptFileNames: () => [syntacticHostCtx.fileName],
172
+ getScriptVersion: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.fileVersion.toString() : '',
173
+ getScriptSnapshot: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.snapshot : undefined,
174
+ getCompilationSettings: () => languageServiceHost.getCompilationSettings() ?? {},
175
+ getCurrentDirectory: () => '/',
176
+ getDefaultLibFileName: () => '',
177
+ readFile: () => undefined,
178
+ fileExists: fileName => fileName === syntacticHostCtx.fileName,
179
+ };
180
+ const syntacticCtx = {
181
+ ...semanticCtx,
182
+ typescript: {
183
+ ...semanticCtx.typescript,
184
+ languageServiceHost: syntacticServiceHost,
185
+ languageService: ts.createLanguageService(syntacticServiceHost),
217
186
  },
218
- 'typescript/languageServiceHost': document => {
219
- if (!document || getSemanticServiceSourceFile(document.uri)) {
220
- return semanticCtx.typescript.languageServiceHost;
221
- }
222
- prepareSyntacticService(document);
223
- return syntacticCtx.typescript.languageServiceHost;
224
- },
225
- 'typescript/syntacticLanguageServiceHost': () => {
226
- return syntacticCtx.typescript.languageServiceHost;
227
- },
228
- },
229
- ...triggerCharacters,
230
- triggerCharacters: [
231
- ...basicTriggerCharacters,
232
- jsDocTriggerCharacter,
233
- directiveCommentTriggerCharacter,
234
- ],
235
- provideAutoInsertionEdit(document, position, ctx) {
236
- if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
237
- && ctx.lastChange.text.endsWith('>')) {
238
- const configName = document.languageId === 'javascriptreact' ? 'javascript.autoClosingTags' : 'typescript.autoClosingTags';
239
- const config = context.env.getConfiguration?.(configName) ?? true;
240
- if (config) {
187
+ };
188
+ const findDocumentSymbols = documentSymbol.register(syntacticCtx);
189
+ const doFormatting = formatting.register(syntacticCtx);
190
+ const getFoldingRanges = foldingRanges.register(syntacticCtx);
191
+ return {
192
+ dispose() {
193
+ languageService.dispose();
194
+ sys.dispose();
195
+ },
196
+ provide: {
197
+ 'typescript/typescript': () => ts,
198
+ 'typescript/sys': () => sys,
199
+ 'typescript/sourceFile': document => {
200
+ if ((0, shared_1.isTsDocument)(document)) {
201
+ const sourceFile = getSemanticServiceSourceFile(document.uri);
202
+ if (sourceFile) {
203
+ return sourceFile;
204
+ }
205
+ prepareSyntacticService(document);
206
+ return syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
207
+ }
208
+ },
209
+ 'typescript/textDocument': semanticCtx.getTextDocument,
210
+ 'typescript/languageService': document => {
211
+ if (!document || getSemanticServiceSourceFile(document.uri)) {
212
+ return semanticCtx.typescript.languageService;
213
+ }
241
214
  prepareSyntacticService(document);
242
- const close = syntacticCtx.typescript.languageService.getJsxClosingTagAtPosition(context.env.uriToFileName(document.uri), document.offsetAt(position));
243
- if (close) {
244
- return '$0' + close.newText;
215
+ return syntacticCtx.typescript.languageService;
216
+ },
217
+ 'typescript/syntacticLanguageService': () => {
218
+ return syntacticCtx.typescript.languageService;
219
+ },
220
+ 'typescript/languageServiceHost': document => {
221
+ if (!document || getSemanticServiceSourceFile(document.uri)) {
222
+ return semanticCtx.typescript.languageServiceHost;
245
223
  }
246
- }
247
- }
248
- },
249
- provideCompletionItems(document, position, context, token) {
250
- if (!(0, shared_1.isTsDocument)(document))
251
- return;
252
- return worker(token, async () => {
253
- let result = {
254
- isIncomplete: false,
255
- items: [],
256
- };
257
- if (!context || context.triggerKind !== 2 || (context.triggerCharacter && basicTriggerCharacters.includes(context.triggerCharacter))) {
258
- const completeOptions = {
259
- triggerCharacter: context?.triggerCharacter,
260
- triggerKind: context?.triggerKind,
261
- };
262
- const basicResult = await doComplete(document.uri, position, completeOptions);
263
- if (basicResult) {
264
- result = basicResult;
224
+ prepareSyntacticService(document);
225
+ return syntacticCtx.typescript.languageServiceHost;
226
+ },
227
+ 'typescript/syntacticLanguageServiceHost': () => {
228
+ return syntacticCtx.typescript.languageServiceHost;
229
+ },
230
+ },
231
+ ...triggerCharacters,
232
+ triggerCharacters: [
233
+ ...basicTriggerCharacters,
234
+ jsDocTriggerCharacter,
235
+ directiveCommentTriggerCharacter,
236
+ ],
237
+ provideAutoInsertionEdit(document, position, ctx) {
238
+ if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
239
+ && ctx.lastChange.text.endsWith('>')) {
240
+ const configName = document.languageId === 'javascriptreact' ? 'javascript.autoClosingTags' : 'typescript.autoClosingTags';
241
+ const config = context.env.getConfiguration?.(configName) ?? true;
242
+ if (config) {
243
+ prepareSyntacticService(document);
244
+ const close = syntacticCtx.typescript.languageService.getJsxClosingTagAtPosition(context.env.uriToFileName(document.uri), document.offsetAt(position));
245
+ if (close) {
246
+ return '$0' + close.newText;
247
+ }
265
248
  }
266
249
  }
267
- if (!context || context.triggerKind !== 2 || context.triggerCharacter === jsDocTriggerCharacter) {
268
- const jsdocResult = await doJsDocComplete(document.uri, position);
269
- if (jsdocResult) {
270
- result.items.push(jsdocResult);
250
+ },
251
+ provideCompletionItems(document, position, context, token) {
252
+ if (!(0, shared_1.isTsDocument)(document))
253
+ return;
254
+ return worker(token, async () => {
255
+ let result = {
256
+ isIncomplete: false,
257
+ items: [],
258
+ };
259
+ if (!context || context.triggerKind !== 2 || (context.triggerCharacter && basicTriggerCharacters.includes(context.triggerCharacter))) {
260
+ const completeOptions = {
261
+ triggerCharacter: context?.triggerCharacter,
262
+ triggerKind: context?.triggerKind,
263
+ };
264
+ const basicResult = await doComplete(document.uri, position, completeOptions);
265
+ if (basicResult) {
266
+ result = basicResult;
267
+ }
271
268
  }
272
- }
273
- if (!context || context.triggerKind !== 2 || context.triggerCharacter === directiveCommentTriggerCharacter) {
274
- const directiveCommentResult = await doDirectiveCommentComplete(document.uri, position);
275
- if (directiveCommentResult) {
276
- result.items = result.items.concat(directiveCommentResult);
269
+ if (!context || context.triggerKind !== 2 || context.triggerCharacter === jsDocTriggerCharacter) {
270
+ const jsdocResult = await doJsDocComplete(document.uri, position);
271
+ if (jsdocResult) {
272
+ result.items.push(jsdocResult);
273
+ }
277
274
  }
278
- }
279
- return result;
280
- });
281
- },
282
- resolveCompletionItem(item, token) {
283
- return worker(token, () => {
284
- return doCompletionResolve(item);
285
- });
286
- },
287
- provideRenameRange(document, position, token) {
288
- if (!(0, shared_1.isTsDocument)(document))
289
- return;
290
- return worker(token, () => {
291
- return doPrepareRename(document.uri, position);
292
- });
293
- },
294
- provideRenameEdits(document, position, newName, token) {
295
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
296
- return;
297
- return worker(token, () => {
298
- return doRename(document.uri, position, newName);
299
- });
300
- },
301
- provideCodeActions(document, range, context, token) {
302
- if (!(0, shared_1.isTsDocument)(document))
303
- return;
304
- return worker(token, () => {
305
- return getCodeActions(document.uri, range, context);
306
- });
307
- },
308
- resolveCodeAction(codeAction, token) {
309
- return worker(token, () => {
310
- return doCodeActionResolve(codeAction);
311
- });
312
- },
313
- provideInlayHints(document, range, token) {
314
- if (!(0, shared_1.isTsDocument)(document))
315
- return;
316
- return worker(token, () => {
317
- return getInlayHints(document.uri, range);
318
- });
319
- },
320
- provideCallHierarchyItems(document, position, token) {
321
- if (!(0, shared_1.isTsDocument)(document))
322
- return;
323
- return worker(token, () => {
324
- return callHierarchy.doPrepare(document.uri, position);
325
- });
326
- },
327
- provideCallHierarchyIncomingCalls(item, token) {
328
- return worker(token, () => {
329
- return callHierarchy.getIncomingCalls(item);
330
- });
331
- },
332
- provideCallHierarchyOutgoingCalls(item, token) {
333
- return worker(token, () => {
334
- return callHierarchy.getOutgoingCalls(item);
335
- });
336
- },
337
- provideDefinition(document, position, token) {
338
- if (!(0, shared_1.isTsDocument)(document))
339
- return;
340
- return worker(token, () => {
341
- return findDefinition(document.uri, position);
342
- });
343
- },
344
- provideTypeDefinition(document, position, token) {
345
- if (!(0, shared_1.isTsDocument)(document))
346
- return;
347
- return worker(token, () => {
348
- return findTypeDefinition(document.uri, position);
349
- });
350
- },
351
- provideDiagnostics(document, token) {
352
- if (!(0, shared_1.isTsDocument)(document))
353
- return;
354
- return worker(token, () => {
355
- return doValidation(document.uri, { syntactic: true, suggestion: true });
356
- });
357
- },
358
- provideSemanticDiagnostics(document, token) {
359
- if (!(0, shared_1.isTsDocument)(document))
360
- return;
361
- return worker(token, () => {
362
- return doValidation(document.uri, { semantic: true, declaration: true });
363
- });
364
- },
365
- provideHover(document, position, token) {
366
- if (!(0, shared_1.isTsDocument)(document))
367
- return;
368
- return worker(token, () => {
369
- return doHover(document.uri, position);
370
- });
371
- },
372
- provideImplementation(document, position, token) {
373
- if (!(0, shared_1.isTsDocument)(document))
374
- return;
375
- return worker(token, () => {
376
- return findImplementations(document.uri, position);
377
- });
378
- },
379
- provideReferences(document, position, token) {
380
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
381
- return;
382
- return worker(token, () => {
383
- return findReferences(document.uri, position);
384
- });
385
- },
386
- provideFileReferences(document, token) {
387
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
388
- return;
389
- return worker(token, () => {
390
- return findFileReferences(document.uri);
391
- });
392
- },
393
- provideDocumentHighlights(document, position, token) {
394
- if (!(0, shared_1.isTsDocument)(document))
395
- return;
396
- return worker(token, () => {
397
- return findDocumentHighlights(document.uri, position);
398
- });
399
- },
400
- provideDocumentSymbols(document) {
401
- if (!(0, shared_1.isTsDocument)(document))
402
- return;
403
- prepareSyntacticService(document);
404
- return findDocumentSymbols(document.uri);
405
- },
406
- provideDocumentSemanticTokens(document, range, legend, token) {
407
- if (!(0, shared_1.isTsDocument)(document))
408
- return;
409
- return worker(token, () => {
410
- return getDocumentSemanticTokens(document.uri, range, legend);
411
- });
412
- },
413
- provideWorkspaceSymbols(query, token) {
414
- return worker(token, () => {
415
- return findWorkspaceSymbols(query);
416
- });
417
- },
418
- provideFileRenameEdits(oldUri, newUri, token) {
419
- return worker(token, () => {
420
- return getEditsForFileRename(oldUri, newUri);
421
- });
422
- },
423
- provideFoldingRanges(document) {
424
- if (!(0, shared_1.isTsDocument)(document))
425
- return;
426
- prepareSyntacticService(document);
427
- return getFoldingRanges(document.uri);
428
- },
429
- provideSelectionRanges(document, positions, token) {
430
- if (!(0, shared_1.isTsDocument)(document))
431
- return;
432
- return worker(token, () => {
433
- return getSelectionRanges(document.uri, positions);
434
- });
435
- },
436
- provideSignatureHelp(document, position, context, token) {
437
- if (!(0, shared_1.isTsDocument)(document))
438
- return;
439
- return worker(token, () => {
440
- return getSignatureHelp(document.uri, position, context);
441
- });
442
- },
443
- async provideDocumentFormattingEdits(document, range, options_2) {
444
- if (!(0, shared_1.isTsDocument)(document))
445
- return;
446
- const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
447
- if (enable === false) {
448
- return;
449
- }
450
- prepareSyntacticService(document);
451
- return await doFormatting.onRange(document, range, options_2);
452
- },
453
- async provideOnTypeFormattingEdits(document, position, key, options_2) {
454
- if (!(0, shared_1.isTsDocument)(document))
455
- return;
456
- const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
457
- if (enable === false) {
458
- return;
459
- }
460
- prepareSyntacticService(document);
461
- return doFormatting.onType(document, options_2, position, key);
462
- },
463
- provideFormattingIndentSensitiveLines(document) {
464
- if (!(0, shared_1.isTsDocument)(document))
465
- return;
466
- prepareSyntacticService(document);
467
- const sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(document.uri));
468
- if (sourceFile) {
469
- const lines = [];
470
- sourceFile.forEachChild(function walk(node) {
471
- if (node.kind === ts.SyntaxKind.FirstTemplateToken
472
- || node.kind === ts.SyntaxKind.LastTemplateToken
473
- || node.kind === ts.SyntaxKind.TemplateHead) {
474
- const startLine = document.positionAt(node.getStart(sourceFile)).line;
475
- const endLine = document.positionAt(node.getEnd()).line;
476
- for (let i = startLine + 1; i <= endLine; i++) {
477
- lines.push(i);
275
+ if (!context || context.triggerKind !== 2 || context.triggerCharacter === directiveCommentTriggerCharacter) {
276
+ const directiveCommentResult = await doDirectiveCommentComplete(document.uri, position);
277
+ if (directiveCommentResult) {
278
+ result.items = result.items.concat(directiveCommentResult);
478
279
  }
479
280
  }
480
- node.forEachChild(walk);
281
+ return result;
282
+ });
283
+ },
284
+ resolveCompletionItem(item, token) {
285
+ return worker(token, () => {
286
+ return doCompletionResolve(item);
287
+ });
288
+ },
289
+ provideRenameRange(document, position, token) {
290
+ if (!(0, shared_1.isTsDocument)(document))
291
+ return;
292
+ return worker(token, () => {
293
+ return doPrepareRename(document.uri, position);
294
+ });
295
+ },
296
+ provideRenameEdits(document, position, newName, token) {
297
+ if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
298
+ return;
299
+ return worker(token, () => {
300
+ return doRename(document.uri, position, newName);
301
+ });
302
+ },
303
+ provideCodeActions(document, range, context, token) {
304
+ if (!(0, shared_1.isTsDocument)(document))
305
+ return;
306
+ return worker(token, () => {
307
+ return getCodeActions(document.uri, range, context);
308
+ });
309
+ },
310
+ resolveCodeAction(codeAction, token) {
311
+ return worker(token, () => {
312
+ return doCodeActionResolve(codeAction);
313
+ });
314
+ },
315
+ provideInlayHints(document, range, token) {
316
+ if (!(0, shared_1.isTsDocument)(document))
317
+ return;
318
+ return worker(token, () => {
319
+ return getInlayHints(document.uri, range);
320
+ });
321
+ },
322
+ provideCallHierarchyItems(document, position, token) {
323
+ if (!(0, shared_1.isTsDocument)(document))
324
+ return;
325
+ return worker(token, () => {
326
+ return callHierarchy.doPrepare(document.uri, position);
327
+ });
328
+ },
329
+ provideCallHierarchyIncomingCalls(item, token) {
330
+ return worker(token, () => {
331
+ return callHierarchy.getIncomingCalls(item);
332
+ });
333
+ },
334
+ provideCallHierarchyOutgoingCalls(item, token) {
335
+ return worker(token, () => {
336
+ return callHierarchy.getOutgoingCalls(item);
337
+ });
338
+ },
339
+ provideDefinition(document, position, token) {
340
+ if (!(0, shared_1.isTsDocument)(document))
341
+ return;
342
+ return worker(token, () => {
343
+ return findDefinition(document.uri, position);
344
+ });
345
+ },
346
+ provideTypeDefinition(document, position, token) {
347
+ if (!(0, shared_1.isTsDocument)(document))
348
+ return;
349
+ return worker(token, () => {
350
+ return findTypeDefinition(document.uri, position);
351
+ });
352
+ },
353
+ provideDiagnostics(document, token) {
354
+ if (!(0, shared_1.isTsDocument)(document))
355
+ return;
356
+ return worker(token, () => {
357
+ return doValidation(document.uri, { syntactic: true, suggestion: true });
358
+ });
359
+ },
360
+ provideSemanticDiagnostics(document, token) {
361
+ if (!(0, shared_1.isTsDocument)(document))
362
+ return;
363
+ return worker(token, () => {
364
+ return doValidation(document.uri, { semantic: true, declaration: true });
365
+ });
366
+ },
367
+ provideHover(document, position, token) {
368
+ if (!(0, shared_1.isTsDocument)(document))
369
+ return;
370
+ return worker(token, () => {
371
+ return doHover(document.uri, position);
372
+ });
373
+ },
374
+ provideImplementation(document, position, token) {
375
+ if (!(0, shared_1.isTsDocument)(document))
376
+ return;
377
+ return worker(token, () => {
378
+ return findImplementations(document.uri, position);
379
+ });
380
+ },
381
+ provideReferences(document, position, token) {
382
+ if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
383
+ return;
384
+ return worker(token, () => {
385
+ return findReferences(document.uri, position);
386
+ });
387
+ },
388
+ provideFileReferences(document, token) {
389
+ if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
390
+ return;
391
+ return worker(token, () => {
392
+ return findFileReferences(document.uri);
393
+ });
394
+ },
395
+ provideDocumentHighlights(document, position, token) {
396
+ if (!(0, shared_1.isTsDocument)(document))
397
+ return;
398
+ return worker(token, () => {
399
+ return findDocumentHighlights(document.uri, position);
400
+ });
401
+ },
402
+ provideDocumentSymbols(document) {
403
+ if (!(0, shared_1.isTsDocument)(document))
404
+ return;
405
+ prepareSyntacticService(document);
406
+ return findDocumentSymbols(document.uri);
407
+ },
408
+ provideDocumentSemanticTokens(document, range, legend, token) {
409
+ if (!(0, shared_1.isTsDocument)(document))
410
+ return;
411
+ return worker(token, () => {
412
+ return getDocumentSemanticTokens(document.uri, range, legend);
413
+ });
414
+ },
415
+ provideWorkspaceSymbols(query, token) {
416
+ return worker(token, () => {
417
+ return findWorkspaceSymbols(query);
481
418
  });
482
- return lines;
419
+ },
420
+ provideFileRenameEdits(oldUri, newUri, token) {
421
+ return worker(token, () => {
422
+ return getEditsForFileRename(oldUri, newUri);
423
+ });
424
+ },
425
+ provideFoldingRanges(document) {
426
+ if (!(0, shared_1.isTsDocument)(document))
427
+ return;
428
+ prepareSyntacticService(document);
429
+ return getFoldingRanges(document.uri);
430
+ },
431
+ provideSelectionRanges(document, positions, token) {
432
+ if (!(0, shared_1.isTsDocument)(document))
433
+ return;
434
+ return worker(token, () => {
435
+ return getSelectionRanges(document.uri, positions);
436
+ });
437
+ },
438
+ provideSignatureHelp(document, position, context, token) {
439
+ if (!(0, shared_1.isTsDocument)(document))
440
+ return;
441
+ return worker(token, () => {
442
+ return getSignatureHelp(document.uri, position, context);
443
+ });
444
+ },
445
+ async provideDocumentFormattingEdits(document, range, options_2) {
446
+ if (!(0, shared_1.isTsDocument)(document))
447
+ return;
448
+ const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
449
+ if (enable === false) {
450
+ return;
451
+ }
452
+ prepareSyntacticService(document);
453
+ return await doFormatting.onRange(document, range, options_2);
454
+ },
455
+ async provideOnTypeFormattingEdits(document, position, key, options_2) {
456
+ if (!(0, shared_1.isTsDocument)(document))
457
+ return;
458
+ const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
459
+ if (enable === false) {
460
+ return;
461
+ }
462
+ prepareSyntacticService(document);
463
+ return doFormatting.onType(document, options_2, position, key);
464
+ },
465
+ provideFormattingIndentSensitiveLines(document) {
466
+ if (!(0, shared_1.isTsDocument)(document))
467
+ return;
468
+ prepareSyntacticService(document);
469
+ const sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(document.uri));
470
+ if (sourceFile) {
471
+ const lines = [];
472
+ sourceFile.forEachChild(function walk(node) {
473
+ if (node.kind === ts.SyntaxKind.FirstTemplateToken
474
+ || node.kind === ts.SyntaxKind.LastTemplateToken
475
+ || node.kind === ts.SyntaxKind.TemplateHead) {
476
+ const startLine = document.positionAt(node.getStart(sourceFile)).line;
477
+ const endLine = document.positionAt(node.getEnd()).line;
478
+ for (let i = startLine + 1; i <= endLine; i++) {
479
+ lines.push(i);
480
+ }
481
+ }
482
+ node.forEachChild(walk);
483
+ });
484
+ return lines;
485
+ }
486
+ },
487
+ };
488
+ async function worker(token, callback) {
489
+ let oldSysVersion = sys.version;
490
+ let result = await callback();
491
+ let newSysVersion = await sys.sync();
492
+ while (newSysVersion !== oldSysVersion && !token.isCancellationRequested) {
493
+ oldSysVersion = newSysVersion;
494
+ result = await callback();
495
+ newSysVersion = await sys.sync();
483
496
  }
484
- },
485
- };
486
- async function worker(token, callback) {
487
- let oldSysVersion = sys.version;
488
- let result = await callback();
489
- let newSysVersion = await sys.sync();
490
- while (newSysVersion !== oldSysVersion && !token.isCancellationRequested) {
491
- oldSysVersion = newSysVersion;
492
- result = await callback();
493
- newSysVersion = await sys.sync();
497
+ return result;
494
498
  }
495
- return result;
496
- }
497
- function getSemanticServiceSourceFile(uri) {
498
- const sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(uri));
499
- if (sourceFile) {
500
- return sourceFile;
499
+ function getSemanticServiceSourceFile(uri) {
500
+ const sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(uri));
501
+ if (sourceFile) {
502
+ return sourceFile;
503
+ }
501
504
  }
502
- }
503
- function prepareSyntacticService(document) {
504
- if (syntacticHostCtx.document === document && syntacticHostCtx.fileVersion === document.version) {
505
- return;
505
+ function prepareSyntacticService(document) {
506
+ if (syntacticHostCtx.document === document && syntacticHostCtx.fileVersion === document.version) {
507
+ return;
508
+ }
509
+ syntacticHostCtx.fileName = context.env.uriToFileName(document.uri);
510
+ syntacticHostCtx.fileVersion = document.version;
511
+ syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
512
+ syntacticHostCtx.projectVersion++;
506
513
  }
507
- syntacticHostCtx.fileName = context.env.uriToFileName(document.uri);
508
- syntacticHostCtx.fileVersion = document.version;
509
- syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
510
- syntacticHostCtx.projectVersion++;
511
- }
512
- };
514
+ };
515
+ }
516
+ exports.create = create;
517
+ exports.default = create;
513
518
  function getBasicTriggerCharacters(tsVersion) {
514
519
  const triggerCharacters = ['.', '"', '\'', '`', '/', '<'];
515
520
  // https://github.com/microsoft/vscode/blob/8e65ae28d5fb8b3c931135da1a41edb9c80ae46f/extensions/typescript-language-features/src/languageFeatures/completions.ts#L811-L833
@@ -1,4 +1,4 @@
1
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
2
2
  export declare namespace SymbolKind {
3
- function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 15 | 22 | 26;
3
+ function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 10 | 22 | 11 | 6 | 7 | 13 | 12 | 9 | 26 | 15;
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-typescript",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -32,5 +32,5 @@
32
32
  "optional": true
33
33
  }
34
34
  },
35
- "gitHead": "5be7c0c4fc41f4ebe3d8f3d272d3a0d8377973ad"
35
+ "gitHead": "7422c8d99d498df660ff9be3491545a5b45b3622"
36
36
  }