@glint/ember-tsc 1.0.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 (181) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -0
  3. package/bin/ember-tsc.js +4 -0
  4. package/bin/glint-language-server.js +2 -0
  5. package/lib/cli/run-volar-tsc.d.ts +2 -0
  6. package/lib/cli/run-volar-tsc.d.ts.map +1 -0
  7. package/lib/cli/run-volar-tsc.js +30 -0
  8. package/lib/cli/run-volar-tsc.js.map +1 -0
  9. package/lib/config/config.d.ts +15 -0
  10. package/lib/config/config.d.ts.map +1 -0
  11. package/lib/config/config.js +21 -0
  12. package/lib/config/config.js.map +1 -0
  13. package/lib/config/environment.d.ts +26 -0
  14. package/lib/config/environment.d.ts.map +1 -0
  15. package/lib/config/environment.js +96 -0
  16. package/lib/config/environment.js.map +1 -0
  17. package/lib/config/index.d.ts +17 -0
  18. package/lib/config/index.d.ts.map +1 -0
  19. package/lib/config/index.js +26 -0
  20. package/lib/config/index.js.map +1 -0
  21. package/lib/config/loader.d.ts +25 -0
  22. package/lib/config/loader.d.ts.map +1 -0
  23. package/lib/config/loader.js +110 -0
  24. package/lib/config/loader.js.map +1 -0
  25. package/lib/config/types.cjs +3 -0
  26. package/lib/config/types.cjs.map +1 -0
  27. package/lib/config/types.d.cts +60 -0
  28. package/lib/config/types.d.cts.map +1 -0
  29. package/lib/environment-ember-template-imports/-private/environment/common.d.ts +13 -0
  30. package/lib/environment-ember-template-imports/-private/environment/common.d.ts.map +1 -0
  31. package/lib/environment-ember-template-imports/-private/environment/common.js +2 -0
  32. package/lib/environment-ember-template-imports/-private/environment/common.js.map +1 -0
  33. package/lib/environment-ember-template-imports/-private/environment/index.d.ts +3 -0
  34. package/lib/environment-ember-template-imports/-private/environment/index.d.ts.map +1 -0
  35. package/lib/environment-ember-template-imports/-private/environment/index.js +76 -0
  36. package/lib/environment-ember-template-imports/-private/environment/index.js.map +1 -0
  37. package/lib/environment-ember-template-imports/-private/environment/preprocess.d.ts +4 -0
  38. package/lib/environment-ember-template-imports/-private/environment/preprocess.d.ts.map +1 -0
  39. package/lib/environment-ember-template-imports/-private/environment/preprocess.js +73 -0
  40. package/lib/environment-ember-template-imports/-private/environment/preprocess.js.map +1 -0
  41. package/lib/environment-ember-template-imports/-private/environment/transform.d.ts +4 -0
  42. package/lib/environment-ember-template-imports/-private/environment/transform.d.ts.map +1 -0
  43. package/lib/environment-ember-template-imports/-private/environment/transform.js +134 -0
  44. package/lib/environment-ember-template-imports/-private/environment/transform.js.map +1 -0
  45. package/lib/index.d.ts +7 -0
  46. package/lib/index.d.ts.map +1 -0
  47. package/lib/index.js +6 -0
  48. package/lib/index.js.map +1 -0
  49. package/lib/plugins/g-compiler-errors.d.ts +12 -0
  50. package/lib/plugins/g-compiler-errors.d.ts.map +1 -0
  51. package/lib/plugins/g-compiler-errors.js +58 -0
  52. package/lib/plugins/g-compiler-errors.js.map +1 -0
  53. package/lib/plugins/g-template-tag-symbols.d.ts +11 -0
  54. package/lib/plugins/g-template-tag-symbols.d.ts.map +1 -0
  55. package/lib/plugins/g-template-tag-symbols.js +48 -0
  56. package/lib/plugins/g-template-tag-symbols.js.map +1 -0
  57. package/lib/plugins/utils.d.ts +25 -0
  58. package/lib/plugins/utils.d.ts.map +1 -0
  59. package/lib/plugins/utils.js +63 -0
  60. package/lib/plugins/utils.js.map +1 -0
  61. package/lib/transform/diagnostics/augmentation.d.ts +4 -0
  62. package/lib/transform/diagnostics/augmentation.d.ts.map +1 -0
  63. package/lib/transform/diagnostics/augmentation.js +223 -0
  64. package/lib/transform/diagnostics/augmentation.js.map +1 -0
  65. package/lib/transform/diagnostics/index.d.ts +5 -0
  66. package/lib/transform/diagnostics/index.d.ts.map +1 -0
  67. package/lib/transform/diagnostics/index.js +2 -0
  68. package/lib/transform/diagnostics/index.js.map +1 -0
  69. package/lib/transform/index.d.ts +4 -0
  70. package/lib/transform/index.d.ts.map +1 -0
  71. package/lib/transform/index.js +2 -0
  72. package/lib/transform/index.js.map +1 -0
  73. package/lib/transform/template/code-features.d.ts +30 -0
  74. package/lib/transform/template/code-features.d.ts.map +1 -0
  75. package/lib/transform/template/code-features.js +26 -0
  76. package/lib/transform/template/code-features.js.map +1 -0
  77. package/lib/transform/template/glimmer-ast-mapping-tree.d.ts +80 -0
  78. package/lib/transform/template/glimmer-ast-mapping-tree.d.ts.map +1 -0
  79. package/lib/transform/template/glimmer-ast-mapping-tree.js +132 -0
  80. package/lib/transform/template/glimmer-ast-mapping-tree.js.map +1 -0
  81. package/lib/transform/template/inlining/index.d.ts +16 -0
  82. package/lib/transform/template/inlining/index.d.ts.map +1 -0
  83. package/lib/transform/template/inlining/index.js +21 -0
  84. package/lib/transform/template/inlining/index.js.map +1 -0
  85. package/lib/transform/template/inlining/tagged-strings.d.ts +8 -0
  86. package/lib/transform/template/inlining/tagged-strings.d.ts.map +1 -0
  87. package/lib/transform/template/inlining/tagged-strings.js +140 -0
  88. package/lib/transform/template/inlining/tagged-strings.js.map +1 -0
  89. package/lib/transform/template/map-template-contents.d.ts +121 -0
  90. package/lib/transform/template/map-template-contents.d.ts.map +1 -0
  91. package/lib/transform/template/map-template-contents.js +287 -0
  92. package/lib/transform/template/map-template-contents.js.map +1 -0
  93. package/lib/transform/template/rewrite-module.d.ts +22 -0
  94. package/lib/transform/template/rewrite-module.d.ts.map +1 -0
  95. package/lib/transform/template/rewrite-module.js +265 -0
  96. package/lib/transform/template/rewrite-module.js.map +1 -0
  97. package/lib/transform/template/scope-stack.d.ts +13 -0
  98. package/lib/transform/template/scope-stack.d.ts.map +1 -0
  99. package/lib/transform/template/scope-stack.js +28 -0
  100. package/lib/transform/template/scope-stack.js.map +1 -0
  101. package/lib/transform/template/template-to-typescript.d.ts +19 -0
  102. package/lib/transform/template/template-to-typescript.d.ts.map +1 -0
  103. package/lib/transform/template/template-to-typescript.js +1095 -0
  104. package/lib/transform/template/template-to-typescript.js.map +1 -0
  105. package/lib/transform/template/transformed-module.d.ts +111 -0
  106. package/lib/transform/template/transformed-module.d.ts.map +1 -0
  107. package/lib/transform/template/transformed-module.js +287 -0
  108. package/lib/transform/template/transformed-module.js.map +1 -0
  109. package/lib/transform/util.d.ts +7 -0
  110. package/lib/transform/util.d.ts.map +1 -0
  111. package/lib/transform/util.js +15 -0
  112. package/lib/transform/util.js.map +1 -0
  113. package/lib/volar/ember-language-plugin.d.ts +14 -0
  114. package/lib/volar/ember-language-plugin.d.ts.map +1 -0
  115. package/lib/volar/ember-language-plugin.js +91 -0
  116. package/lib/volar/ember-language-plugin.js.map +1 -0
  117. package/lib/volar/gts-virtual-code.d.ts +83 -0
  118. package/lib/volar/gts-virtual-code.d.ts.map +1 -0
  119. package/lib/volar/gts-virtual-code.js +210 -0
  120. package/lib/volar/gts-virtual-code.js.map +1 -0
  121. package/lib/volar/language-server.d.ts +2 -0
  122. package/lib/volar/language-server.d.ts.map +1 -0
  123. package/lib/volar/language-server.js +214 -0
  124. package/lib/volar/language-server.js.map +1 -0
  125. package/lib/volar/script-snapshot.d.ts +17 -0
  126. package/lib/volar/script-snapshot.d.ts.map +1 -0
  127. package/lib/volar/script-snapshot.js +24 -0
  128. package/lib/volar/script-snapshot.js.map +1 -0
  129. package/package.json +104 -0
  130. package/src/cli/run-volar-tsc.ts +36 -0
  131. package/src/config/config.ts +33 -0
  132. package/src/config/environment.ts +128 -0
  133. package/src/config/index.ts +30 -0
  134. package/src/config/loader.ts +143 -0
  135. package/src/config/types.cts +85 -0
  136. package/src/environment-ember-template-imports/-private/environment/common.ts +14 -0
  137. package/src/environment-ember-template-imports/-private/environment/index.ts +83 -0
  138. package/src/environment-ember-template-imports/-private/environment/preprocess.ts +90 -0
  139. package/src/environment-ember-template-imports/-private/environment/transform.ts +202 -0
  140. package/src/index.ts +9 -0
  141. package/src/plugins/g-compiler-errors.ts +67 -0
  142. package/src/plugins/g-template-tag-symbols.ts +54 -0
  143. package/src/plugins/utils.ts +86 -0
  144. package/src/transform/diagnostics/augmentation.ts +333 -0
  145. package/src/transform/diagnostics/index.ts +5 -0
  146. package/src/transform/index.ts +4 -0
  147. package/src/transform/template/code-features.ts +30 -0
  148. package/src/transform/template/glimmer-ast-mapping-tree.ts +173 -0
  149. package/src/transform/template/inlining/index.ts +33 -0
  150. package/src/transform/template/inlining/tagged-strings.ts +187 -0
  151. package/src/transform/template/map-template-contents.ts +501 -0
  152. package/src/transform/template/rewrite-module.ts +372 -0
  153. package/src/transform/template/scope-stack.ts +34 -0
  154. package/src/transform/template/template-to-typescript.ts +1476 -0
  155. package/src/transform/template/transformed-module.ts +431 -0
  156. package/src/transform/util.ts +24 -0
  157. package/src/volar/ember-language-plugin.ts +108 -0
  158. package/src/volar/gts-virtual-code.ts +249 -0
  159. package/src/volar/language-server.ts +250 -0
  160. package/src/volar/script-snapshot.ts +27 -0
  161. package/types/-private/dsl/globals.d.ts +204 -0
  162. package/types/-private/dsl/index.d.ts +50 -0
  163. package/types/-private/dsl/integration-declarations.d.ts +143 -0
  164. package/types/-private/intrinsics/action.d.ts +45 -0
  165. package/types/-private/intrinsics/concat.d.ts +6 -0
  166. package/types/-private/intrinsics/each-in.d.ts +24 -0
  167. package/types/-private/intrinsics/each.d.ts +17 -0
  168. package/types/-private/intrinsics/fn.d.ts +44 -0
  169. package/types/-private/intrinsics/get.d.ts +31 -0
  170. package/types/-private/intrinsics/input.d.ts +24 -0
  171. package/types/-private/intrinsics/link-to.d.ts +31 -0
  172. package/types/-private/intrinsics/log.d.ts +6 -0
  173. package/types/-private/intrinsics/mount.d.ts +9 -0
  174. package/types/-private/intrinsics/mut.d.ts +14 -0
  175. package/types/-private/intrinsics/on.d.ts +21 -0
  176. package/types/-private/intrinsics/outlet.d.ts +8 -0
  177. package/types/-private/intrinsics/textarea.d.ts +16 -0
  178. package/types/-private/intrinsics/unbound.d.ts +10 -0
  179. package/types/-private/intrinsics/unique-id.d.ts +5 -0
  180. package/types/globals/index.d.ts +3 -0
  181. package/types/silent-error.d.ts +4 -0
@@ -0,0 +1,91 @@
1
+ import { VirtualGtsCode } from './gts-virtual-code.js';
2
+ /**
3
+ * Create a [Volar](https://volarjs.dev) language plugin to support
4
+ *
5
+ * - .gts/.gjs files (the `ember-template-imports` environment)
6
+ */
7
+ export function createEmberLanguagePlugin(glintConfig, { clientId } = {}) {
8
+ return {
9
+ /**
10
+ * For files that are not opened in the IDE, the language ID will not be provided
11
+ * to the language server, so a hook is needed to parse the language ID of files
12
+ * that are known extension but not opened in the IDE.
13
+ *
14
+ * In other words, clients like VSCode and other editors are in charge of determining
15
+ * the language ID and passing it in, but the language ID isn't available in other
16
+ * contexts, in which case this hook is called to determine it for a file based on its
17
+ * extension.
18
+ */
19
+ getLanguageId(fileNameOrUri) {
20
+ if (String(fileNameOrUri).endsWith('.gts')) {
21
+ return 'glimmer-ts';
22
+ }
23
+ if (String(fileNameOrUri).endsWith('.gjs')) {
24
+ return 'glimmer-js';
25
+ }
26
+ },
27
+ createVirtualCode(scriptId, languageId, snapshot, codegenContext) {
28
+ const scriptIdStr = String(scriptId);
29
+ if (languageId === 'glimmer-ts' ||
30
+ languageId === 'glimmer-js' ||
31
+ languageId === 'typescript.glimmer' ||
32
+ languageId === 'javascript.glimmer') {
33
+ return new VirtualGtsCode(glintConfig, snapshot, languageId, clientId);
34
+ }
35
+ },
36
+ typescript: {
37
+ extraFileExtensions: [
38
+ { extension: 'gts', isMixedContent: true, scriptKind: 7 },
39
+ { extension: 'gjs', isMixedContent: true, scriptKind: 7 },
40
+ ],
41
+ // Allow extension-less imports, e.g. `import Foo from './Foo`.
42
+ // Upstream Volar support for our extension-less use case was added here:
43
+ // https://github.com/volarjs/volar.js/pull/190
44
+ //
45
+ // NOTE: as of Mar 7, 2025, TS Plugin mode does not support extension-less imports.
46
+ // It's possible this could be fixed upstream but we should maybe not count on it.
47
+ //
48
+ // Tracking here: https://github.com/typed-ember/glint/issues/806
49
+ resolveHiddenExtensions: true,
50
+ // This is called when TS requests the file that we'll be typechecking, which in our case
51
+ // is the transformed Intermediate Representation of ths .gts with the <template> tags
52
+ // converted to type-checkable TS.
53
+ getServiceScript(rootVirtualCode) {
54
+ // The first embeddedCode is always the TS Intermediate Representation code
55
+ const transformedCode = rootVirtualCode.embeddedCodes?.[0];
56
+ if (!transformedCode) {
57
+ return;
58
+ }
59
+ switch (rootVirtualCode.languageId) {
60
+ case 'glimmer-ts':
61
+ case 'typescript.glimmer':
62
+ return {
63
+ code: transformedCode,
64
+ extension: '.ts',
65
+ scriptKind: 3,
66
+ };
67
+ case 'glimmer-js':
68
+ case 'javascript.glimmer':
69
+ return {
70
+ code: transformedCode,
71
+ extension: '.js',
72
+ scriptKind: 1,
73
+ };
74
+ default:
75
+ throw new Error(`getScript: Unexpected languageId: ${rootVirtualCode.languageId}`);
76
+ }
77
+ },
78
+ resolveLanguageServiceHost(host) {
79
+ return {
80
+ ...host,
81
+ getCompilationSettings: () => ({
82
+ ...host.getCompilationSettings(),
83
+ // Always allow JS for type checking.
84
+ allowJs: true,
85
+ }),
86
+ };
87
+ },
88
+ },
89
+ };
90
+ }
91
+ //# sourceMappingURL=ember-language-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ember-language-plugin.js","sourceRoot":"","sources":["../../src/volar/ember-language-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,WAAwB,EACxB,EAAE,QAAQ,KAA4B,EAAE;IAExC,OAAO;QACL;;;;;;;;;WASG;QACH,aAAa,CAAC,aAAa;YACzB,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3C,OAAO,YAAY,CAAC;YACtB,CAAC;YACD,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3C,OAAO,YAAY,CAAC;YACtB,CAAC;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S,EAAE,KAAK;4BAChB,UAAU,EAAE,CAA4B;yBACzC,CAAC;oBACJ;wBACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;gBACvF,CAAC;YACH,CAAC;YAED,0BAA0B,CAAC,IAAI;gBAC7B,OAAO;oBACL,GAAG,IAAI;oBACP,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;wBAC7B,GAAG,IAAI,CAAC,sBAAsB,EAAE;wBAChC,qCAAqC;wBACrC,OAAO,EAAE,IAAI;qBACd,CAAC;iBACH,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { CodeMapping, VirtualCode } from '@volar/language-core';
2
+ import type ts from 'typescript';
3
+ import { IScriptSnapshot } from 'typescript';
4
+ import { GlintConfig } from '../index.js';
5
+ import { Directive, rewriteModule } from '../transform/index.js';
6
+ export type TS = typeof ts;
7
+ interface EmbeddedCodeWithDirectives extends VirtualCode {
8
+ directives: readonly Directive[];
9
+ }
10
+ /**
11
+ * A Volar VirtualCode representing .gts/.gjs files, which includes 0+ embedded
12
+ * Handlebars templates within <template> tags.
13
+ *
14
+ * ## Virtual Code Overview (and how we use it)
15
+ *
16
+ * VirtualCodes are one of the most core/central primitives provided by Volar.
17
+ * They are:
18
+ *
19
+ * - Used both in (classic) Language Server mode and in newer TS Plugin mode
20
+ * - Responsible for parsing and transforming source code of a particular language (e.g. GTS)
21
+ * into embedded codes (e.g. a valid type-checkable TS file wherein all `<template>` tags
22
+ * have been replaced with valid TS code)
23
+ *
24
+ * ## Embedded Codes
25
+ *
26
+ * The VirtualCode interface has an `embeddedCodes` array that (typically) contains
27
+ * generated code based on the root virtual code file type (in our case, GTS). The generated
28
+ * embedded codes will typically have a different file type ID (e.g. `typescript`); Volar
29
+ * in turn can perform language processing on these specific files (e.g. generate diagnostics),
30
+ * and then propagate these diagnostics upwards to the root virtual code file. In order to do this,
31
+ * we need to provide source code mapping information so that Volar can correctly map the diagnostics
32
+ * back to the original source code.
33
+ *
34
+ * Note that "embedded code" can be somewhat of a confusing concept based on how familiar
35
+ * languages like HTML allow other languages (JS in script tags, CSS in style tags, etc.)
36
+ * to be embedded within a parent file (e.g. HTML). If you were building a VirtualCode for HTML,
37
+ * you would have an `embeddedCodes` array that contains VirtualCodes for the embedded languages,
38
+ * where each VirtualCode had the extracted HTML, CSS, JS, etc contents.
39
+ *
40
+ * But for GTS, the embedded code that we generate does not actually exist in the same form in
41
+ * the parent document (the .gts file); rather, the embedded code is a valid TS file that has
42
+ * been generated from the .gts by replacing all of the embedded `<template>`s with TS. Whereas
43
+ * for HTML, embedded codes are simple extracted strings of HTML, CSS, JS, etc, for GTS, the
44
+ * embedded code is a transformed file that's most likely much larger than the original .gts file.
45
+ *
46
+ * Additionally:
47
+ *
48
+ * - We always generate an embedded code of TypeScript even when the .gts file has no embedded templates
49
+ * (meaning it is already valid TS). This keeps both our code and the structure of our VirtualCode
50
+ * simple and consistent. In cases where there are no embedded templates, the embedded code contains
51
+ * the same contents as the root virtual code file.
52
+ *
53
+ * - Even when there are multiple <template> tags, we only generate 1 embedded TS code representing
54
+ * the TS code for all of the entire .gts file.
55
+ *
56
+ * - The Root VirtualCode we provide is simple the untransformed .gts file itself. This is a Volar
57
+ * convention and also allows for the possible of writing language service plugins that operate
58
+ * directly on .gts (i.e. `glimmer-ts`) files directly (rather than on an embedded code).
59
+ *
60
+ * In summary, `embeddedCodes` is a more general/abstract concept of ANY kind of language that
61
+ * is embedded or generated from the root virtual code file for the purposes of performing
62
+ * language service processing for the particular file type of the embedded code.
63
+ */
64
+ export declare class VirtualGtsCode implements VirtualCode {
65
+ private glintConfig;
66
+ snapshot: IScriptSnapshot;
67
+ languageId: 'glimmer-ts' | 'glimmer-js' | 'typescript.glimmer' | 'javascript.glimmer';
68
+ clientId?: string | undefined;
69
+ /**
70
+ * The virtual files embedded in the GTS file. (such as <template>)
71
+ */
72
+ embeddedCodes: EmbeddedCodeWithDirectives[];
73
+ /**
74
+ * The id is a unique (within the VirtualCode and its embedded files) id for Volar to identify it. It could be any string.
75
+ */
76
+ id: string;
77
+ mappings: CodeMapping[];
78
+ transformedModule: ReturnType<typeof rewriteModule> | null;
79
+ constructor(glintConfig: GlintConfig, snapshot: IScriptSnapshot, languageId: 'glimmer-ts' | 'glimmer-js' | 'typescript.glimmer' | 'javascript.glimmer', clientId?: string | undefined);
80
+ update(snapshot: IScriptSnapshot): void;
81
+ }
82
+ export {};
83
+ //# sourceMappingURL=gts-virtual-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gts-virtual-code.d.ts","sourceRoot":"","sources":["../../src/volar/gts-virtual-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEjE,MAAM,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;AAE3B,UAAU,0BAA2B,SAAQ,WAAW;IACtD,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,qBAAa,cAAe,YAAW,WAAW;IAgB9C,OAAO,CAAC,WAAW;IACZ,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,YAAY,GAAG,YAAY,GAAG,oBAAoB,GAAG,oBAAoB;IACrF,QAAQ,CAAC,EAAE,MAAM;IAlB1B;;OAEG;IACH,aAAa,EAAE,0BAA0B,EAAE,CAAM;IAEjD;;OAEG;IACH,EAAE,SAAS;IAEX,QAAQ,EAAE,WAAW,EAAE,CAAM;IAE7B,iBAAiB,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,GAAG,IAAI,CAAQ;gBAGxD,WAAW,EAAE,WAAW,EACzB,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,YAAY,GAAG,YAAY,GAAG,oBAAoB,GAAG,oBAAoB,EACrF,QAAQ,CAAC,EAAE,MAAM,YAAA;IAO1B,MAAM,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;CA4JxC"}
@@ -0,0 +1,210 @@
1
+ import { rewriteModule } from '../transform/index.js';
2
+ import { ScriptSnapshot } from './script-snapshot.js';
3
+ /**
4
+ * A Volar VirtualCode representing .gts/.gjs files, which includes 0+ embedded
5
+ * Handlebars templates within <template> tags.
6
+ *
7
+ * ## Virtual Code Overview (and how we use it)
8
+ *
9
+ * VirtualCodes are one of the most core/central primitives provided by Volar.
10
+ * They are:
11
+ *
12
+ * - Used both in (classic) Language Server mode and in newer TS Plugin mode
13
+ * - Responsible for parsing and transforming source code of a particular language (e.g. GTS)
14
+ * into embedded codes (e.g. a valid type-checkable TS file wherein all `<template>` tags
15
+ * have been replaced with valid TS code)
16
+ *
17
+ * ## Embedded Codes
18
+ *
19
+ * The VirtualCode interface has an `embeddedCodes` array that (typically) contains
20
+ * generated code based on the root virtual code file type (in our case, GTS). The generated
21
+ * embedded codes will typically have a different file type ID (e.g. `typescript`); Volar
22
+ * in turn can perform language processing on these specific files (e.g. generate diagnostics),
23
+ * and then propagate these diagnostics upwards to the root virtual code file. In order to do this,
24
+ * we need to provide source code mapping information so that Volar can correctly map the diagnostics
25
+ * back to the original source code.
26
+ *
27
+ * Note that "embedded code" can be somewhat of a confusing concept based on how familiar
28
+ * languages like HTML allow other languages (JS in script tags, CSS in style tags, etc.)
29
+ * to be embedded within a parent file (e.g. HTML). If you were building a VirtualCode for HTML,
30
+ * you would have an `embeddedCodes` array that contains VirtualCodes for the embedded languages,
31
+ * where each VirtualCode had the extracted HTML, CSS, JS, etc contents.
32
+ *
33
+ * But for GTS, the embedded code that we generate does not actually exist in the same form in
34
+ * the parent document (the .gts file); rather, the embedded code is a valid TS file that has
35
+ * been generated from the .gts by replacing all of the embedded `<template>`s with TS. Whereas
36
+ * for HTML, embedded codes are simple extracted strings of HTML, CSS, JS, etc, for GTS, the
37
+ * embedded code is a transformed file that's most likely much larger than the original .gts file.
38
+ *
39
+ * Additionally:
40
+ *
41
+ * - We always generate an embedded code of TypeScript even when the .gts file has no embedded templates
42
+ * (meaning it is already valid TS). This keeps both our code and the structure of our VirtualCode
43
+ * simple and consistent. In cases where there are no embedded templates, the embedded code contains
44
+ * the same contents as the root virtual code file.
45
+ *
46
+ * - Even when there are multiple <template> tags, we only generate 1 embedded TS code representing
47
+ * the TS code for all of the entire .gts file.
48
+ *
49
+ * - The Root VirtualCode we provide is simple the untransformed .gts file itself. This is a Volar
50
+ * convention and also allows for the possible of writing language service plugins that operate
51
+ * directly on .gts (i.e. `glimmer-ts`) files directly (rather than on an embedded code).
52
+ *
53
+ * In summary, `embeddedCodes` is a more general/abstract concept of ANY kind of language that
54
+ * is embedded or generated from the root virtual code file for the purposes of performing
55
+ * language service processing for the particular file type of the embedded code.
56
+ */
57
+ export class VirtualGtsCode {
58
+ constructor(glintConfig, snapshot, languageId, clientId) {
59
+ this.glintConfig = glintConfig;
60
+ this.snapshot = snapshot;
61
+ this.languageId = languageId;
62
+ this.clientId = clientId;
63
+ /**
64
+ * The virtual files embedded in the GTS file. (such as <template>)
65
+ */
66
+ this.embeddedCodes = [];
67
+ /**
68
+ * The id is a unique (within the VirtualCode and its embedded files) id for Volar to identify it. It could be any string.
69
+ */
70
+ this.id = 'gts';
71
+ this.mappings = [];
72
+ this.transformedModule = null;
73
+ this.update(snapshot);
74
+ }
75
+ // This gets called by the constructor and whenever the language server receives a file change event,
76
+ // i.e. the user saved the file.
77
+ update(snapshot) {
78
+ this.snapshot = snapshot;
79
+ const length = snapshot.getLength();
80
+ // The root virtual code is always the untransformed .gts file itself. (See docs/explanation
81
+ // at top of file for more details.) Therefore we declare a mapping that maps the entire
82
+ // contents of the source .gts to the identical "generated" .gts file (which is literally
83
+ // the same contents).
84
+ this.mappings[0] = {
85
+ // Map the entire length of the file from source to "generated"
86
+ sourceOffsets: [0],
87
+ generatedOffsets: [0],
88
+ lengths: [length],
89
+ // The `CodeInformation` specifies the capabilities / language feature enablements for the span
90
+ // of code covered by the mapping. Because this mapping covers the whole file, we are
91
+ // essentially controlling which language features are enabled for the entire .gts file,
92
+ // which ultimately determines whether Volar will pass the contents of this file to
93
+ // any number of the various language feature plugins supported by Volar.
94
+ data: {
95
+ // I have not personally vetted whether these should be disabled; we should revisit
96
+ // what specifically we actually need.
97
+ completion: true,
98
+ format: true,
99
+ navigation: true,
100
+ semantic: true,
101
+ structure: true,
102
+ // `verification: true` tells Volar to evaluate the root untransformed .gts file
103
+ // for diagnostics. Note that this only applies to diagnostics generated by the
104
+ // _Language Server_, and not the TS Plugin. The TS Plugin only performs
105
+ // type-checking a specific TypeScript embedded code, i.e. the TS code
106
+ // containing the transformed representation of our .gts file. Search `getServiceScript`
107
+ // for where this embedded code selection occurs.
108
+ //
109
+ // @GLINT_FEATURE_DIAGNOSTICS
110
+ // @GLINT_FEATURE_DIAGNOSTICS_LANGUAGE_SERVER
111
+ // @GLINT_FEATURE_DIAGNOSTICS_LANGUAGE_SERVER_GTS_COMPILER_ERRORS
112
+ verification: true,
113
+ },
114
+ };
115
+ const contents = snapshot.getText(0, length);
116
+ const isJavascript = this.languageId === 'glimmer-js' || this.languageId === 'javascript.glimmer';
117
+ const embeddedLanguageId = isJavascript ? 'javascript' : 'typescript';
118
+ const filename = isJavascript ? 'root.gjs' : 'root.gts';
119
+ let script = { filename, contents };
120
+ const transformedModule = rewriteModule(this.glintConfig.ts, { script }, this.glintConfig.environment, this.clientId);
121
+ this.transformedModule = transformedModule;
122
+ if (transformedModule) {
123
+ // .gts file has embedded templates, so lets generate a new embedded code
124
+ // that contains the transformed TS code.
125
+ const mappings = transformedModule.toVolarMappings();
126
+ const embeddedCodes = [
127
+ {
128
+ embeddedCodes: [],
129
+ id: 'template_ts',
130
+ languageId: embeddedLanguageId,
131
+ mappings,
132
+ snapshot: new ScriptSnapshot(transformedModule.transformedContents),
133
+ directives: transformedModule.directives,
134
+ },
135
+ ];
136
+ // Add an embedded code for each <template> tag in the .gts file
137
+ // so that the HTML Language Service can kick in and provide symbols
138
+ // and other functionality.
139
+ transformedModule.correlatedSpans.forEach((span, index) => {
140
+ if (!span.glimmerAstMapping) {
141
+ return;
142
+ }
143
+ const openTemplateTagLength = 10; // "<template>"
144
+ const closeTemplateTagLength = 11; // "</template>"
145
+ embeddedCodes.push({
146
+ embeddedCodes: [],
147
+ id: `template_html_${index}`,
148
+ languageId: 'html', // technically this is 'handlebars' but 'html' causes the HTML Language Service to kick in
149
+ mappings: [
150
+ {
151
+ sourceOffsets: [span.originalStart + openTemplateTagLength],
152
+ generatedOffsets: [0],
153
+ lengths: [span.originalLength - openTemplateTagLength - closeTemplateTagLength],
154
+ data: {
155
+ completion: true,
156
+ format: true,
157
+ navigation: true,
158
+ semantic: true,
159
+ structure: true,
160
+ verification: false,
161
+ },
162
+ },
163
+ ],
164
+ snapshot: new ScriptSnapshot(contents.slice(span.originalStart + openTemplateTagLength, span.originalStart + span.originalLength - closeTemplateTagLength)),
165
+ directives: [],
166
+ });
167
+ });
168
+ this.embeddedCodes = embeddedCodes;
169
+ }
170
+ else {
171
+ // Null transformed module means there's no embedded HBS templates,
172
+ // so just return a full "no-op" mapping from source to transformed.
173
+ //
174
+ // Note that this does mean that both the root virtual code and this embedded
175
+ // code we generate have the same contents, but we will configure the
176
+ // CodeInformation below differently than we do above to enable type-checking
177
+ // on the embedded code. While this might seem a bit wasteful/confusing to have
178
+ // root and embedded code essentially point to the same document, it keeps the
179
+ // structure clean, simple, and consistent, rather than, say, changing the structure
180
+ // of our VirtualCode only in the case of .gts files without embedded templates.
181
+ this.embeddedCodes = [
182
+ {
183
+ embeddedCodes: [],
184
+ id: 'template_ts',
185
+ languageId: embeddedLanguageId,
186
+ mappings: [
187
+ {
188
+ // Hacked hardwired values for now.
189
+ sourceOffsets: [0],
190
+ generatedOffsets: [0],
191
+ lengths: [length],
192
+ data: {
193
+ completion: true,
194
+ format: false,
195
+ navigation: true,
196
+ semantic: true,
197
+ structure: true,
198
+ // Unlike the root virtual code, we enable verification (which enables TS type-checking).
199
+ verification: true,
200
+ },
201
+ },
202
+ ],
203
+ snapshot: new ScriptSnapshot(contents),
204
+ directives: [],
205
+ },
206
+ ];
207
+ }
208
+ }
209
+ }
210
+ //# sourceMappingURL=gts-virtual-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gts-virtual-code.js","sourceRoot":"","sources":["../../src/volar/gts-virtual-code.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,OAAO,cAAc;IAezB,YACU,WAAwB,EACzB,QAAyB,EACzB,UAAqF,EACrF,QAAiB;QAHhB,gBAAW,GAAX,WAAW,CAAa;QACzB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,eAAU,GAAV,UAAU,CAA2E;QACrF,aAAQ,GAAR,QAAQ,CAAS;QAlB1B;;WAEG;QACH,kBAAa,GAAiC,EAAE,CAAC;QAEjD;;WAEG;QACH,OAAE,GAAG,KAAK,CAAC;QAEX,aAAQ,GAAkB,EAAE,CAAC;QAE7B,sBAAiB,GAA4C,IAAI,CAAC;QAQhE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;IAED,qGAAqG;IACrG,gCAAgC;IAChC,MAAM,CAAC,QAAyB;QAC9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,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"","sources":["../../src/volar/language-server.ts"],"names":[],"mappings":""}
@@ -0,0 +1,214 @@
1
+ import { createLanguage } from '@volar/language-core';
2
+ import { createLanguageServiceEnvironment } from '@volar/language-server/lib/project/simpleProject.js';
3
+ import { createConnection, createServer } from '@volar/language-server/node.js';
4
+ import { createLanguageService, createUriMap } from '@volar/language-service';
5
+ import * as ts from 'typescript';
6
+ import { create as createHtmlSyntacticPlugin } from 'volar-service-html';
7
+ import { create as createTypeScriptSyntacticPlugin } from 'volar-service-typescript/lib/plugins/syntactic.js';
8
+ import { URI } from 'vscode-uri';
9
+ import { ConfigLoader } from '../config/loader.js';
10
+ import { create as createCompilerErrorsPlugin } from '../plugins/g-compiler-errors.js';
11
+ import { create as createTemplateTagSymbolsPlugin } from '../plugins/g-template-tag-symbols.js';
12
+ import { createEmberLanguagePlugin } from './ember-language-plugin.js';
13
+ const connection = createConnection();
14
+ const server = createServer(connection);
15
+ const tsserverRequestHandlers = new Map();
16
+ let tsserverRequestId = 0;
17
+ connection.listen();
18
+ connection.onNotification('tsserver/response', ([id, res]) => {
19
+ tsserverRequestHandlers.get(id)?.(res);
20
+ tsserverRequestHandlers.delete(id);
21
+ });
22
+ /**
23
+ * Handle the `initialize` request from the client. This is the first request sent by the client to
24
+ * the server. It includes the set of capabilities supported by the client as well as
25
+ * other initialization params needed by the server.
26
+ */
27
+ connection.onInitialize((params) => {
28
+ const tsconfigProjects = createUriMap();
29
+ server.fileWatcher.onDidChangeWatchedFiles((obj) => {
30
+ for (const change of obj.changes) {
31
+ const changeUri = URI.parse(change.uri);
32
+ if (tsconfigProjects.has(changeUri)) {
33
+ tsconfigProjects.get(changeUri).dispose();
34
+ tsconfigProjects.delete(changeUri);
35
+ }
36
+ }
37
+ });
38
+ let simpleLs;
39
+ return server.initialize(params, {
40
+ setup() { },
41
+ async getLanguageService(uri) {
42
+ if (uri.scheme === 'file') {
43
+ // Use tsserver to find the tsconfig governing this file.
44
+ const fileName = uri.fsPath.replace(/\\/g, '/');
45
+ const projectInfo = await sendTsServerRequest('_glint:' + ts.server.protocol.CommandTypes.ProjectInfo, {
46
+ file: fileName,
47
+ needFileNameList: false,
48
+ });
49
+ if (projectInfo) {
50
+ const { configFileName } = projectInfo;
51
+ let ls = tsconfigProjects.get(URI.file(configFileName));
52
+ if (!ls) {
53
+ ls = createLanguageServiceHelper(server, configFileName);
54
+ tsconfigProjects.set(URI.file(configFileName), ls);
55
+ }
56
+ return ls;
57
+ }
58
+ }
59
+ // TODO: this branch is hit when running Volar Labs and currently breaks. Figure out
60
+ // how to reinstate a "simple" LS without a tsconfig.
61
+ return (simpleLs ?? (simpleLs = createLanguageServiceHelper(server, undefined)));
62
+ },
63
+ getExistingLanguageServices() {
64
+ return Promise.all([...tsconfigProjects.values(), simpleLs].filter((promise) => !!promise));
65
+ },
66
+ reload() {
67
+ for (const ls of [...tsconfigProjects.values(), simpleLs]) {
68
+ ls?.dispose();
69
+ }
70
+ tsconfigProjects.clear();
71
+ simpleLs = undefined;
72
+ },
73
+ }, getHybridModeLanguageServicePluginsForLanguageServer({
74
+ // TODO: Implement Glint-specific tsserver requests similar to Vue
75
+ // For now, keeping the basic structure ready for future implementation
76
+ // getQuickInfoAtPosition(...args) {
77
+ // return sendTsServerRequest('_glint:quickinfo', args);
78
+ // },
79
+ // getDocumentHighlights(...args) {
80
+ // return sendTsServerRequest('_glint:documentHighlights-full', args);
81
+ // },
82
+ // getEncodedSemanticClassifications(...args) {
83
+ // return sendTsServerRequest('_glint:encodedSemanticClassifications-full', args);
84
+ // },
85
+ }));
86
+ async function sendTsServerRequest(command, args) {
87
+ return await new Promise((resolve) => {
88
+ const requestId = ++tsserverRequestId;
89
+ tsserverRequestHandlers.set(requestId, resolve);
90
+ connection.sendNotification('tsserver/request', [requestId, command, args]);
91
+ });
92
+ }
93
+ function createLanguageServiceHelper(server, tsconfigFileName) {
94
+ const languagePlugins = [
95
+ {
96
+ getLanguageId: (uri) => server.documents.get(uri)?.languageId,
97
+ },
98
+ ];
99
+ if (tsconfigFileName) {
100
+ const configLoader = new ConfigLoader();
101
+ const glintConfig = configLoader.configForFile(tsconfigFileName);
102
+ if (glintConfig) {
103
+ const emberLanguagePlugin = createEmberLanguagePlugin(glintConfig);
104
+ languagePlugins.push(emberLanguagePlugin);
105
+ }
106
+ }
107
+ const language = createLanguage(languagePlugins, createUriMap(), (uri) => {
108
+ const document = server.documents.get(uri);
109
+ if (document) {
110
+ language.scripts.set(uri, document.getSnapshot(), document.languageId);
111
+ }
112
+ else {
113
+ language.scripts.delete(uri);
114
+ }
115
+ });
116
+ return createLanguageService(language, server.languageServicePlugins, createLanguageServiceEnvironment(server, [...server.workspaceFolders.all]), {});
117
+ }
118
+ });
119
+ connection.onInitialized(server.initialized);
120
+ connection.onShutdown(server.shutdown);
121
+ function getHybridModeLanguageServicePluginsForLanguageServer(tsPluginClient = {}) {
122
+ const plugins = [
123
+ // Lightweight syntax-only TS Language Service. Provides Symbols (e.g. Outline view) and other features.
124
+ createTypeScriptSyntacticPlugin(ts),
125
+ createHtmlSyntacticPlugin(),
126
+ ...getCommonLanguageServicePluginsForLanguageServer(() => tsPluginClient),
127
+ ];
128
+ for (const plugin of plugins) {
129
+ // avoid affecting TS plugin
130
+ delete plugin.capabilities.semanticTokensProvider;
131
+ }
132
+ return plugins;
133
+ }
134
+ function getCommonLanguageServicePluginsForLanguageServer(getTsPluginClient) {
135
+ return [
136
+ createTemplateTagSymbolsPlugin(),
137
+ createCompilerErrorsPlugin(),
138
+ // createTypeScriptTwoslashQueriesPlugin(ts),
139
+ // createCssPlugin(),
140
+ // createPugFormatPlugin(),
141
+ // createJsonPlugin(),
142
+ // createVueTemplatePlugin('html', getTsPluginClient),
143
+ // createVueTemplatePlugin('pug', getTsPluginClient),
144
+ // createVueMissingPropsHintsPlugin(getTsPluginClient),
145
+ // createVueCompilerDomErrorsPlugin(),
146
+ // createVueSfcPlugin(),
147
+ // createVueTwoslashQueriesPlugin(getTsPluginClient),
148
+ // createVueDocumentLinksPlugin(),
149
+ // createVueDocumentDropPlugin(ts, getTsPluginClient),
150
+ // createVueCompleteDefineAssignmentPlugin(),
151
+ // createVueAutoDotValuePlugin(ts, getTsPluginClient),
152
+ // createVueAutoAddSpacePlugin(),
153
+ // createVueInlayHintsPlugin(ts),
154
+ // createVueDirectiveCommentsPlugin(),
155
+ // createVueExtractFilePlugin(ts, getTsPluginClient),
156
+ // createEmmetPlugin({
157
+ // mappedLanguages: {
158
+ // 'vue-root-tags': 'html',
159
+ // 'postcss': 'scss',
160
+ // },
161
+ // }),
162
+ // {
163
+ // name: 'vue-parse-sfc',
164
+ // capabilities: {
165
+ // executeCommandProvider: {
166
+ // commands: [commands.parseSfc],
167
+ // },
168
+ // },
169
+ // create() {
170
+ // return {
171
+ // executeCommand(_command, [source]) {
172
+ // return parse(source);
173
+ // },
174
+ // };
175
+ // },
176
+ // },
177
+ // {
178
+ // name: 'vue-name-casing',
179
+ // capabilities: {
180
+ // executeCommandProvider: {
181
+ // commands: [
182
+ // commands.detectNameCasing,
183
+ // commands.convertTagsToKebabCase,
184
+ // commands.convertTagsToPascalCase,
185
+ // commands.convertPropsToKebabCase,
186
+ // commands.convertPropsToCamelCase,
187
+ // ],
188
+ // }
189
+ // },
190
+ // create(context) {
191
+ // return {
192
+ // executeCommand(command, [uri]) {
193
+ // if (command === commands.detectNameCasing) {
194
+ // return detect(context, URI.parse(uri));
195
+ // }
196
+ // else if (command === commands.convertTagsToKebabCase) {
197
+ // return convertTagName(context, URI.parse(uri), TagNameCasing.Kebab, getTsPluginClient(context));
198
+ // }
199
+ // else if (command === commands.convertTagsToPascalCase) {
200
+ // return convertTagName(context, URI.parse(uri), TagNameCasing.Pascal, getTsPluginClient(context));
201
+ // }
202
+ // else if (command === commands.convertPropsToKebabCase) {
203
+ // return convertAttrName(context, URI.parse(uri), AttrNameCasing.Kebab, getTsPluginClient(context));
204
+ // }
205
+ // else if (command === commands.convertPropsToCamelCase) {
206
+ // return convertAttrName(context, URI.parse(uri), AttrNameCasing.Camel, getTsPluginClient(context));
207
+ // }
208
+ // },
209
+ // };
210
+ // },
211
+ // }
212
+ ];
213
+ }
214
+ //# sourceMappingURL=language-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-server.js","sourceRoot":"","sources":["../../src/volar/language-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,gCAAgC,EAAE,MAAM,qDAAqD,CAAC;AACvG,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAmB,MAAM,yBAAyB,CAAC;AAC/F,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,IAAI,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,MAAM,IAAI,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AAC9G,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,MAAM,IAAI,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;AACtC,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;AACxC,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAA8B,CAAC;AAEtE,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,UAAU,CAAC,MAAM,EAAE,CAAC;AAEpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;IAC3D,uBAAuB,CA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ACP,MAAM;QACN,cAAc;QACd,aAAa;QACb,0CAA0C;QAC1C,4BAA4B;QAC5B,QAAQ;QACR,OAAO;QACP,MAAM;QACN,KAAK;QACL,IAAI;QACJ,4BAA4B;QAC5B,mBAAmB;QACnB,8BAA8B;QAC9B,iBAAiB;QACjB,iCAAiC;QACjC,uCAAuC;QACvC,wCAAwC;QACxC,wCAAwC;QACxC,wCAAwC;QACxC,QAAQ;QACR,MAAM;QACN,MAAM;QACN,qBAAqB;QACrB,aAAa;QACb,sCAAsC;QACtC,mDAAmD;QACnD,+CAA+C;QAC/C,QAAQ;QACR,8DAA8D;QAC9D,wGAAwG;QACxG,QAAQ;QACR,+DAA+D;QAC/D,yGAAyG;QACzG,QAAQ;QACR,+DAA+D;QAC/D,0GAA0G;QAC1G,QAAQ;QACR,+DAA+D;QAC/D,0GAA0G;QAC1G,QAAQ;QACR,QAAQ;QACR,OAAO;QACP,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @typedef {import('typescript').IScriptSnapshot} IScriptSnapshot
3
+ */
4
+ import { IScriptSnapshot, TextChangeRange } from 'typescript';
5
+ /**
6
+ * A TypeScript compatible script snapshot that wraps a string of text.
7
+ *
8
+ * @implements {IScriptSnapshot}
9
+ */
10
+ export declare class ScriptSnapshot implements IScriptSnapshot {
11
+ text: string;
12
+ constructor(text: string);
13
+ getChangeRange(_oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
14
+ getLength(): number;
15
+ getText(start: number, end: number): string;
16
+ }
17
+ //# sourceMappingURL=script-snapshot.d.ts.map