@volar/language-service 2.4.0-alpha.8 → 2.4.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.
Files changed (60) hide show
  1. package/lib/features/provideAutoInsertSnippet.d.ts +2 -2
  2. package/lib/features/provideAutoInsertSnippet.js +1 -3
  3. package/lib/features/provideCallHierarchyItems.d.ts +5 -2
  4. package/lib/features/provideCallHierarchyItems.js +83 -8
  5. package/lib/features/provideCodeActions.d.ts +2 -2
  6. package/lib/features/provideCodeActions.js +1 -3
  7. package/lib/features/provideCodeLenses.d.ts +2 -2
  8. package/lib/features/provideCodeLenses.js +1 -3
  9. package/lib/features/provideColorPresentations.d.ts +2 -2
  10. package/lib/features/provideColorPresentations.js +1 -3
  11. package/lib/features/provideCompletionItems.d.ts +2 -2
  12. package/lib/features/provideCompletionItems.js +1 -2
  13. package/lib/features/provideDefinition.d.ts +2 -2
  14. package/lib/features/provideDefinition.js +1 -2
  15. package/lib/features/provideDiagnostics.d.ts +6 -6
  16. package/lib/features/provideDiagnostics.js +84 -81
  17. package/lib/features/provideDocumentColors.d.ts +2 -2
  18. package/lib/features/provideDocumentColors.js +1 -3
  19. package/lib/features/provideDocumentDropEdits.d.ts +2 -2
  20. package/lib/features/provideDocumentDropEdits.js +1 -3
  21. package/lib/features/provideDocumentFormattingEdits.d.ts +2 -2
  22. package/lib/features/provideDocumentFormattingEdits.js +1 -2
  23. package/lib/features/provideDocumentHighlights.d.ts +2 -2
  24. package/lib/features/provideDocumentHighlights.js +1 -2
  25. package/lib/features/provideDocumentLinks.d.ts +2 -2
  26. package/lib/features/provideDocumentLinks.js +1 -3
  27. package/lib/features/provideDocumentSemanticTokens.d.ts +2 -2
  28. package/lib/features/provideDocumentSemanticTokens.js +2 -4
  29. package/lib/features/provideDocumentSymbols.d.ts +2 -2
  30. package/lib/features/provideDocumentSymbols.js +1 -3
  31. package/lib/features/provideFileReferences.d.ts +2 -2
  32. package/lib/features/provideFileReferences.js +1 -2
  33. package/lib/features/provideFileRenameEdits.d.ts +2 -2
  34. package/lib/features/provideFileRenameEdits.js +1 -4
  35. package/lib/features/provideFoldingRanges.d.ts +2 -2
  36. package/lib/features/provideFoldingRanges.js +1 -3
  37. package/lib/features/provideHover.d.ts +2 -2
  38. package/lib/features/provideHover.js +1 -3
  39. package/lib/features/provideInlayHints.d.ts +2 -2
  40. package/lib/features/provideInlayHints.js +1 -3
  41. package/lib/features/provideInlineValue.d.ts +4 -0
  42. package/lib/features/provideInlineValue.js +30 -0
  43. package/lib/features/provideLinkedEditingRanges.d.ts +2 -2
  44. package/lib/features/provideLinkedEditingRanges.js +1 -3
  45. package/lib/features/provideMoniker.d.ts +4 -0
  46. package/lib/features/provideMoniker.js +17 -0
  47. package/lib/features/provideReferences.d.ts +2 -2
  48. package/lib/features/provideReferences.js +1 -2
  49. package/lib/features/provideRenameEdits.d.ts +2 -2
  50. package/lib/features/provideRenameEdits.js +1 -2
  51. package/lib/features/provideRenameRange.d.ts +2 -2
  52. package/lib/features/provideRenameRange.js +1 -3
  53. package/lib/features/provideSelectionRanges.d.ts +2 -2
  54. package/lib/features/provideSelectionRanges.js +1 -3
  55. package/lib/features/provideSignatureHelp.d.ts +2 -2
  56. package/lib/features/provideSignatureHelp.js +1 -3
  57. package/lib/languageService.d.ts +80 -68
  58. package/lib/languageService.js +17 -14
  59. package/lib/types.d.ts +14 -10
  60. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, selection: vscode.Position, change: {
3
+ import type { LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, selection: vscode.Position, change: {
5
5
  rangeOffset: number;
6
6
  rangeLength: number;
7
7
  text: string;
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const cancellation_1 = require("../utils/cancellation");
7
6
  const featureWorkers_1 = require("../utils/featureWorkers");
8
7
  function register(context) {
9
- return (_uri, selection, change, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
8
+ return (uri, selection, change, token = cancellation_1.NoneCancellationToken) => {
11
9
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => ({ selection, change }), function* (docs) {
12
10
  for (const mappedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, selection, language_core_1.isAutoInsertEnabled)) {
13
11
  for (const mapped of docs[2].toGeneratedLocation(change.rangeOffset)) {
@@ -1,6 +1,6 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
3
+ import type { LanguageServiceContext } from '../types';
4
4
  export interface PluginCallHierarchyData {
5
5
  uri: string;
6
6
  original: Pick<vscode.CallHierarchyItem, 'data'>;
@@ -8,7 +8,10 @@ export interface PluginCallHierarchyData {
8
8
  embeddedDocumentUri: string | undefined;
9
9
  }
10
10
  export declare function register(context: LanguageServiceContext): {
11
- getCallHierarchyItems(_uri: URI | UriComponents, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>;
11
+ getCallHierarchyItems(uri: URI, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>;
12
+ getTypeHierarchyItems(uri: URI, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
12
13
  getCallHierarchyIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyIncomingCall[]>;
13
14
  getCallHierarchyOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyOutgoingCall[]>;
15
+ getTypeHierarchySupertypes(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
16
+ getTypeHierarchySubtypes(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
14
17
  };
@@ -8,8 +8,7 @@ const dedupe = require("../utils/dedupe");
8
8
  const featureWorkers_1 = require("../utils/featureWorkers");
9
9
  function register(context) {
10
10
  return {
11
- getCallHierarchyItems(_uri, position, token = cancellation_1.NoneCancellationToken) {
12
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
11
+ getCallHierarchyItems(uri, position, token = cancellation_1.NoneCancellationToken) {
13
12
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, language_core_1.isCallHierarchyEnabled), async (plugin, document, position, map) => {
14
13
  if (token.isCancellationRequested) {
15
14
  return;
@@ -31,7 +30,33 @@ function register(context) {
31
30
  return data;
32
31
  }
33
32
  return data
34
- .map(item => transformCallHierarchyItem(item, [])?.[0])
33
+ .map(item => transformHierarchyItem(item, [])?.[0])
34
+ .filter(item => !!item);
35
+ }, arr => dedupe.withLocations(arr.flat()));
36
+ },
37
+ getTypeHierarchyItems(uri, position, token = cancellation_1.NoneCancellationToken) {
38
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, language_core_1.isTypeHierarchyEnabled), async (plugin, document, position, map) => {
39
+ if (token.isCancellationRequested) {
40
+ return;
41
+ }
42
+ const items = await plugin[1].provideTypeHierarchyItems?.(document, position, token);
43
+ items?.forEach(item => {
44
+ item.data = {
45
+ uri: uri.toString(),
46
+ original: {
47
+ data: item.data,
48
+ },
49
+ pluginIndex: context.plugins.indexOf(plugin),
50
+ embeddedDocumentUri: map?.[1].uri,
51
+ };
52
+ });
53
+ return items;
54
+ }, (data, map) => {
55
+ if (!map) {
56
+ return data;
57
+ }
58
+ return data
59
+ .map(item => transformHierarchyItem(item, [])?.[0])
35
60
  .filter(item => !!item);
36
61
  }, arr => dedupe.withLocations(arr.flat()));
37
62
  },
@@ -49,7 +74,7 @@ function register(context) {
49
74
  if (isEmbeddedContent) {
50
75
  const _calls = await plugin[1].provideCallHierarchyIncomingCalls(item, token);
51
76
  for (const _call of _calls) {
52
- const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
77
+ const calls = transformHierarchyItem(_call.from, _call.fromRanges);
53
78
  if (!calls) {
54
79
  continue;
55
80
  }
@@ -63,7 +88,7 @@ function register(context) {
63
88
  else {
64
89
  const _calls = await plugin[1].provideCallHierarchyIncomingCalls(item, token);
65
90
  for (const _call of _calls) {
66
- const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
91
+ const calls = transformHierarchyItem(_call.from, _call.fromRanges);
67
92
  if (!calls) {
68
93
  continue;
69
94
  }
@@ -90,7 +115,7 @@ function register(context) {
90
115
  if (isEmbeddedContent) {
91
116
  const _calls = await plugin[1].provideCallHierarchyOutgoingCalls(item, token);
92
117
  for (const call of _calls) {
93
- const calls = transformCallHierarchyItem(call.to, call.fromRanges);
118
+ const calls = transformHierarchyItem(call.to, call.fromRanges);
94
119
  if (!calls) {
95
120
  continue;
96
121
  }
@@ -104,7 +129,7 @@ function register(context) {
104
129
  else {
105
130
  const _calls = await plugin[1].provideCallHierarchyOutgoingCalls(item, token);
106
131
  for (const call of _calls) {
107
- const calls = transformCallHierarchyItem(call.to, call.fromRanges);
132
+ const calls = transformHierarchyItem(call.to, call.fromRanges);
108
133
  if (!calls) {
109
134
  continue;
110
135
  }
@@ -117,8 +142,58 @@ function register(context) {
117
142
  }
118
143
  return dedupe.withCallHierarchyOutgoingCalls(items);
119
144
  },
145
+ async getTypeHierarchySupertypes(item, token) {
146
+ const data = item.data;
147
+ if (data) {
148
+ const plugin = context.plugins[data.pluginIndex];
149
+ if (!plugin[1].provideTypeHierarchySupertypes) {
150
+ return [];
151
+ }
152
+ Object.assign(item, data.original);
153
+ if (data.embeddedDocumentUri) {
154
+ const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
155
+ if (isEmbeddedContent) {
156
+ const items = await plugin[1].provideTypeHierarchySupertypes(item, token);
157
+ return items
158
+ .map(item => transformHierarchyItem(item, [])?.[0])
159
+ .filter(item => !!item);
160
+ }
161
+ }
162
+ else {
163
+ const items = await plugin[1].provideTypeHierarchySupertypes(item, token);
164
+ return items
165
+ .map(item => transformHierarchyItem(item, [])?.[0])
166
+ .filter(item => !!item);
167
+ }
168
+ }
169
+ },
170
+ async getTypeHierarchySubtypes(item, token) {
171
+ const data = item.data;
172
+ if (data) {
173
+ const plugin = context.plugins[data.pluginIndex];
174
+ if (!plugin[1].provideTypeHierarchySubtypes) {
175
+ return [];
176
+ }
177
+ Object.assign(item, data.original);
178
+ if (data.embeddedDocumentUri) {
179
+ const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
180
+ if (isEmbeddedContent) {
181
+ const items = await plugin[1].provideTypeHierarchySubtypes(item, token);
182
+ return items
183
+ .map(item => transformHierarchyItem(item, [])?.[0])
184
+ .filter(item => !!item);
185
+ }
186
+ }
187
+ else {
188
+ const items = await plugin[1].provideTypeHierarchySubtypes(item, token);
189
+ return items
190
+ .map(item => transformHierarchyItem(item, [])?.[0])
191
+ .filter(item => !!item);
192
+ }
193
+ }
194
+ },
120
195
  };
121
- function transformCallHierarchyItem(tsItem, tsRanges) {
196
+ function transformHierarchyItem(tsItem, tsRanges) {
122
197
  const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(tsItem.uri));
123
198
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
124
199
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
@@ -1,10 +1,10 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
3
+ import type { LanguageServiceContext } from '../types';
4
4
  export interface ServiceCodeActionData {
5
5
  uri: string;
6
6
  version: number;
7
7
  original: Pick<vscode.CodeAction, 'data' | 'edit'>;
8
8
  pluginIndex: number;
9
9
  }
10
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, range: vscode.Range, codeActionContext: vscode.CodeActionContext, token?: vscode.CancellationToken) => Promise<vscode.CodeAction[] | undefined>;
10
+ export declare function register(context: LanguageServiceContext): (uri: URI, range: vscode.Range, codeActionContext: vscode.CodeActionContext, token?: vscode.CancellationToken) => Promise<vscode.CodeAction[] | undefined>;
@@ -2,15 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const cancellation_1 = require("../utils/cancellation");
7
6
  const common_1 = require("../utils/common");
8
7
  const dedupe = require("../utils/dedupe");
9
8
  const featureWorkers_1 = require("../utils/featureWorkers");
10
9
  const transform_1 = require("../utils/transform");
11
10
  function register(context) {
12
- return async (_uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
13
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
11
+ return async (uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
14
12
  const sourceScript = context.language.scripts.get(uri);
15
13
  if (!sourceScript) {
16
14
  return;
@@ -1,6 +1,6 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
3
+ import type { LanguageServiceContext } from '../types';
4
4
  export interface ServiceCodeLensData {
5
5
  kind: 'normal';
6
6
  uri: string;
@@ -14,4 +14,4 @@ export interface ServiceReferencesCodeLensData {
14
14
  workerFileRange: vscode.Range;
15
15
  pluginIndex: number;
16
16
  }
17
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, token?: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
17
+ export declare function register(context: LanguageServiceContext): (uri: URI, token?: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const cancellation_1 = require("../utils/cancellation");
7
6
  const featureWorkers_1 = require("../utils/featureWorkers");
8
7
  function register(context) {
9
- return async (_uri, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
8
+ return async (uri, token = cancellation_1.NoneCancellationToken) => {
11
9
  return await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isCodeLensEnabled)(mapping.data)), async (plugin, document) => {
12
10
  if (token.isCancellationRequested) {
13
11
  return;
@@ -1,4 +1,4 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
3
+ import type { LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const cancellation_1 = require("../utils/cancellation");
7
6
  const featureWorkers_1 = require("../utils/featureWorkers");
8
7
  function register(context) {
9
- return (_uri, color, range, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
8
+ return (uri, color, range, token = cancellation_1.NoneCancellationToken) => {
11
9
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => range, function* (docs) {
12
10
  for (const mappedRange of (0, featureWorkers_1.getGeneratedRanges)(docs, range, language_core_1.isColorEnabled)) {
13
11
  yield mappedRange;
@@ -1,10 +1,10 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
3
+ import type { LanguageServiceContext } from '../types';
4
4
  export interface ServiceCompletionData {
5
5
  uri: string;
6
6
  original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
7
7
  pluginIndex: number;
8
8
  embeddedDocumentUri: string | undefined;
9
9
  }
10
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
10
+ export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
@@ -8,8 +8,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
8
8
  const transform_1 = require("../utils/transform");
9
9
  function register(context) {
10
10
  let lastResult;
11
- return async (_uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
12
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
11
+ return async (uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
13
12
  let langaugeIdAndSnapshot;
14
13
  let sourceScript;
15
14
  const decoded = context.decodeEmbeddedDocumentUri(uri);
@@ -1,5 +1,5 @@
1
1
  import type { CodeInformation } from '@volar/language-core';
2
2
  import type * as vscode from 'vscode-languageserver-protocol';
3
3
  import { URI } from 'vscode-uri';
4
- import type { LanguageServiceContext, UriComponents } from '../types';
5
- export declare function register(context: LanguageServiceContext, apiName: 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidPosition: (data: CodeInformation) => boolean): (_uri: URI | UriComponents, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
4
+ import type { LanguageServiceContext } from '../types';
5
+ export declare function register(context: LanguageServiceContext, apiName: 'provideDeclaration' | 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidPosition: (data: CodeInformation) => boolean): (uri: URI, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
@@ -6,8 +6,7 @@ const cancellation_1 = require("../utils/cancellation");
6
6
  const dedupe = require("../utils/dedupe");
7
7
  const featureWorkers_1 = require("../utils/featureWorkers");
8
8
  function register(context, apiName, isValidPosition) {
9
- return (_uri, position, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
9
+ return (uri, position, token = cancellation_1.NoneCancellationToken) => {
11
10
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, isValidPosition), async (plugin, document, position) => {
12
11
  if (token.isCancellationRequested) {
13
12
  return;
@@ -1,12 +1,8 @@
1
1
  import { type CodeInformation } from '@volar/language-core';
2
2
  import type * as vscode from 'vscode-languageserver-protocol';
3
3
  import { URI } from 'vscode-uri';
4
- import type { LanguageServiceContext, UriComponents } from '../types';
4
+ import type { LanguageServiceContext } from '../types';
5
5
  import { DocumentsAndMap } from '../utils/featureWorkers';
6
- export declare function updateRange(range: vscode.Range, change: {
7
- range: vscode.Range;
8
- newEnd: vscode.Position;
9
- }): vscode.Range | undefined;
10
6
  export interface ServiceDiagnosticData {
11
7
  uri: string;
12
8
  version: number;
@@ -19,5 +15,9 @@ export declare const errorMarkups: Map<URI, {
19
15
  error: vscode.Diagnostic;
20
16
  markup: vscode.MarkupContent;
21
17
  }[]>;
22
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, token?: vscode.CancellationToken, response?: (result: vscode.Diagnostic[]) => void) => Promise<vscode.Diagnostic[]>;
18
+ export declare function register(context: LanguageServiceContext): (uri: URI, response?: (result: vscode.Diagnostic[]) => void, token?: vscode.CancellationToken) => Promise<vscode.Diagnostic[]>;
23
19
  export declare function transformDiagnostic(context: LanguageServiceContext, error: vscode.Diagnostic, docs: DocumentsAndMap | undefined, filter: (data: CodeInformation) => boolean): vscode.Diagnostic | undefined;
20
+ export declare function updateRange(range: vscode.Range, change: {
21
+ range: vscode.Range;
22
+ newEnd: vscode.Position;
23
+ }): vscode.Range | undefined;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorMarkups = void 0;
4
- exports.updateRange = updateRange;
5
4
  exports.register = register;
6
5
  exports.transformDiagnostic = transformDiagnostic;
6
+ exports.updateRange = updateRange;
7
7
  const language_core_1 = require("@volar/language-core");
8
8
  const vscode_uri_1 = require("vscode-uri");
9
9
  const cancellation_1 = require("../utils/cancellation");
@@ -11,77 +11,6 @@ const common_1 = require("../utils/common");
11
11
  const dedupe = require("../utils/dedupe");
12
12
  const featureWorkers_1 = require("../utils/featureWorkers");
13
13
  const uriMap_1 = require("../utils/uriMap");
14
- function updateRange(range, change) {
15
- if (!updatePosition(range.start, change, false)) {
16
- return;
17
- }
18
- if (!updatePosition(range.end, change, true)) {
19
- return;
20
- }
21
- if (range.end.line === range.start.line && range.end.character <= range.start.character) {
22
- range.end.character++;
23
- }
24
- return range;
25
- }
26
- function updatePosition(position, change, isEnd) {
27
- if (change.range.end.line > position.line) {
28
- if (change.newEnd.line > position.line) {
29
- // No change
30
- return true;
31
- }
32
- else if (change.newEnd.line === position.line) {
33
- position.character = Math.min(position.character, change.newEnd.character);
34
- return true;
35
- }
36
- else if (change.newEnd.line < position.line) {
37
- position.line = change.newEnd.line;
38
- position.character = change.newEnd.character;
39
- return true;
40
- }
41
- }
42
- else if (change.range.end.line === position.line) {
43
- const characterDiff = change.newEnd.character - change.range.end.character;
44
- if (position.character >= change.range.end.character) {
45
- if (change.newEnd.line !== change.range.end.line) {
46
- position.line = change.newEnd.line;
47
- position.character = change.newEnd.character + position.character - change.range.end.character;
48
- }
49
- else {
50
- if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
51
- position.character += characterDiff;
52
- }
53
- else {
54
- const offset = change.range.end.character - position.character;
55
- if (-characterDiff > offset) {
56
- position.character += characterDiff + offset;
57
- }
58
- }
59
- }
60
- return true;
61
- }
62
- else {
63
- if (change.newEnd.line === change.range.end.line) {
64
- const offset = change.range.end.character - position.character;
65
- if (-characterDiff > offset) {
66
- position.character += characterDiff + offset;
67
- }
68
- }
69
- else if (change.newEnd.line < change.range.end.line) {
70
- position.line = change.newEnd.line;
71
- position.character = change.newEnd.character;
72
- }
73
- else {
74
- // No change
75
- }
76
- return true;
77
- }
78
- }
79
- else if (change.range.end.line < position.line) {
80
- position.line += change.newEnd.line - change.range.end.line;
81
- return true;
82
- }
83
- return false;
84
- }
85
14
  exports.errorMarkups = (0, uriMap_1.createUriMap)();
86
15
  function register(context) {
87
16
  const lastResponses = (0, uriMap_1.createUriMap)();
@@ -94,8 +23,7 @@ function register(context) {
94
23
  cacheMaps.semantic.clear();
95
24
  cacheMaps.syntactic.clear();
96
25
  });
97
- return async (_uri, token = cancellation_1.NoneCancellationToken, response) => {
98
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
26
+ return async (uri, response, token = cancellation_1.NoneCancellationToken) => {
99
27
  let langaugeIdAndSnapshot;
100
28
  const decoded = context.decodeEmbeddedDocumentUri(uri);
101
29
  if (decoded) {
@@ -137,11 +65,11 @@ function register(context) {
137
65
  }
138
66
  }
139
67
  }
140
- await worker('provideDiagnostics', cacheMaps.syntactic, lastResponse.syntactic);
141
- await doResponse();
142
- await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
68
+ await worker('syntactic', cacheMaps.syntactic, lastResponse.syntactic);
69
+ processResponse();
70
+ await worker('semantic', cacheMaps.semantic, lastResponse.semantic);
143
71
  return collectErrors();
144
- function doResponse() {
72
+ function processResponse() {
145
73
  if (errorsUpdated && !updateCacheRangeFailed) {
146
74
  response?.(collectErrors());
147
75
  errorsUpdated = false;
@@ -150,8 +78,12 @@ function register(context) {
150
78
  function collectErrors() {
151
79
  return Object.values(lastResponse).flatMap(({ errors }) => errors);
152
80
  }
153
- async function worker(api, cacheMap, cache) {
81
+ async function worker(kind, cacheMap, cache) {
154
82
  const result = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)), async (plugin, document) => {
83
+ const interFileDependencies = plugin[0].capabilities.diagnosticProvider?.interFileDependencies;
84
+ if (kind === 'semantic' !== interFileDependencies) {
85
+ return;
86
+ }
155
87
  if (Date.now() - lastCheckCancelAt >= 10) {
156
88
  await (0, common_1.sleep)(10); // waiting LSP event polling
157
89
  lastCheckCancelAt = Date.now();
@@ -162,10 +94,10 @@ function register(context) {
162
94
  const pluginIndex = context.plugins.indexOf(plugin);
163
95
  const pluginCache = cacheMap.get(pluginIndex) ?? cacheMap.set(pluginIndex, new Map()).get(pluginIndex);
164
96
  const cache = pluginCache.get(document.uri);
165
- if (api !== 'provideSemanticDiagnostics' && cache && cache.documentVersion === document.version) {
97
+ if (!interFileDependencies && cache && cache.documentVersion === document.version) {
166
98
  return cache.errors;
167
99
  }
168
- const errors = await plugin[1][api]?.(document, token) || [];
100
+ const errors = await plugin[1].provideDiagnostics?.(document, token) || [];
169
101
  errors.forEach(error => {
170
102
  error.data = {
171
103
  uri: uri.toString(),
@@ -237,4 +169,75 @@ function transformDiagnostic(context, error, docs, filter) {
237
169
  }
238
170
  return _error;
239
171
  }
172
+ function updateRange(range, change) {
173
+ if (!updatePosition(range.start, change, false)) {
174
+ return;
175
+ }
176
+ if (!updatePosition(range.end, change, true)) {
177
+ return;
178
+ }
179
+ if (range.end.line === range.start.line && range.end.character <= range.start.character) {
180
+ range.end.character++;
181
+ }
182
+ return range;
183
+ }
184
+ function updatePosition(position, change, isEnd) {
185
+ if (change.range.end.line > position.line) {
186
+ if (change.newEnd.line > position.line) {
187
+ // No change
188
+ return true;
189
+ }
190
+ else if (change.newEnd.line === position.line) {
191
+ position.character = Math.min(position.character, change.newEnd.character);
192
+ return true;
193
+ }
194
+ else if (change.newEnd.line < position.line) {
195
+ position.line = change.newEnd.line;
196
+ position.character = change.newEnd.character;
197
+ return true;
198
+ }
199
+ }
200
+ else if (change.range.end.line === position.line) {
201
+ const characterDiff = change.newEnd.character - change.range.end.character;
202
+ if (position.character >= change.range.end.character) {
203
+ if (change.newEnd.line !== change.range.end.line) {
204
+ position.line = change.newEnd.line;
205
+ position.character = change.newEnd.character + position.character - change.range.end.character;
206
+ }
207
+ else {
208
+ if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
209
+ position.character += characterDiff;
210
+ }
211
+ else {
212
+ const offset = change.range.end.character - position.character;
213
+ if (-characterDiff > offset) {
214
+ position.character += characterDiff + offset;
215
+ }
216
+ }
217
+ }
218
+ return true;
219
+ }
220
+ else {
221
+ if (change.newEnd.line === change.range.end.line) {
222
+ const offset = change.range.end.character - position.character;
223
+ if (-characterDiff > offset) {
224
+ position.character += characterDiff + offset;
225
+ }
226
+ }
227
+ else if (change.newEnd.line < change.range.end.line) {
228
+ position.line = change.newEnd.line;
229
+ position.character = change.newEnd.character;
230
+ }
231
+ else {
232
+ // No change
233
+ }
234
+ return true;
235
+ }
236
+ }
237
+ else if (change.range.end.line < position.line) {
238
+ position.line += change.newEnd.line - change.range.end.line;
239
+ return true;
240
+ }
241
+ return false;
242
+ }
240
243
  //# sourceMappingURL=provideDiagnostics.js.map
@@ -1,4 +1,4 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, token?: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>;
3
+ import type { LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, token?: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>;
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
4
  const language_core_1 = require("@volar/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
5
  const cancellation_1 = require("../utils/cancellation");
7
6
  const featureWorkers_1 = require("../utils/featureWorkers");
8
7
  function register(context) {
9
- return (_uri, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
8
+ return (uri, token = cancellation_1.NoneCancellationToken) => {
11
9
  return (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isColorEnabled)(mapping.data)), (plugin, document) => {
12
10
  if (token.isCancellationRequested) {
13
11
  return;
@@ -1,4 +1,4 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { DataTransferItem, LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token?: vscode.CancellationToken) => Promise<import("../types").DocumentDropEdit | undefined>;
3
+ import type { DataTransferItem, LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token?: vscode.CancellationToken) => Promise<import("../types").DocumentDropEdit | undefined>;
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.register = register;
4
- const vscode_uri_1 = require("vscode-uri");
5
4
  const cancellation_1 = require("../utils/cancellation");
6
5
  const featureWorkers_1 = require("../utils/featureWorkers");
7
6
  const transform_1 = require("../utils/transform");
8
7
  function register(context) {
9
- return (_uri, position, dataTransfer, token = cancellation_1.NoneCancellationToken) => {
10
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
8
+ return (uri, position, dataTransfer, token = cancellation_1.NoneCancellationToken) => {
11
9
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, function* (docs) {
12
10
  for (const mappedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, position)) {
13
11
  yield mappedPosition;
@@ -1,7 +1,7 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, options: vscode.FormattingOptions, range: vscode.Range | undefined, onTypeParams: {
3
+ import type { LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, options: vscode.FormattingOptions, range: vscode.Range | undefined, onTypeParams: {
5
5
  ch: string;
6
6
  position: vscode.Position;
7
7
  } | undefined, token?: vscode.CancellationToken) => Promise<vscode.TextEdit[] | undefined>;
@@ -8,8 +8,7 @@ const cancellation_1 = require("../utils/cancellation");
8
8
  const common_1 = require("../utils/common");
9
9
  const featureWorkers_1 = require("../utils/featureWorkers");
10
10
  function register(context) {
11
- return async (_uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
12
- const uri = _uri instanceof vscode_uri_1.URI ? _uri : vscode_uri_1.URI.from(_uri);
11
+ return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
13
12
  const sourceScript = context.language.scripts.get(uri);
14
13
  if (!sourceScript) {
15
14
  return;
@@ -1,4 +1,4 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import { URI } from 'vscode-uri';
3
- import type { LanguageServiceContext, UriComponents } from '../types';
4
- export declare function register(context: LanguageServiceContext): (_uri: URI | UriComponents, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>;
3
+ import type { LanguageServiceContext } from '../types';
4
+ export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>;