@volar/language-server 1.2.0-alpha.9 → 1.3.0-alpha.0

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.
@@ -153,12 +153,16 @@ function createDocuments(connection) {
153
153
  const onDidChangeContents = new Set();
154
154
  const onDidCloses = new Set();
155
155
  connection.onDidOpenTextDocument(params => {
156
+ if (params.textDocument.uri.startsWith('git:/'))
157
+ return;
156
158
  snapshots.uriSet(params.textDocument.uri, new IncrementalScriptSnapshot(params.textDocument.uri, params.textDocument.languageId, params.textDocument.version, params.textDocument.text));
157
159
  for (const cb of onDidChangeContents) {
158
160
  cb({ textDocument: params.textDocument, contentChanges: [{ text: params.textDocument.text }] });
159
161
  }
160
162
  });
161
163
  connection.onDidChangeTextDocument(params => {
164
+ if (params.textDocument.uri.startsWith('git:/'))
165
+ return;
162
166
  const incrementalSnapshot = snapshots.uriGet(params.textDocument.uri);
163
167
  if (incrementalSnapshot) {
164
168
  if (params.contentChanges.every(vscode.TextDocumentContentChangeEvent.isIncremental)) {
@@ -181,6 +185,8 @@ function createDocuments(connection) {
181
185
  }
182
186
  });
183
187
  connection.onDidCloseTextDocument(params => {
188
+ if (params.textDocument.uri.startsWith('git:/'))
189
+ return;
184
190
  snapshots.uriDelete(params.textDocument.uri);
185
191
  for (const cb of onDidCloses) {
186
192
  cb(params);
@@ -71,14 +71,15 @@ function register(connection, projects) {
71
71
  }
72
72
  }));
73
73
  connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
74
- var _p, _q;
74
+ var _p, _q, _r;
75
75
  const project = yield projects.getProject(document.uri);
76
76
  const fileNames = [];
77
77
  if (project) {
78
78
  const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(shared.uriToFileName(document.uri))) === null || _q === void 0 ? void 0 : _q.root;
79
79
  if (rootVirtualFile) {
80
+ const kinds = (_r = document.fileKinds) !== null && _r !== void 0 ? _r : [language_core_1.FileKind.TypeScriptHostFile];
80
81
  (0, language_core_1.forEachEmbeddedFile)(rootVirtualFile, e => {
81
- if (e.snapshot.getLength() && e.kind === language_core_1.FileKind.TypeScriptHostFile && e.capabilities.diagnostic) {
82
+ if (e.snapshot.getLength() && kinds.includes(e.kind)) {
82
83
  fileNames.push(e.fileName);
83
84
  }
84
85
  });
@@ -87,15 +88,15 @@ function register(connection, projects) {
87
88
  return fileNames;
88
89
  }));
89
90
  connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
90
- var _r, _s, _t, _u;
91
+ var _s, _t, _u, _v;
91
92
  const project = yield projects.getProject(params.sourceFileUri);
92
93
  if (project) {
93
- const [virtualFile, source] = (_s = (_r = project.project) === null || _r === void 0 ? void 0 : _r.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName)) !== null && _s !== void 0 ? _s : [];
94
+ 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 : [];
94
95
  if (virtualFile && source) {
95
96
  const mappings = {};
96
97
  for (const mapping of virtualFile.mappings) {
97
- const sourceUri = shared.fileNameToUri((_t = mapping.source) !== null && _t !== void 0 ? _t : source.fileName);
98
- (_u = mappings[sourceUri]) !== null && _u !== void 0 ? _u : (mappings[sourceUri] = []);
98
+ const sourceUri = shared.fileNameToUri((_u = mapping.source) !== null && _u !== void 0 ? _u : source.fileName);
99
+ (_v = mappings[sourceUri]) !== null && _v !== void 0 ? _v : (mappings[sourceUri] = []);
99
100
  mappings[sourceUri].push(mapping);
100
101
  }
101
102
  return {
@@ -109,11 +110,11 @@ function register(connection, projects) {
109
110
  projects.reloadProject();
110
111
  });
111
112
  connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
112
- var _v;
113
+ var _w;
113
114
  const fs = yield Promise.resolve().then(() => require('fs'));
114
115
  const project = yield projects.getProject(params.uri);
115
116
  if (project) {
116
- const ls = (_v = (yield project.project)) === null || _v === void 0 ? void 0 : _v.getLanguageServiceDontCreate();
117
+ const ls = (_w = (yield project.project)) === null || _w === void 0 ? void 0 : _w.getLanguageServiceDontCreate();
117
118
  if (ls) {
118
119
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
119
120
  for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
@@ -1,5 +1,6 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import { CancellationTokenHost } from '../cancellationPipe';
3
3
  import type { Workspaces } from '../workspaces';
4
- import { RuntimeEnvironment } from '../../types';
5
- export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment): void;
4
+ import { RuntimeEnvironment, LanguageServerInitializationOptions } from '../../types';
5
+ import { createDocuments } from '../documents';
6
+ export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, initOptions: LanguageServerInitializationOptions, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment, documents: ReturnType<typeof createDocuments>): void;
@@ -13,7 +13,7 @@ const embedded = require("@volar/language-service");
13
13
  const vscode = require("vscode-languageserver");
14
14
  const protocol_1 = require("../../protocol");
15
15
  const shared = require("@volar/shared");
16
- function register(connection, projects, initParams, cancelHost, semanticTokensLegend, runtime) {
16
+ function register(connection, projects, initParams, initOptions, cancelHost, semanticTokensLegend, runtime, documents) {
17
17
  let lastCompleteUri;
18
18
  let lastCompleteLs;
19
19
  let lastCodeLensLs;
@@ -66,13 +66,37 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
66
66
  }));
67
67
  connection.onCompletion((params, token) => __awaiter(this, void 0, void 0, function* () {
68
68
  return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
69
+ var _a;
69
70
  lastCompleteUri = params.textDocument.uri;
70
71
  lastCompleteLs = service;
72
+ const document = (_a = documents.data.uriGet(params.textDocument.uri)) === null || _a === void 0 ? void 0 : _a.getDocument();
71
73
  const list = yield service.doComplete(params.textDocument.uri, params.position, params.context);
72
- if (list) {
73
- for (const item of list.items) {
74
- fixTextEdit(item);
75
- }
74
+ for (const item of list.items) {
75
+ fixTextEdit(item);
76
+ }
77
+ if (!initOptions.fullCompletionList && document) {
78
+ list.items = list.items.filter(item => {
79
+ var _a, _b;
80
+ const range = item.textEdit ? (vscode.InsertReplaceEdit.is(item.textEdit)
81
+ ? item.textEdit.replace
82
+ : item.textEdit.range) : ((_a = list.itemDefaults) === null || _a === void 0 ? void 0 : _a.editRange) ? (vscode.Range.is(list.itemDefaults.editRange)
83
+ ? list.itemDefaults.editRange
84
+ : list.itemDefaults.editRange.replace) : undefined;
85
+ if (range) {
86
+ const sourceText = document.getText(range).toLowerCase();
87
+ if (sourceText.trim()) {
88
+ let filterText = ((_b = item.filterText) !== null && _b !== void 0 ? _b : item.label).toLowerCase();
89
+ for (const char of sourceText) {
90
+ const index = filterText.indexOf(char);
91
+ if (index === -1) {
92
+ return false;
93
+ }
94
+ filterText = filterText.slice(index + 1);
95
+ }
96
+ }
97
+ }
98
+ return true;
99
+ });
76
100
  }
77
101
  return list;
78
102
  }));
@@ -111,8 +135,8 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
111
135
  }));
112
136
  }));
113
137
  connection.onCodeLensResolve((codeLens) => __awaiter(this, void 0, void 0, function* () {
114
- var _a;
115
- return (_a = yield (lastCodeLensLs === null || lastCodeLensLs === void 0 ? void 0 : lastCodeLensLs.doCodeLensResolve(codeLens))) !== null && _a !== void 0 ? _a : codeLens;
138
+ var _b;
139
+ return (_b = yield (lastCodeLensLs === null || lastCodeLensLs === void 0 ? void 0 : lastCodeLensLs.doCodeLensResolve(codeLens))) !== null && _b !== void 0 ? _b : codeLens;
116
140
  }));
117
141
  connection.onExecuteCommand((params) => __awaiter(this, void 0, void 0, function* () {
118
142
  if (params.command === embedded.showReferencesCommand
@@ -129,9 +153,9 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
129
153
  }));
130
154
  connection.onCodeAction((params, token) => __awaiter(this, void 0, void 0, function* () {
131
155
  return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
132
- var _b, _c, _d;
156
+ var _c, _d, _e;
133
157
  lastCodeActionLs = service;
134
- let codeActions = (_b = yield service.doCodeActions(params.textDocument.uri, params.range, params.context)) !== null && _b !== void 0 ? _b : [];
158
+ let codeActions = (_c = yield service.doCodeActions(params.textDocument.uri, params.range, params.context)) !== null && _c !== void 0 ? _c : [];
135
159
  for (const codeAction of codeActions) {
136
160
  if (codeAction.data && typeof codeAction.data === 'object') {
137
161
  codeAction.data.uri = params.textDocument.uri;
@@ -140,15 +164,15 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
140
164
  codeAction.data = { uri: params.textDocument.uri };
141
165
  }
142
166
  }
143
- if (!((_d = (_c = initParams.capabilities.textDocument) === null || _c === void 0 ? void 0 : _c.codeAction) === null || _d === void 0 ? void 0 : _d.disabledSupport)) {
167
+ if (!((_e = (_d = initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.codeAction) === null || _e === void 0 ? void 0 : _e.disabledSupport)) {
144
168
  codeActions = codeActions.filter(codeAction => !codeAction.disabled);
145
169
  }
146
170
  return codeActions;
147
171
  }));
148
172
  }));
149
173
  connection.onCodeActionResolve((codeAction) => __awaiter(this, void 0, void 0, function* () {
150
- var _e;
151
- return (_e = yield lastCodeActionLs.doCodeActionResolve(codeAction)) !== null && _e !== void 0 ? _e : codeAction;
174
+ var _f;
175
+ return (_f = yield lastCodeActionLs.doCodeActionResolve(codeAction)) !== null && _f !== void 0 ? _f : codeAction;
152
176
  }));
153
177
  connection.onReferences((params, token) => __awaiter(this, void 0, void 0, function* () {
154
178
  return worker(params.textDocument.uri, token, service => {
@@ -201,37 +225,37 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
201
225
  return results;
202
226
  }));
203
227
  connection.languages.callHierarchy.onPrepare((params, token) => __awaiter(this, void 0, void 0, function* () {
204
- var _f;
205
- return (_f = yield worker(params.textDocument.uri, token, (service) => __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
230
  lastCallHierarchyLs = service;
207
231
  return service.callHierarchy.doPrepare(params.textDocument.uri, params.position);
208
- }))) !== null && _f !== void 0 ? _f : [];
232
+ }))) !== null && _g !== void 0 ? _g : [];
209
233
  }));
210
234
  connection.languages.callHierarchy.onIncomingCalls((params) => __awaiter(this, void 0, void 0, function* () {
211
- var _g;
212
- return (_g = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getIncomingCalls(params.item))) !== null && _g !== void 0 ? _g : [];
235
+ var _h;
236
+ return (_h = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getIncomingCalls(params.item))) !== null && _h !== void 0 ? _h : [];
213
237
  }));
214
238
  connection.languages.callHierarchy.onOutgoingCalls((params) => __awaiter(this, void 0, void 0, function* () {
215
- var _h;
216
- return (_h = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getOutgoingCalls(params.item))) !== null && _h !== void 0 ? _h : [];
239
+ var _j;
240
+ return (_j = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getOutgoingCalls(params.item))) !== null && _j !== void 0 ? _j : [];
217
241
  }));
218
242
  connection.languages.semanticTokens.on((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
219
- var _j;
243
+ var _k;
220
244
  yield shared.sleep(200);
221
- return (_j = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
222
- var _k;
223
- const result = (_k = 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(buildTokens(tokens))))) !== null && _k !== void 0 ? _k : [];
245
+ return (_k = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
246
+ var _l;
247
+ const result = (_l = 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(buildTokens(tokens))))) !== null && _l !== void 0 ? _l : [];
224
248
  return buildTokens(result);
225
- }))) !== null && _j !== void 0 ? _j : buildTokens([]);
249
+ }))) !== null && _k !== void 0 ? _k : buildTokens([]);
226
250
  }));
227
251
  connection.languages.semanticTokens.onRange((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
228
- var _l;
252
+ var _m;
229
253
  yield shared.sleep(200);
230
- return (_l = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
231
- var _m;
232
- const result = (_m = 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(buildTokens(tokens))))) !== null && _m !== void 0 ? _m : [];
254
+ return (_m = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
255
+ var _o;
256
+ const result = (_o = 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(buildTokens(tokens))))) !== null && _o !== void 0 ? _o : [];
233
257
  return buildTokens(result);
234
- }))) !== null && _l !== void 0 ? _l : buildTokens([]);
258
+ }))) !== null && _m !== void 0 ? _m : buildTokens([]);
235
259
  }));
236
260
  connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
237
261
  const result = yield worker(params.textDocument.uri, token, service => {
@@ -265,11 +289,11 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
265
289
  return null;
266
290
  }
267
291
  const _edits = yield Promise.all(params.files.map((file) => __awaiter(this, void 0, void 0, function* () {
268
- var _o;
269
- return (_o = yield worker(file.oldUri, token, service => {
292
+ var _p;
293
+ return (_p = yield worker(file.oldUri, token, service => {
270
294
  var _a;
271
295
  return (_a = service.getEditsForFileRename(file.oldUri, file.newUri)) !== null && _a !== void 0 ? _a : null;
272
- })) !== null && _o !== void 0 ? _o : null;
296
+ })) !== null && _p !== void 0 ? _p : null;
273
297
  })));
274
298
  const edits = _edits.filter(shared.notEmpty);
275
299
  if (edits.length) {
@@ -59,6 +59,7 @@ export declare function createProject(context: ProjectContext): Promise<{
59
59
  };
60
60
  languageServiceHost: embedded.LanguageServiceHost;
61
61
  getLanguageService: () => {
62
+ triggerCharacters: string[];
62
63
  format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
63
64
  ch: string;
64
65
  position: embeddedLS.Position;
@@ -66,7 +67,7 @@ export declare function createProject(context: ProjectContext): Promise<{
66
67
  getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
67
68
  getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
68
69
  findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
69
- findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
70
+ findDocumentSymbols: (uri: string) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
70
71
  findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
71
72
  getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
72
73
  doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
@@ -89,7 +90,7 @@ export declare function createProject(context: ProjectContext): Promise<{
89
90
  doCodeLensResolve: (item: embeddedLS.CodeLens) => Promise<embeddedLS.CodeLens>;
90
91
  findDocumentHighlights: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
91
92
  findDocumentLinks: (uri: string) => Promise<embeddedLS.DocumentLink[]>;
92
- findWorkspaceSymbols: (query: string) => Promise<embeddedLS.SymbolInformation[]>;
93
+ findWorkspaceSymbols: (query: string) => Promise<embeddedLS.WorkspaceSymbol[]>;
93
94
  doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: {
94
95
  lastChange: {
95
96
  range: embeddedLS.Range;
@@ -108,6 +109,7 @@ export declare function createProject(context: ProjectContext): Promise<{
108
109
  context: embeddedLS.LanguageServicePluginContext;
109
110
  };
110
111
  getLanguageServiceDontCreate: () => {
112
+ triggerCharacters: string[];
111
113
  format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
112
114
  ch: string;
113
115
  position: embeddedLS.Position;
@@ -115,7 +117,7 @@ export declare function createProject(context: ProjectContext): Promise<{
115
117
  getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
116
118
  getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
117
119
  findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
118
- findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
120
+ findDocumentSymbols: (uri: string) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
119
121
  findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
120
122
  getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
121
123
  doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
@@ -138,7 +140,7 @@ export declare function createProject(context: ProjectContext): Promise<{
138
140
  doCodeLensResolve: (item: embeddedLS.CodeLens) => Promise<embeddedLS.CodeLens>;
139
141
  findDocumentHighlights: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
140
142
  findDocumentLinks: (uri: string) => Promise<embeddedLS.DocumentLink[]>;
141
- findWorkspaceSymbols: (query: string) => Promise<embeddedLS.SymbolInformation[]>;
143
+ findWorkspaceSymbols: (query: string) => Promise<embeddedLS.WorkspaceSymbol[]>;
142
144
  doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: {
143
145
  lastChange: {
144
146
  range: embeddedLS.Range;
@@ -127,7 +127,7 @@ function startCommonLanguageServer(context) {
127
127
  projects.add(root);
128
128
  }
129
129
  (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
130
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv);
130
+ (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
131
131
  for (const plugin of plugins) {
132
132
  (_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService);
133
133
  }