@volar/language-service 1.0.0-beta.1 → 1.0.0-beta.2

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.
Files changed (41) hide show
  1. package/out/baseDocumentService.js +1 -1
  2. package/out/baseLanguageService.d.ts +1 -1
  3. package/out/baseLanguageService.js +2 -2
  4. package/out/documentFeatures/autoInsert.js +2 -9
  5. package/out/documentFeatures/colorPresentations.js +7 -14
  6. package/out/documentFeatures/documentColors.js +1 -4
  7. package/out/documentFeatures/documentSymbols.js +3 -6
  8. package/out/documentFeatures/foldingRanges.js +1 -6
  9. package/out/documentFeatures/format.js +23 -30
  10. package/out/documentFeatures/linkedEditingRanges.js +2 -11
  11. package/out/documentFeatures/selectionRanges.js +3 -8
  12. package/out/documents.d.ts +23 -49
  13. package/out/documents.js +105 -73
  14. package/out/languageFeatures/autoInsert.js +20 -21
  15. package/out/languageFeatures/callHierarchy.js +17 -13
  16. package/out/languageFeatures/codeActions.js +10 -9
  17. package/out/languageFeatures/codeLens.js +1 -2
  18. package/out/languageFeatures/complete.js +11 -7
  19. package/out/languageFeatures/completeResolve.d.ts +1 -1
  20. package/out/languageFeatures/completeResolve.js +8 -8
  21. package/out/languageFeatures/definition.js +17 -20
  22. package/out/languageFeatures/documentHighlights.js +7 -10
  23. package/out/languageFeatures/documentLinks.js +4 -5
  24. package/out/languageFeatures/documentSemanticTokens.js +21 -23
  25. package/out/languageFeatures/executeCommand.d.ts +1 -1
  26. package/out/languageFeatures/executeCommand.js +1 -1
  27. package/out/languageFeatures/fileReferences.js +13 -11
  28. package/out/languageFeatures/fileRename.js +1 -1
  29. package/out/languageFeatures/hover.js +6 -13
  30. package/out/languageFeatures/inlayHints.js +12 -11
  31. package/out/languageFeatures/references.js +14 -13
  32. package/out/languageFeatures/rename.d.ts +0 -13
  33. package/out/languageFeatures/rename.js +49 -37
  34. package/out/languageFeatures/renamePrepare.js +6 -8
  35. package/out/languageFeatures/signatureHelp.js +1 -5
  36. package/out/languageFeatures/validation.js +31 -33
  37. package/out/languageFeatures/workspaceSymbols.js +9 -2
  38. package/out/plugin.d.ts +1 -1
  39. package/out/utils/featureWorkers.d.ts +2 -2
  40. package/out/utils/featureWorkers.js +1 -4
  41. package/package.json +7 -7
@@ -117,15 +117,15 @@ function register(context) {
117
117
  }
118
118
  let shouldSend = false;
119
119
  let lastCheckCancelAt = 0;
120
- yield worker(false, 'onFull', nonTsCache, cache.nonTs);
120
+ yield worker(0 /* EmbeddedFileKind.TextFile */, 'onFull', nonTsCache, cache.nonTs);
121
121
  doResponse();
122
- yield worker(true, 'onSyntactic', scriptTsCache_syntactic, cache.tsSyntactic);
122
+ yield worker(1 /* EmbeddedFileKind.TypeScriptHostFile */, 'onSyntactic', scriptTsCache_syntactic, cache.tsSyntactic);
123
123
  doResponse();
124
- yield worker(true, 'onSuggestion', scriptTsCache_suggestion, cache.tsSuggestion);
124
+ yield worker(1 /* EmbeddedFileKind.TypeScriptHostFile */, 'onSuggestion', scriptTsCache_suggestion, cache.tsSuggestion);
125
125
  doResponse();
126
- yield worker(true, 'onSemantic', scriptTsCache_semantic, cache.tsSemantic);
126
+ yield worker(1 /* EmbeddedFileKind.TypeScriptHostFile */, 'onSemantic', scriptTsCache_semantic, cache.tsSemantic);
127
127
  doResponse();
128
- yield worker(true, 'onDeclaration', scriptTsCache_declaration, cache.tsDeclaration);
128
+ yield worker(1 /* EmbeddedFileKind.TypeScriptHostFile */, 'onDeclaration', scriptTsCache_declaration, cache.tsDeclaration);
129
129
  return getErrors();
130
130
  function doResponse() {
131
131
  if (shouldSend) {
@@ -136,10 +136,10 @@ function register(context) {
136
136
  function getErrors() {
137
137
  return Object.values(cache).flatMap(({ errors }) => errors);
138
138
  }
139
- function worker(isTs, mode, cacheMap, cache) {
139
+ function worker(kind, mode, cacheMap, cache) {
140
140
  return __awaiter(this, void 0, void 0, function* () {
141
141
  const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, sourceMap) {
142
- if (sourceMap.embeddedFile.capabilities.diagnostics && sourceMap.embeddedFile.isTsHostFile === isTs) {
142
+ if (sourceMap.embeddedFile.capabilities.diagnostic && sourceMap.embeddedFile.kind === kind) {
143
143
  yield arg;
144
144
  }
145
145
  }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
@@ -153,13 +153,13 @@ function register(context) {
153
153
  return;
154
154
  }
155
155
  // avoid duplicate errors from vue plugin & typescript plugin
156
- if (isTsDocument(document) !== isTs)
156
+ if (isTsDocument(document) !== (kind === 1 /* EmbeddedFileKind.TypeScriptHostFile */))
157
157
  return;
158
158
  const pluginId = context.plugins.indexOf(plugin);
159
159
  const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
160
160
  const cache = pluginCache.get(document.uri);
161
- const tsProjectVersion = isTs ? (_c = (_b = context.core.typescriptLanguageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
162
- if (!isTs) {
161
+ const tsProjectVersion = kind === 1 /* EmbeddedFileKind.TypeScriptHostFile */ ? (_c = (_b = context.core.typescriptLanguageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
162
+ if (kind !== 1 /* EmbeddedFileKind.TypeScriptHostFile */) {
163
163
  if (cache && cache.documentVersion === document.version) {
164
164
  return cache.errors;
165
165
  }
@@ -193,37 +193,35 @@ function register(context) {
193
193
  }
194
194
  });
195
195
  function transformErrorRange(sourceMap, errors) {
196
- var _a, _b, _c;
197
196
  const result = [];
198
197
  for (const error of errors) {
199
- const _error = Object.assign({}, error);
198
+ // clone it to avoid modify cache
199
+ let _error = Object.assign({}, error);
200
200
  if (sourceMap) {
201
- let sourceRange = (_a = sourceMap.getSourceRange(error.range.start, error.range.end, data => !!data.diagnostic)) === null || _a === void 0 ? void 0 : _a[0];
202
- // fix https://github.com/johnsoncodehk/volar/issues/1205
203
- // fix https://github.com/johnsoncodehk/volar/issues/1264
204
- if (!sourceRange) {
205
- const start = (_b = sourceMap.getSourceRange(error.range.start, error.range.start, data => !!data.diagnostic)) === null || _b === void 0 ? void 0 : _b[0].start;
206
- const end = (_c = sourceMap.getSourceRange(error.range.end, error.range.end, data => !!data.diagnostic)) === null || _c === void 0 ? void 0 : _c[0].end;
207
- if (start && end) {
208
- sourceRange = { start, end };
209
- }
210
- }
211
- if (!sourceRange)
201
+ const range = sourceMap.toSourceRange(error.range, data => !!data.diagnostic);
202
+ if (!range) {
212
203
  continue;
213
- _error.range = sourceRange;
204
+ }
205
+ _error.range = range;
214
206
  }
215
207
  if (_error.relatedInformation) {
216
208
  const relatedInfos = [];
217
209
  for (const info of _error.relatedInformation) {
218
- for (const sourceLoc of context.documents.fromEmbeddedLocation(info.location.uri, info.location.range.start, info.location.range.end, data => !!data.diagnostic)) {
219
- relatedInfos.push({
220
- location: {
221
- uri: sourceLoc.uri,
222
- range: sourceLoc.range,
223
- },
224
- message: info.message,
225
- });
226
- break;
210
+ const map = context.documents.sourceMapFromEmbeddedDocumentUri(info.location.uri);
211
+ if (map) {
212
+ const range = map.toSourceRange(info.location.range, data => !!data.diagnostic);
213
+ if (range) {
214
+ relatedInfos.push({
215
+ location: {
216
+ uri: map.sourceDocument.uri,
217
+ range,
218
+ },
219
+ message: info.message,
220
+ });
221
+ }
222
+ }
223
+ else {
224
+ relatedInfos.push(info);
227
225
  }
228
226
  }
229
227
  _error.relatedInformation = relatedInfos;
@@ -21,8 +21,15 @@ function register(context) {
21
21
  if (!embeddedSymbols)
22
22
  continue;
23
23
  const symbols = (0, transforms_1.transformSymbolInformations)(embeddedSymbols, loc => {
24
- for (const vueLoc of context.documents.fromEmbeddedLocation(loc.uri, loc.range.start, loc.range.end)) {
25
- return vscode.Location.create(vueLoc.uri, vueLoc.range);
24
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(loc.uri);
25
+ if (sourceMap) {
26
+ const range = sourceMap.toSourceRange(loc.range);
27
+ if (range) {
28
+ return vscode.Location.create(sourceMap.sourceDocument.uri, range);
29
+ }
30
+ }
31
+ else {
32
+ return loc;
26
33
  }
27
34
  });
28
35
  symbolsList.push(symbols);
package/out/plugin.d.ts CHANGED
@@ -55,7 +55,7 @@ export interface LanguageServicePlugin {
55
55
  triggerCharacters?: string[];
56
56
  isAdditional?: boolean;
57
57
  on?(document: TextDocument, position: vscode.Position, context?: vscode.CompletionContext): NullableResult<vscode.CompletionList>;
58
- resolve?(item: vscode.CompletionItem, newPosition?: vscode.Position): NotNullableResult<vscode.CompletionItem>;
58
+ resolve?(item: vscode.CompletionItem): NotNullableResult<vscode.CompletionItem>;
59
59
  };
60
60
  rename?: {
61
61
  prepare?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Range | vscode.ResponseError<void>>;
@@ -2,6 +2,6 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
2
2
  import type { DocumentServiceRuntimeContext, LanguageServiceRuntimeContext } from '../types';
3
3
  import { LanguageServicePlugin } from '@volar/language-service';
4
4
  import { EmbeddedDocumentSourceMap, SourceFileDocument } from '../documents';
5
- export declare function documentFeatureWorker<T>(context: DocumentServiceRuntimeContext, document: TextDocument, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, worker: (plugin: LanguageServicePlugin, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
6
- export declare function documentArgFeatureWorker<T, K>(context: DocumentServiceRuntimeContext, document: TextDocument, arg: K, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | [K], worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
5
+ export declare function documentFeatureWorker<T>(context: DocumentServiceRuntimeContext, document: TextDocument, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, worker: (plugin: LanguageServicePlugin, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
6
+ export declare function documentArgFeatureWorker<T, K>(context: DocumentServiceRuntimeContext, document: TextDocument, arg: K, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | [K], worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
7
7
  export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | K[], worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K, sourceMap: EmbeddedDocumentSourceMap | undefined, vueDocument: SourceFileDocument | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
@@ -44,10 +44,7 @@ function documentArgFeatureWorker(context, document, arg, isValidSourceMap, tran
44
44
  if (results.length === 0 || !!combineResult) {
45
45
  context.prepareLanguageServices(document);
46
46
  for (const plugin of context.plugins) {
47
- const embeddedResult = yield worker(plugin, document, arg);
48
- if (!embeddedResult)
49
- continue;
50
- const result = yield transform(embeddedResult, undefined);
47
+ const result = yield worker(plugin, document, arg);
51
48
  if (!result)
52
49
  continue;
53
50
  results.push(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -16,11 +16,11 @@
16
16
  "typescript": "beta"
17
17
  },
18
18
  "dependencies": {
19
- "@volar/language-core": "1.0.0-beta.1",
20
- "@volar/shared": "1.0.0-beta.1",
21
- "@volar/source-map": "1.0.0-beta.1",
22
- "@volar/transforms": "1.0.0-beta.1",
23
- "@volar/typescript-faster": "1.0.0-beta.1",
19
+ "@volar/language-core": "1.0.0-beta.2",
20
+ "@volar/shared": "1.0.0-beta.2",
21
+ "@volar/source-map": "1.0.0-beta.2",
22
+ "@volar/transforms": "1.0.0-beta.2",
23
+ "@volar/typescript-faster": "1.0.0-beta.2",
24
24
  "@vue/reactivity": "^3.2.38",
25
25
  "upath": "^2.0.1",
26
26
  "vscode-html-languageservice": "^5.0.1",
@@ -29,5 +29,5 @@
29
29
  "vscode-languageserver-textdocument": "^1.0.7",
30
30
  "vscode-uri": "^3.0.3"
31
31
  },
32
- "gitHead": "3421929c584e8fafd772b2386c12ffe9b48355f2"
32
+ "gitHead": "a523013ad349e28c9d0a7d9ad3f0c0834e0067e7"
33
33
  }