@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.10

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.
@@ -1,41 +1,32 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.register = void 0;
12
4
  const protocol_1 = require("../../protocol");
13
5
  const language_core_1 = require("@volar/language-core");
14
6
  function register(connection, projects, env) {
15
- connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
7
+ connection.onNotification(protocol_1.ReportStats.type, async () => {
17
8
  for (const [rootUri, _workspace] of projects.workspaces) {
18
9
  connection.console.log('workspace: ' + rootUri);
19
- const workspace = yield _workspace;
20
- connection.console.log('documentRegistry stats: ' + ((_a = workspace.documentRegistry) === null || _a === void 0 ? void 0 : _a.reportStats()));
10
+ const workspace = await _workspace;
11
+ connection.console.log('documentRegistry stats: ' + workspace.documentRegistry?.reportStats());
21
12
  connection.console.log('');
22
13
  connection.console.log('tsconfig: inferred');
23
14
  const _inferredProject = workspace.getInferredProjectDontCreate();
24
15
  if (_inferredProject) {
25
16
  connection.console.log('loaded: true');
26
- const inferredProject = yield _inferredProject;
17
+ const inferredProject = await _inferredProject;
27
18
  connection.console.log('largest 10 files:');
28
19
  for (const script of [...inferredProject.scripts.values()]
29
- .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
20
+ .sort((a, b) => (b.snapshot?.getLength() ?? 0) - (a.snapshot?.getLength() ?? 0))
30
21
  .slice(0, 10)) {
31
22
  connection.console.log(' - ' + script.fileName);
32
- connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
23
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
33
24
  }
34
25
  connection.console.log('files:');
35
26
  for (const script of inferredProject.scripts.values()) {
36
27
  connection.console.log(' - ' + script.fileName);
37
- connection.console.log(` size: ${(_c = script.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()}`);
38
- connection.console.log(` ref counts: "${(_e = (_d = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _e === void 0 ? void 0 : _e.call(_d, script.fileName, (_g = (_f = inferredProject.languageServiceHost).getScriptKind) === null || _g === void 0 ? void 0 : _g.call(_f, script.fileName))})"`);
28
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
29
+ connection.console.log(` ref counts: "${workspace.documentRegistry.getLanguageServiceRefCounts?.(script.fileName, inferredProject.languageServiceHost.getScriptKind?.(script.fileName))})"`);
39
30
  }
40
31
  }
41
32
  else {
@@ -43,40 +34,39 @@ function register(connection, projects, env) {
43
34
  }
44
35
  connection.console.log('');
45
36
  for (const _project of workspace.projects.values()) {
46
- const project = yield _project;
37
+ const project = await _project;
47
38
  connection.console.log('tsconfig: ' + project.tsConfig);
48
39
  connection.console.log('loaded: ' + !!project.getLanguageServiceDontCreate());
49
40
  connection.console.log('largest 10 files:');
50
41
  for (const script of [...project.scripts.values()]
51
- .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
42
+ .sort((a, b) => (b.snapshot?.getLength() ?? 0) - (a.snapshot?.getLength() ?? 0))
52
43
  .slice(0, 10)) {
53
44
  connection.console.log(' - ' + script.fileName);
54
- connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
45
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
55
46
  }
56
47
  connection.console.log('files:');
57
48
  for (const script of project.scripts.values()) {
58
49
  connection.console.log(' - ' + script.fileName);
59
- connection.console.log(` size: ${(_j = script.snapshot) === null || _j === void 0 ? void 0 : _j.getLength()}`);
60
- connection.console.log(` ref counts: "${(_l = (_k = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _l === void 0 ? void 0 : _l.call(_k, script.fileName, (_o = (_m = project.languageServiceHost).getScriptKind) === null || _o === void 0 ? void 0 : _o.call(_m, script.fileName))})"`);
50
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
51
+ connection.console.log(` ref counts: "${workspace.documentRegistry.getLanguageServiceRefCounts?.(script.fileName, project.languageServiceHost.getScriptKind?.(script.fileName))})"`);
61
52
  }
62
53
  }
63
54
  connection.console.log('');
64
55
  }
65
- }));
66
- connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
67
- const project = (yield projects.getProject(params.uri));
68
- if (project === null || project === void 0 ? void 0 : project.tsconfig) {
56
+ });
57
+ connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
58
+ const project = (await projects.getProject(params.uri));
59
+ if (project?.tsconfig) {
69
60
  return { uri: env.fileNameToUri(project.tsconfig) };
70
61
  }
71
- }));
72
- connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
73
- var _p, _q, _r;
74
- const project = yield projects.getProject(document.uri);
62
+ });
63
+ connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, async (document) => {
64
+ const project = await projects.getProject(document.uri);
75
65
  const fileNames = [];
76
66
  if (project) {
77
- const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(env.uriToFileName(document.uri))) === null || _q === void 0 ? void 0 : _q.root;
67
+ const rootVirtualFile = project.project?.getLanguageService().context.core.virtualFiles.getSource(env.uriToFileName(document.uri))?.root;
78
68
  if (rootVirtualFile) {
79
- const kinds = (_r = document.fileKinds) !== null && _r !== void 0 ? _r : [language_core_1.FileKind.TypeScriptHostFile];
69
+ const kinds = document.fileKinds ?? [language_core_1.FileKind.TypeScriptHostFile];
80
70
  (0, language_core_1.forEachEmbeddedFile)(rootVirtualFile, e => {
81
71
  if (e.snapshot.getLength() && kinds.includes(e.kind)) {
82
72
  fileNames.push(e.fileName);
@@ -85,17 +75,16 @@ function register(connection, projects, env) {
85
75
  }
86
76
  }
87
77
  return fileNames;
88
- }));
89
- connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
90
- var _s, _t, _u, _v;
91
- const project = yield projects.getProject(params.sourceFileUri);
78
+ });
79
+ connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (params) => {
80
+ const project = await projects.getProject(params.sourceFileUri);
92
81
  if (project) {
93
- const [virtualFile, source] = (_t = (_s = project.project) === null || _s === void 0 ? void 0 : _s.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName)) !== null && _t !== void 0 ? _t : [];
82
+ const [virtualFile, source] = project.project?.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName) ?? [];
94
83
  if (virtualFile && source) {
95
84
  const mappings = {};
96
85
  for (const mapping of virtualFile.mappings) {
97
- const sourceUri = env.fileNameToUri((_u = mapping.source) !== null && _u !== void 0 ? _u : source.fileName);
98
- (_v = mappings[sourceUri]) !== null && _v !== void 0 ? _v : (mappings[sourceUri] = []);
86
+ const sourceUri = env.fileNameToUri(mapping.source ?? source.fileName);
87
+ mappings[sourceUri] ??= [];
99
88
  mappings[sourceUri].push(mapping);
100
89
  }
101
90
  return {
@@ -104,16 +93,15 @@ function register(connection, projects, env) {
104
93
  };
105
94
  }
106
95
  }
107
- }));
96
+ });
108
97
  connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
109
98
  projects.reloadProject();
110
99
  });
111
- connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
112
- var _w;
113
- const fs = yield Promise.resolve().then(() => require('fs'));
114
- const project = yield projects.getProject(params.uri);
100
+ connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
101
+ const fs = await Promise.resolve().then(() => require('fs'));
102
+ const project = await projects.getProject(params.uri);
115
103
  if (project) {
116
- const ls = (_w = (yield project.project)) === null || _w === void 0 ? void 0 : _w.getLanguageServiceDontCreate();
104
+ const ls = (await project.project)?.getLanguageServiceDontCreate();
117
105
  if (ls) {
118
106
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
119
107
  for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
@@ -126,7 +114,7 @@ function register(connection, projects, env) {
126
114
  }
127
115
  }
128
116
  }
129
- }));
117
+ });
130
118
  }
131
119
  exports.register = register;
132
120
  //# sourceMappingURL=customFeatures.js.map
@@ -1,12 +1,4 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.sleep = exports.register = void 0;
12
4
  const embedded = require("@volar/language-service");
@@ -19,73 +11,73 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
19
11
  let lastCodeLensLs;
20
12
  let lastCodeActionLs;
21
13
  let lastCallHierarchyLs;
22
- connection.onDocumentFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
14
+ let lastDocumentLinkLs;
15
+ let lastInlayHintLs;
16
+ connection.onDocumentFormatting(async (params, token) => {
23
17
  return worker(params.textDocument.uri, token, service => {
24
18
  return service.format(params.textDocument.uri, params.options, undefined, undefined, token);
25
19
  });
26
- }));
27
- connection.onDocumentRangeFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
20
+ });
21
+ connection.onDocumentRangeFormatting(async (params, token) => {
28
22
  return worker(params.textDocument.uri, token, service => {
29
23
  return service.format(params.textDocument.uri, params.options, params.range, undefined, token);
30
24
  });
31
- }));
32
- connection.onDocumentOnTypeFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
25
+ });
26
+ connection.onDocumentOnTypeFormatting(async (params, token) => {
33
27
  return worker(params.textDocument.uri, token, service => {
34
28
  return service.format(params.textDocument.uri, params.options, undefined, params, token);
35
29
  });
36
- }));
37
- connection.onSelectionRanges((params, token) => __awaiter(this, void 0, void 0, function* () {
30
+ });
31
+ connection.onSelectionRanges(async (params, token) => {
38
32
  return worker(params.textDocument.uri, token, service => {
39
33
  return service.getSelectionRanges(params.textDocument.uri, params.positions, token);
40
34
  });
41
- }));
42
- connection.onFoldingRanges((params, token) => __awaiter(this, void 0, void 0, function* () {
35
+ });
36
+ connection.onFoldingRanges(async (params, token) => {
43
37
  return worker(params.textDocument.uri, token, service => {
44
38
  return service.getFoldingRanges(params.textDocument.uri, token);
45
39
  });
46
- }));
47
- connection.languages.onLinkedEditingRange((params, token) => __awaiter(this, void 0, void 0, function* () {
40
+ });
41
+ connection.languages.onLinkedEditingRange(async (params, token) => {
48
42
  return worker(params.textDocument.uri, token, service => {
49
43
  return service.findLinkedEditingRanges(params.textDocument.uri, params.position, token);
50
44
  });
51
- }));
52
- connection.onDocumentSymbol((params, token) => __awaiter(this, void 0, void 0, function* () {
45
+ });
46
+ connection.onDocumentSymbol(async (params, token) => {
53
47
  return worker(params.textDocument.uri, token, service => {
54
48
  return service.findDocumentSymbols(params.textDocument.uri, token);
55
49
  });
56
- }));
57
- connection.onDocumentColor((params, token) => __awaiter(this, void 0, void 0, function* () {
50
+ });
51
+ connection.onDocumentColor(async (params, token) => {
58
52
  return worker(params.textDocument.uri, token, service => {
59
53
  return service.findDocumentColors(params.textDocument.uri, token);
60
54
  });
61
- }));
62
- connection.onColorPresentation((params, token) => __awaiter(this, void 0, void 0, function* () {
55
+ });
56
+ connection.onColorPresentation(async (params, token) => {
63
57
  return worker(params.textDocument.uri, token, service => {
64
58
  return service.getColorPresentations(params.textDocument.uri, params.color, params.range, token);
65
59
  });
66
- }));
67
- connection.onCompletion((params, token) => __awaiter(this, void 0, void 0, function* () {
68
- return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
69
- var _a;
60
+ });
61
+ connection.onCompletion(async (params, token) => {
62
+ return worker(params.textDocument.uri, token, async (service) => {
70
63
  lastCompleteUri = params.textDocument.uri;
71
64
  lastCompleteLs = service;
72
- const document = (_a = documents.data.uriGet(params.textDocument.uri)) === null || _a === void 0 ? void 0 : _a.getDocument();
73
- const list = yield service.doComplete(params.textDocument.uri, params.position, params.context, token);
65
+ const document = documents.data.uriGet(params.textDocument.uri)?.getDocument();
66
+ const list = await service.doComplete(params.textDocument.uri, params.position, params.context, token);
74
67
  for (const item of list.items) {
75
68
  fixTextEdit(item);
76
69
  }
77
70
  if (!initOptions.fullCompletionList && document) {
78
71
  list.items = list.items.filter(item => {
79
- var _a, _b;
80
72
  const range = item.textEdit ? (vscode.InsertReplaceEdit.is(item.textEdit)
81
73
  ? item.textEdit.replace
82
- : item.textEdit.range) : ((_a = list.itemDefaults) === null || _a === void 0 ? void 0 : _a.editRange) ? (vscode.Range.is(list.itemDefaults.editRange)
74
+ : item.textEdit.range) : list.itemDefaults?.editRange ? (vscode.Range.is(list.itemDefaults.editRange)
83
75
  ? list.itemDefaults.editRange
84
76
  : list.itemDefaults.editRange.replace) : undefined;
85
77
  if (range) {
86
78
  const sourceText = document.getText(range).toLowerCase();
87
79
  if (sourceText.trim()) {
88
- let filterText = ((_b = item.filterText) !== null && _b !== void 0 ? _b : item.label).toLowerCase();
80
+ let filterText = (item.filterText ?? item.label).toLowerCase();
89
81
  for (const char of sourceText) {
90
82
  const index = filterText.indexOf(char);
91
83
  if (index === -1) {
@@ -99,63 +91,48 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
99
91
  });
100
92
  }
101
93
  return list;
102
- }));
103
- }));
104
- connection.onCompletionResolve((item, token) => __awaiter(this, void 0, void 0, function* () {
94
+ });
95
+ });
96
+ connection.onCompletionResolve(async (item, token) => {
105
97
  if (lastCompleteUri && lastCompleteLs) {
106
- item = yield lastCompleteLs.doCompletionResolve(item, token);
98
+ item = await lastCompleteLs.doCompletionResolve(item, token);
107
99
  fixTextEdit(item);
108
100
  }
109
101
  return item;
110
- }));
111
- connection.onHover((params, token) => __awaiter(this, void 0, void 0, function* () {
102
+ });
103
+ connection.onHover(async (params, token) => {
112
104
  return worker(params.textDocument.uri, token, service => {
113
105
  return service.doHover(params.textDocument.uri, params.position, token);
114
106
  });
115
- }));
116
- connection.onSignatureHelp((params, token) => __awaiter(this, void 0, void 0, function* () {
107
+ });
108
+ connection.onSignatureHelp(async (params, token) => {
117
109
  return worker(params.textDocument.uri, token, service => {
118
110
  return service.getSignatureHelp(params.textDocument.uri, params.position, params.context, token);
119
111
  });
120
- }));
121
- connection.onPrepareRename((params, token) => __awaiter(this, void 0, void 0, function* () {
112
+ });
113
+ connection.onPrepareRename(async (params, token) => {
122
114
  return worker(params.textDocument.uri, token, service => {
123
115
  return service.prepareRename(params.textDocument.uri, params.position, token);
124
116
  });
125
- }));
126
- connection.onRenameRequest((params, token) => __awaiter(this, void 0, void 0, function* () {
117
+ });
118
+ connection.onRenameRequest(async (params, token) => {
127
119
  return worker(params.textDocument.uri, token, service => {
128
120
  return service.doRename(params.textDocument.uri, params.position, params.newName, token);
129
121
  });
130
- }));
131
- connection.onCodeLens((params, token) => __awaiter(this, void 0, void 0, function* () {
132
- return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
122
+ });
123
+ connection.onCodeLens(async (params, token) => {
124
+ return worker(params.textDocument.uri, token, async (service) => {
133
125
  lastCodeLensLs = service;
134
126
  return service.doCodeLens(params.textDocument.uri, token);
135
- }));
136
- }));
137
- connection.onCodeLensResolve((codeLens, token) => __awaiter(this, void 0, void 0, function* () {
138
- var _b;
139
- return (_b = yield (lastCodeLensLs === null || lastCodeLensLs === void 0 ? void 0 : lastCodeLensLs.doCodeLensResolve(codeLens, token))) !== null && _b !== void 0 ? _b : codeLens;
140
- }));
141
- connection.onExecuteCommand((params) => __awaiter(this, void 0, void 0, function* () {
142
- if (params.command === embedded.showReferencesCommand
143
- && params.arguments) {
144
- const args = params.arguments;
145
- yield connection.sendNotification(protocol_1.ShowReferencesNotification.type, {
146
- textDocument: {
147
- uri: args[0],
148
- },
149
- position: args[1],
150
- references: args[2],
151
- });
152
- }
153
- }));
154
- connection.onCodeAction((params, token) => __awaiter(this, void 0, void 0, function* () {
155
- return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
156
- var _c, _d, _e;
127
+ });
128
+ });
129
+ connection.onCodeLensResolve(async (codeLens, token) => {
130
+ return await lastCodeLensLs?.doCodeLensResolve(codeLens, token) ?? codeLens;
131
+ });
132
+ connection.onCodeAction(async (params, token) => {
133
+ return worker(params.textDocument.uri, token, async (service) => {
157
134
  lastCodeActionLs = service;
158
- let codeActions = (_c = yield service.doCodeActions(params.textDocument.uri, params.range, params.context, token)) !== null && _c !== void 0 ? _c : [];
135
+ let codeActions = await service.doCodeActions(params.textDocument.uri, params.range, params.context, token) ?? [];
159
136
  for (const codeAction of codeActions) {
160
137
  if (codeAction.data && typeof codeAction.data === 'object') {
161
138
  codeAction.data.uri = params.textDocument.uri;
@@ -164,104 +141,102 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
164
141
  codeAction.data = { uri: params.textDocument.uri };
165
142
  }
166
143
  }
167
- if (!((_e = (_d = initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.codeAction) === null || _e === void 0 ? void 0 : _e.disabledSupport)) {
144
+ if (!initParams.capabilities.textDocument?.codeAction?.disabledSupport) {
168
145
  codeActions = codeActions.filter(codeAction => !codeAction.disabled);
169
146
  }
170
147
  return codeActions;
171
- }));
172
- }));
173
- connection.onCodeActionResolve((codeAction, token) => __awaiter(this, void 0, void 0, function* () {
174
- var _f;
175
- return (_f = yield lastCodeActionLs.doCodeActionResolve(codeAction, token)) !== null && _f !== void 0 ? _f : codeAction;
176
- }));
177
- connection.onReferences((params, token) => __awaiter(this, void 0, void 0, function* () {
148
+ });
149
+ });
150
+ connection.onCodeActionResolve(async (codeAction, token) => {
151
+ return await lastCodeActionLs.doCodeActionResolve(codeAction, token) ?? codeAction;
152
+ });
153
+ connection.onReferences(async (params, token) => {
178
154
  return worker(params.textDocument.uri, token, service => {
179
155
  return service.findReferences(params.textDocument.uri, params.position, token);
180
156
  });
181
- }));
182
- connection.onRequest(protocol_1.FindFileReferenceRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
157
+ });
158
+ connection.onRequest(protocol_1.FindFileReferenceRequest.type, async (params, token) => {
183
159
  return worker(params.textDocument.uri, token, service => {
184
160
  return service.findFileReferences(params.textDocument.uri, token);
185
161
  });
186
- }));
187
- connection.onImplementation((params, token) => __awaiter(this, void 0, void 0, function* () {
162
+ });
163
+ connection.onImplementation(async (params, token) => {
188
164
  return worker(params.textDocument.uri, token, service => {
189
165
  return service.findImplementations(params.textDocument.uri, params.position, token);
190
166
  });
191
- }));
192
- connection.onDefinition((params, token) => __awaiter(this, void 0, void 0, function* () {
167
+ });
168
+ connection.onDefinition(async (params, token) => {
193
169
  return worker(params.textDocument.uri, token, service => {
194
170
  return service.findDefinition(params.textDocument.uri, params.position, token);
195
171
  });
196
- }));
197
- connection.onTypeDefinition((params, token) => __awaiter(this, void 0, void 0, function* () {
172
+ });
173
+ connection.onTypeDefinition(async (params, token) => {
198
174
  return worker(params.textDocument.uri, token, service => {
199
175
  return service.findTypeDefinition(params.textDocument.uri, params.position, token);
200
176
  });
201
- }));
202
- connection.onDocumentHighlight((params, token) => __awaiter(this, void 0, void 0, function* () {
177
+ });
178
+ connection.onDocumentHighlight(async (params, token) => {
203
179
  return worker(params.textDocument.uri, token, service => {
204
180
  return service.findDocumentHighlights(params.textDocument.uri, params.position, token);
205
181
  });
206
- }));
207
- connection.onDocumentLinks((params, token) => __awaiter(this, void 0, void 0, function* () {
208
- return yield worker(params.textDocument.uri, token, service => {
182
+ });
183
+ connection.onDocumentLinks(async (params, token) => {
184
+ return await worker(params.textDocument.uri, token, service => {
185
+ lastDocumentLinkLs = service;
209
186
  return service.findDocumentLinks(params.textDocument.uri, token);
210
187
  });
211
- }));
212
- connection.onWorkspaceSymbol((params, token) => __awaiter(this, void 0, void 0, function* () {
188
+ });
189
+ connection.onDocumentLinkResolve(async (link, token) => {
190
+ return await lastDocumentLinkLs.doDocumentLinkResolve(link, token);
191
+ });
192
+ connection.onWorkspaceSymbol(async (params, token) => {
213
193
  let results = [];
214
194
  for (const _workspace of projects.workspaces.values()) {
215
- const workspace = yield _workspace;
195
+ const workspace = await _workspace;
216
196
  let projects = [...workspace.projects.values()];
217
197
  projects = projects.length ? projects : [workspace.getInferredProject()];
218
198
  for (const project of projects) {
219
199
  if (token.isCancellationRequested)
220
200
  return;
221
- const service = (yield project).getLanguageService();
222
- results = results.concat(yield service.findWorkspaceSymbols(params.query, token));
201
+ const service = (await project).getLanguageService();
202
+ results = results.concat(await service.findWorkspaceSymbols(params.query, token));
223
203
  }
224
204
  }
225
205
  return results;
226
- }));
227
- connection.languages.callHierarchy.onPrepare((params, token) => __awaiter(this, void 0, void 0, function* () {
228
- var _g;
229
- return (_g = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
206
+ });
207
+ connection.languages.callHierarchy.onPrepare(async (params, token) => {
208
+ return await worker(params.textDocument.uri, token, async (service) => {
230
209
  lastCallHierarchyLs = service;
231
210
  return service.callHierarchy.doPrepare(params.textDocument.uri, params.position, token);
232
- }))) !== null && _g !== void 0 ? _g : [];
233
- }));
234
- connection.languages.callHierarchy.onIncomingCalls((params, token) => __awaiter(this, void 0, void 0, function* () {
235
- var _h;
236
- return (_h = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getIncomingCalls(params.item, token))) !== null && _h !== void 0 ? _h : [];
237
- }));
238
- connection.languages.callHierarchy.onOutgoingCalls((params, token) => __awaiter(this, void 0, void 0, function* () {
239
- var _j;
240
- return (_j = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getOutgoingCalls(params.item, token))) !== null && _j !== void 0 ? _j : [];
241
- }));
242
- connection.languages.semanticTokens.on((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
243
- var _k;
244
- yield sleep(200);
245
- return (_k = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
246
- return yield (service === null || service === void 0 ? void 0 : service.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(tokens)));
247
- }))) !== null && _k !== void 0 ? _k : { data: [] };
248
- }));
249
- connection.languages.semanticTokens.onRange((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
250
- var _l;
251
- yield sleep(200);
252
- return (_l = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
253
- return yield (service === null || service === void 0 ? void 0 : service.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(tokens)));
254
- }))) !== null && _l !== void 0 ? _l : { data: [] };
255
- }));
256
- connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
257
- const result = yield worker(params.textDocument.uri, token, service => {
211
+ }) ?? [];
212
+ });
213
+ connection.languages.callHierarchy.onIncomingCalls(async (params, token) => {
214
+ return await lastCallHierarchyLs?.callHierarchy.getIncomingCalls(params.item, token) ?? [];
215
+ });
216
+ connection.languages.callHierarchy.onOutgoingCalls(async (params, token) => {
217
+ return await lastCallHierarchyLs?.callHierarchy.getOutgoingCalls(params.item, token) ?? [];
218
+ });
219
+ connection.languages.semanticTokens.on(async (params, token, _, resultProgress) => {
220
+ await sleep(200);
221
+ return await worker(params.textDocument.uri, token, async (service) => {
222
+ return await service?.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
223
+ }) ?? { data: [] };
224
+ });
225
+ connection.languages.semanticTokens.onRange(async (params, token, _, resultProgress) => {
226
+ await sleep(200);
227
+ return await worker(params.textDocument.uri, token, async (service) => {
228
+ return await service?.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
229
+ }) ?? { data: [] };
230
+ });
231
+ connection.languages.diagnostics.on(async (params, token, _workDoneProgressReporter, resultProgressReporter) => {
232
+ const result = await worker(params.textDocument.uri, token, service => {
258
233
  const tsToken = cancelHost.createCancellationToken(token);
259
234
  const mode = initOptions.serverMode === types_1.ServerMode.PartialSemantic ? 'semantic'
260
235
  : initOptions.serverMode === types_1.ServerMode.Syntactic ? 'syntactic'
261
236
  : 'all';
262
- return service.doValidation(params.textDocument.uri, tsToken, mode, errors => {
237
+ return service.doValidation(params.textDocument.uri, mode, tsToken, errors => {
263
238
  // resultProgressReporter is undefined in vscode
264
- resultProgressReporter === null || resultProgressReporter === void 0 ? void 0 : resultProgressReporter.report({
239
+ resultProgressReporter?.report({
265
240
  relatedDocuments: {
266
241
  [params.textDocument.uri]: {
267
242
  kind: vscode.DocumentDiagnosticReportKind.Full,
@@ -273,57 +248,58 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
273
248
  });
274
249
  return {
275
250
  kind: vscode.DocumentDiagnosticReportKind.Full,
276
- items: result !== null && result !== void 0 ? result : [],
251
+ items: result ?? [],
277
252
  };
278
- }));
279
- connection.languages.inlayHint.on((params, token) => __awaiter(this, void 0, void 0, function* () {
280
- return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
253
+ });
254
+ connection.languages.inlayHint.on(async (params, token) => {
255
+ return worker(params.textDocument.uri, token, async (service) => {
256
+ lastInlayHintLs = service;
281
257
  return service.getInlayHints(params.textDocument.uri, params.range, token);
282
- }));
283
- }));
284
- // TODO: connection.languages.inlayHint.resolve
285
- connection.workspace.onWillRenameFiles((params, token) => __awaiter(this, void 0, void 0, function* () {
286
- const config = yield connection.workspace.getConfiguration('volar.updateImportsOnFileMove.enabled');
258
+ });
259
+ });
260
+ connection.languages.inlayHint.resolve(async (hint, token) => {
261
+ return await lastInlayHintLs.doInlayHintResolve(hint, token);
262
+ });
263
+ connection.workspace.onWillRenameFiles(async (params, token) => {
264
+ const config = await connection.workspace.getConfiguration('volar.updateImportsOnFileMove.enabled');
287
265
  if (!config) {
288
266
  return null;
289
267
  }
290
- const _edits = yield Promise.all(params.files.map((file) => __awaiter(this, void 0, void 0, function* () {
291
- var _m;
292
- return (_m = yield worker(file.oldUri, token, service => {
293
- var _a;
294
- return (_a = service.getEditsForFileRename(file.oldUri, file.newUri, token)) !== null && _a !== void 0 ? _a : null;
295
- })) !== null && _m !== void 0 ? _m : null;
296
- })));
268
+ const _edits = await Promise.all(params.files.map(async (file) => {
269
+ return await worker(file.oldUri, token, service => {
270
+ return service.getEditsForFileRename(file.oldUri, file.newUri, token) ?? null;
271
+ }) ?? null;
272
+ }));
297
273
  const edits = _edits.filter((edit) => !!edit);
298
274
  if (edits.length) {
299
275
  embedded.mergeWorkspaceEdits(edits[0], ...edits.slice(1));
300
276
  return edits[0];
301
277
  }
302
278
  return null;
303
- }));
304
- connection.onRequest(protocol_1.AutoInsertRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
279
+ });
280
+ connection.onRequest(protocol_1.AutoInsertRequest.type, async (params, token) => {
305
281
  return worker(params.textDocument.uri, token, service => {
306
282
  return service.doAutoInsert(params.textDocument.uri, params.position, params.options, token);
307
283
  });
308
- }));
284
+ });
309
285
  function worker(uri, token, cb) {
310
286
  return new Promise(resolve => {
311
- runtime.timer.setImmediate(() => __awaiter(this, void 0, void 0, function* () {
287
+ runtime.timer.setImmediate(async () => {
312
288
  if (token.isCancellationRequested) {
313
289
  resolve(undefined);
314
290
  return;
315
291
  }
316
- const service = yield getLanguageService(uri);
292
+ const service = await getLanguageService(uri);
317
293
  if (service) {
318
294
  try { // handle TS cancel throw
319
- const result = yield cb(service);
295
+ const result = await cb(service);
320
296
  if (token.isCancellationRequested) {
321
297
  resolve(undefined);
322
298
  return;
323
299
  }
324
300
  resolve(result);
325
301
  }
326
- catch (_a) {
302
+ catch {
327
303
  resolve(undefined);
328
304
  return;
329
305
  }
@@ -331,19 +307,15 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
331
307
  else {
332
308
  resolve(undefined);
333
309
  }
334
- }));
310
+ });
335
311
  });
336
312
  }
337
- function getLanguageService(uri) {
338
- var _a;
339
- return __awaiter(this, void 0, void 0, function* () {
340
- const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
341
- return project === null || project === void 0 ? void 0 : project.getLanguageService();
342
- });
313
+ async function getLanguageService(uri) {
314
+ const project = (await projects.getProject(uri))?.project;
315
+ return project?.getLanguageService();
343
316
  }
344
317
  function fixTextEdit(item) {
345
- var _a, _b, _c, _d;
346
- const insertReplaceSupport = (_d = (_c = (_b = (_a = initParams.capabilities.textDocument) === null || _a === void 0 ? void 0 : _a.completion) === null || _b === void 0 ? void 0 : _b.completionItem) === null || _c === void 0 ? void 0 : _c.insertReplaceSupport) !== null && _d !== void 0 ? _d : false;
318
+ const insertReplaceSupport = initParams.capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport ?? false;
347
319
  if (!insertReplaceSupport) {
348
320
  if (item.textEdit && vscode.InsertReplaceEdit.is(item.textEdit)) {
349
321
  item.textEdit = vscode.TextEdit.replace(item.textEdit.insert, item.textEdit.newText);