@volar/language-core 2.2.0-alpha.0 → 2.2.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.
package/index.js CHANGED
@@ -142,6 +142,12 @@ function createLanguage(plugins, caseSensitive, sync) {
142
142
  exports.createLanguage = createLanguage;
143
143
  function updateVirtualCodeMapOfMap(virtualCode, mapOfMap, getSourceSnapshot) {
144
144
  const sources = new Set();
145
+ if (!virtualCode.mappings.length) {
146
+ const source = getSourceSnapshot(undefined);
147
+ if (source) {
148
+ mapOfMap.set(source[0], [source[1], new source_map_1.SourceMap([])]);
149
+ }
150
+ }
145
151
  for (const mapping of virtualCode.mappings) {
146
152
  if (sources.has(mapping.source)) {
147
153
  continue;
@@ -16,7 +16,7 @@ exports.isCodeLensEnabled = isCodeLensEnabled;
16
16
  function isSemanticTokensEnabled(info) {
17
17
  return typeof info.semantic === 'object'
18
18
  ? info.semantic.shouldHighlight?.() ?? true
19
- : info.semantic;
19
+ : !!info.semantic;
20
20
  }
21
21
  exports.isSemanticTokensEnabled = isSemanticTokensEnabled;
22
22
  function isCallHierarchyEnabled(info) {
@@ -48,27 +48,27 @@ function isHighlightEnabled(info) {
48
48
  }
49
49
  exports.isHighlightEnabled = isHighlightEnabled;
50
50
  function isSymbolsEnabled(info) {
51
- return info.structure;
51
+ return !!info.structure;
52
52
  }
53
53
  exports.isSymbolsEnabled = isSymbolsEnabled;
54
54
  function isFoldingRangesEnabled(info) {
55
- return info.structure;
55
+ return !!info.structure;
56
56
  }
57
57
  exports.isFoldingRangesEnabled = isFoldingRangesEnabled;
58
58
  function isSelectionRangesEnabled(info) {
59
- return info.structure;
59
+ return !!info.structure;
60
60
  }
61
61
  exports.isSelectionRangesEnabled = isSelectionRangesEnabled;
62
62
  function isLinkedEditingEnabled(info) {
63
- return info.structure;
63
+ return !!info.structure;
64
64
  }
65
65
  exports.isLinkedEditingEnabled = isLinkedEditingEnabled;
66
66
  function isColorEnabled(info) {
67
- return info.structure;
67
+ return !!info.structure;
68
68
  }
69
69
  exports.isColorEnabled = isColorEnabled;
70
70
  function isDocumentLinkEnabled(info) {
71
- return info.structure;
71
+ return !!info.structure;
72
72
  }
73
73
  exports.isDocumentLinkEnabled = isDocumentLinkEnabled;
74
74
  function isDiagnosticsEnabled(info) {
@@ -80,7 +80,7 @@ function isCodeActionsEnabled(info) {
80
80
  }
81
81
  exports.isCodeActionsEnabled = isCodeActionsEnabled;
82
82
  function isFormattingEnabled(info) {
83
- return info.format;
83
+ return !!info.format;
84
84
  }
85
85
  exports.isFormattingEnabled = isFormattingEnabled;
86
86
  function isCompletionEnabled(info) {
@@ -99,7 +99,7 @@ exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
99
99
  function shouldReportDiagnostics(info) {
100
100
  return typeof info.verification === 'object'
101
101
  ? info.verification.shouldReport?.() ?? true
102
- : info.verification;
102
+ : !!info.verification;
103
103
  }
104
104
  exports.shouldReportDiagnostics = shouldReportDiagnostics;
105
105
  // resolve...
@@ -0,0 +1,17 @@
1
+ import { SourceMap } from '@volar/source-map';
2
+ import type * as ts from 'typescript';
3
+ import { LinkedCodeMap } from './linkedCodeMap';
4
+ import type { CodeInformation, LanguagePlugin, SourceFile, VirtualCode } from './types';
5
+ export type FileRegistry = ReturnType<typeof createFileRegistry>;
6
+ export declare function createFileRegistry(languagePlugins: LanguagePlugin[], caseSensitive: boolean, sync: (id: string) => void): {
7
+ languagePlugins: LanguagePlugin<VirtualCode>[];
8
+ set(id: string, languageId: string, snapshot: ts.IScriptSnapshot, plugins?: LanguagePlugin<VirtualCode>[]): SourceFile;
9
+ delete(id: string): void;
10
+ get(id: string): SourceFile | undefined;
11
+ getByVirtualCode(virtualCode: VirtualCode): SourceFile;
12
+ getLinkedCodeMap(virtualCode: VirtualCode): LinkedCodeMap | undefined;
13
+ getMaps(virtualCode: VirtualCode): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
14
+ getVirtualCode(sourceFileId: string, virtualCodeId: string): readonly [VirtualCode, SourceFile] | readonly [undefined, undefined];
15
+ };
16
+ export declare function updateVirtualCodeMaps(virtualCode: VirtualCode, getSourceSnapshot: (sourceUri: string | undefined) => [string, ts.IScriptSnapshot] | undefined, map?: Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
17
+ export declare function forEachEmbeddedCode(code: VirtualCode): Generator<VirtualCode>;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.forEachEmbeddedCode = exports.updateVirtualCodeMaps = exports.createFileRegistry = void 0;
4
+ const source_map_1 = require("@volar/source-map");
5
+ const linkedCodeMap_1 = require("./linkedCodeMap");
6
+ const utils_1 = require("./utils");
7
+ function createFileRegistry(languagePlugins, caseSensitive, sync) {
8
+ const sourceFiles = new utils_1.FileMap(caseSensitive);
9
+ const virtualCodeToSourceFileMap = new WeakMap();
10
+ const virtualCodeToMaps = new WeakMap();
11
+ const virtualCodeToLinkedCodeMap = new WeakMap();
12
+ return {
13
+ languagePlugins,
14
+ set(id, languageId, snapshot, plugins = languagePlugins) {
15
+ const value = sourceFiles.get(id);
16
+ if (value) {
17
+ if (value.languageId !== languageId) {
18
+ // languageId changed
19
+ this.delete(id);
20
+ return this.set(id, languageId, snapshot);
21
+ }
22
+ else if (value.snapshot !== snapshot) {
23
+ // snapshot updated
24
+ value.snapshot = snapshot;
25
+ if (value.generated) {
26
+ value.generated.code = value.generated.languagePlugin.updateVirtualCode(id, value.generated.code, snapshot, this);
27
+ for (const code of forEachEmbeddedCode(value.generated.code)) {
28
+ virtualCodeToSourceFileMap.set(code, value);
29
+ }
30
+ }
31
+ return value;
32
+ }
33
+ else {
34
+ // not changed
35
+ return value;
36
+ }
37
+ }
38
+ // created
39
+ const sourceFile = { id, languageId, snapshot };
40
+ sourceFiles.set(id, sourceFile);
41
+ for (const languagePlugin of plugins) {
42
+ const virtualCode = languagePlugin.createVirtualCode(id, languageId, snapshot, this);
43
+ if (virtualCode) {
44
+ sourceFile.generated = {
45
+ code: virtualCode,
46
+ languagePlugin,
47
+ };
48
+ for (const code of forEachEmbeddedCode(virtualCode)) {
49
+ virtualCodeToSourceFileMap.set(code, sourceFile);
50
+ }
51
+ break;
52
+ }
53
+ }
54
+ return sourceFile;
55
+ },
56
+ delete(id) {
57
+ const value = sourceFiles.get(id);
58
+ if (value) {
59
+ if (value.generated) {
60
+ value.generated.languagePlugin.disposeVirtualCode?.(id, value.generated.code, this);
61
+ }
62
+ sourceFiles.delete(id);
63
+ }
64
+ },
65
+ get(id) {
66
+ sync(id);
67
+ return sourceFiles.get(id);
68
+ },
69
+ getByVirtualCode(virtualCode) {
70
+ return virtualCodeToSourceFileMap.get(virtualCode);
71
+ },
72
+ getLinkedCodeMap(virtualCode) {
73
+ if (!virtualCodeToLinkedCodeMap.has(virtualCode.snapshot)) {
74
+ virtualCodeToLinkedCodeMap.set(virtualCode.snapshot, virtualCode.linkedCodeMappings
75
+ ? new linkedCodeMap_1.LinkedCodeMap(virtualCode.linkedCodeMappings)
76
+ : undefined);
77
+ }
78
+ return virtualCodeToLinkedCodeMap.get(virtualCode.snapshot);
79
+ },
80
+ getMaps(virtualCode) {
81
+ if (!virtualCodeToMaps.has(virtualCode.snapshot)) {
82
+ virtualCodeToMaps.set(virtualCode.snapshot, new Map());
83
+ }
84
+ updateVirtualCodeMaps(virtualCode, sourceFileId => {
85
+ if (sourceFileId) {
86
+ const sourceFile = sourceFiles.get(sourceFileId);
87
+ return [sourceFileId, sourceFile.snapshot];
88
+ }
89
+ else {
90
+ const sourceFile = virtualCodeToSourceFileMap.get(virtualCode);
91
+ return [sourceFile.id, sourceFile.snapshot];
92
+ }
93
+ }, virtualCodeToMaps.get(virtualCode.snapshot));
94
+ return virtualCodeToMaps.get(virtualCode.snapshot);
95
+ },
96
+ getVirtualCode(sourceFileId, virtualCodeId) {
97
+ const sourceFile = this.get(sourceFileId);
98
+ if (sourceFile?.generated) {
99
+ for (const code of forEachEmbeddedCode(sourceFile.generated.code)) {
100
+ if (code.id === virtualCodeId) {
101
+ return [code, sourceFile];
102
+ }
103
+ }
104
+ }
105
+ return [undefined, undefined];
106
+ },
107
+ };
108
+ }
109
+ exports.createFileRegistry = createFileRegistry;
110
+ function updateVirtualCodeMaps(virtualCode, getSourceSnapshot, map = new Map()) {
111
+ const sources = new Set();
112
+ for (const mapping of virtualCode.mappings) {
113
+ if (sources.has(mapping.source)) {
114
+ continue;
115
+ }
116
+ sources.add(mapping.source);
117
+ const source = getSourceSnapshot(mapping.source);
118
+ if (!source) {
119
+ continue;
120
+ }
121
+ if (!map.has(source[0]) || map.get(source[0])[0] !== source[1]) {
122
+ map.set(source[0], [source[1], new source_map_1.SourceMap(virtualCode.mappings.filter(mapping2 => mapping2.source === mapping.source))]);
123
+ }
124
+ }
125
+ return map;
126
+ }
127
+ exports.updateVirtualCodeMaps = updateVirtualCodeMaps;
128
+ function* forEachEmbeddedCode(code) {
129
+ yield code;
130
+ if (code.embeddedCodes) {
131
+ for (const embeddedCode of code.embeddedCodes) {
132
+ yield* forEachEmbeddedCode(embeddedCode);
133
+ }
134
+ }
135
+ }
136
+ exports.forEachEmbeddedCode = forEachEmbeddedCode;
137
+ //# sourceMappingURL=fileRegistry.js.map
package/lib/types.d.ts CHANGED
@@ -46,28 +46,28 @@ export interface VirtualCode {
46
46
  }
47
47
  export interface CodeInformation {
48
48
  /** virtual code is expected to support verification */
49
- verification: boolean | {
49
+ verification?: boolean | {
50
50
  shouldReport?(): boolean;
51
51
  };
52
52
  /** virtual code is expected to support assisted completion */
53
- completion: boolean | {
53
+ completion?: boolean | {
54
54
  isAdditional?: boolean;
55
55
  onlyImport?: boolean;
56
56
  };
57
57
  /** virtual code is expected correctly reflect semantic of the source code */
58
- semantic: boolean | {
58
+ semantic?: boolean | {
59
59
  shouldHighlight?(): boolean;
60
60
  };
61
61
  /** virtual code is expected correctly reflect reference relationships of the source code */
62
- navigation: boolean | {
62
+ navigation?: boolean | {
63
63
  shouldRename?(): boolean;
64
64
  resolveRenameNewName?(newName: string): string;
65
65
  resolveRenameEditText?(newText: string): string;
66
66
  };
67
67
  /** virtual code is expected correctly reflect the structural information of the source code */
68
- structure: boolean;
68
+ structure?: boolean;
69
69
  /** virtual code is expected correctly reflect the format information of the source code */
70
- format: boolean;
70
+ format?: boolean;
71
71
  }
72
72
  export interface ServiceScript {
73
73
  code: VirtualCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-core",
3
- "version": "2.2.0-alpha.0",
3
+ "version": "2.2.0-alpha.10",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/source-map": "2.2.0-alpha.0"
15
+ "@volar/source-map": "2.2.0-alpha.10"
16
16
  },
17
- "gitHead": "95ffe51f944ee87f570be113541e17ddfe75f588"
17
+ "gitHead": "aedd2230883c457f703be93ed150917a3efde75c"
18
18
  }