@astrojs/language-server 0.23.2 → 0.24.1

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 (84) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/browser.js +8 -1
  3. package/dist/check.d.ts +2 -1
  4. package/dist/check.js +8 -2
  5. package/dist/core/DiagnosticsManager.d.ts +2 -2
  6. package/dist/core/config/ConfigManager.d.ts +5 -6
  7. package/dist/core/config/ConfigManager.js +2 -9
  8. package/dist/core/documents/AstroDocument.d.ts +1 -1
  9. package/dist/core/documents/AstroDocument.js +1 -1
  10. package/dist/core/documents/DocumentBase.d.ts +2 -2
  11. package/dist/core/documents/DocumentManager.d.ts +1 -1
  12. package/dist/core/documents/DocumentManager.js +1 -1
  13. package/dist/core/documents/DocumentMapper.d.ts +2 -2
  14. package/dist/core/documents/parseHtml.d.ts +3 -2
  15. package/dist/core/documents/parseHtml.js +12 -5
  16. package/dist/core/documents/utils.d.ts +3 -3
  17. package/dist/core/documents/utils.js +1 -2
  18. package/dist/node.js +15 -1
  19. package/dist/plugins/PluginHost.d.ts +2 -2
  20. package/dist/plugins/PluginHost.js +1 -1
  21. package/dist/plugins/astro/AstroPlugin.d.ts +6 -5
  22. package/dist/plugins/astro/AstroPlugin.js +1 -0
  23. package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -3
  24. package/dist/plugins/astro/features/CompletionsProvider.js +12 -15
  25. package/dist/plugins/css/CSSDocument.d.ts +2 -2
  26. package/dist/plugins/css/CSSDocument.js +1 -1
  27. package/dist/plugins/css/CSSPlugin.d.ts +1 -1
  28. package/dist/plugins/css/CSSPlugin.js +3 -3
  29. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  30. package/dist/plugins/css/StyleAttributeDocument.js +1 -1
  31. package/dist/plugins/css/features/astro-selectors.d.ts +1 -1
  32. package/dist/plugins/css/features/getIdClassCompletions.d.ts +2 -2
  33. package/dist/plugins/html/HTMLPlugin.d.ts +3 -3
  34. package/dist/plugins/html/HTMLPlugin.js +1 -1
  35. package/dist/plugins/html/utils.d.ts +1 -1
  36. package/dist/plugins/index.d.ts +4 -4
  37. package/dist/plugins/index.js +4 -4
  38. package/dist/plugins/interfaces.d.ts +2 -2
  39. package/dist/plugins/typescript/LanguageServiceManager.d.ts +8 -9
  40. package/dist/plugins/typescript/LanguageServiceManager.js +5 -3
  41. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -6
  42. package/dist/plugins/typescript/TypeScriptPlugin.js +15 -15
  43. package/dist/plugins/typescript/astro-sys.d.ts +2 -3
  44. package/dist/plugins/typescript/astro-sys.js +7 -11
  45. package/dist/plugins/typescript/astro2tsx.js +3 -4
  46. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +5 -4
  47. package/dist/plugins/typescript/features/CodeActionsProvider.js +6 -9
  48. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +9 -7
  49. package/dist/plugins/typescript/features/CompletionsProvider.js +56 -80
  50. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +4 -4
  51. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +6 -4
  52. package/dist/plugins/typescript/features/DiagnosticsProvider.js +29 -19
  53. package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +3 -2
  54. package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
  55. package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +7 -4
  56. package/dist/plugins/typescript/features/FoldingRangesProvider.js +12 -15
  57. package/dist/plugins/typescript/features/HoverProvider.d.ts +5 -4
  58. package/dist/plugins/typescript/features/HoverProvider.js +3 -6
  59. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +5 -4
  60. package/dist/plugins/typescript/features/InlayHintsProvider.js +5 -8
  61. package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +3 -2
  62. package/dist/plugins/typescript/features/SemanticTokenProvider.js +4 -7
  63. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +5 -4
  64. package/dist/plugins/typescript/features/SignatureHelpProvider.js +7 -10
  65. package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +3 -3
  66. package/dist/plugins/typescript/features/utils.d.ts +3 -3
  67. package/dist/plugins/typescript/language-service.d.ts +7 -6
  68. package/dist/plugins/typescript/language-service.js +29 -30
  69. package/dist/plugins/typescript/module-loader.d.ts +2 -2
  70. package/dist/plugins/typescript/module-loader.js +12 -16
  71. package/dist/plugins/typescript/previewer.d.ts +3 -7
  72. package/dist/plugins/typescript/previewer.js +13 -17
  73. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +4 -5
  74. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +2 -7
  75. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +5 -2
  76. package/dist/plugins/typescript/snapshots/SnapshotManager.js +15 -17
  77. package/dist/plugins/typescript/snapshots/utils.d.ts +7 -7
  78. package/dist/plugins/typescript/snapshots/utils.js +28 -29
  79. package/dist/plugins/typescript/utils.d.ts +8 -10
  80. package/dist/plugins/typescript/utils.js +90 -107
  81. package/dist/server.d.ts +5 -1
  82. package/dist/server.js +27 -17
  83. package/dist/utils.d.ts +1 -1
  84. package/package.json +5 -4
@@ -1,9 +1,10 @@
1
1
  import { CancellationToken, Range, SemanticTokens } from 'vscode-languageserver';
2
2
  import { AstroDocument } from '../../../core/documents';
3
- import { SemanticTokensProvider } from '../../interfaces';
4
- import { LanguageServiceManager } from '../LanguageServiceManager';
3
+ import type { SemanticTokensProvider } from '../../interfaces';
4
+ import type { LanguageServiceManager } from '../LanguageServiceManager';
5
5
  export declare class SemanticTokensProviderImpl implements SemanticTokensProvider {
6
6
  private languageServiceManager;
7
+ private ts;
7
8
  constructor(languageServiceManager: LanguageServiceManager);
8
9
  getSemanticTokens(document: AstroDocument, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
9
10
  private mapToOrigin;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SemanticTokensProviderImpl = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
4
  const vscode_languageserver_1 = require("vscode-languageserver");
9
5
  const documents_1 = require("../../../core/documents");
10
6
  const utils_1 = require("../utils");
11
7
  class SemanticTokensProviderImpl {
12
8
  constructor(languageServiceManager) {
13
9
  this.languageServiceManager = languageServiceManager;
10
+ this.ts = languageServiceManager.docContext.ts;
14
11
  }
15
12
  async getSemanticTokens(document, range, cancellationToken) {
16
13
  const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
@@ -26,7 +23,7 @@ class SemanticTokensProviderImpl {
26
23
  ? fragment.offsetAt(fragment.getGeneratedPosition(range.end)) - start
27
24
  : // We don't want tokens for things added by astro2tsx
28
25
  fragment.text.lastIndexOf('export default function ') || fragment.text.length,
29
- }, typescript_1.default.SemanticClassificationFormat.TwentyTwenty);
26
+ }, this.ts.SemanticClassificationFormat.TwentyTwenty);
30
27
  const tokens = [];
31
28
  let i = 0;
32
29
  while (i < spans.length) {
@@ -72,10 +69,10 @@ class SemanticTokensProviderImpl {
72
69
  * TSClassification = (TokenType + 1) << TokenEncodingConsts.typeOffset + TokenModifier
73
70
  */
74
71
  getTokenTypeFromClassification(tsClassification) {
75
- return (tsClassification >> 8 /* typeOffset */) - 1;
72
+ return (tsClassification >> 8 /* TokenEncodingConsts.typeOffset */) - 1;
76
73
  }
77
74
  getTokenModifierFromClassification(tsClassification) {
78
- return tsClassification & 255 /* modifierMask */;
75
+ return tsClassification & 255 /* TokenEncodingConsts.modifierMask */;
79
76
  }
80
77
  }
81
78
  exports.SemanticTokensProviderImpl = SemanticTokensProviderImpl;
@@ -1,9 +1,10 @@
1
- import type { LanguageServiceManager } from '../LanguageServiceManager';
1
+ import { CancellationToken, Position, SignatureHelp, SignatureHelpContext } from 'vscode-languageserver';
2
+ import type { AstroDocument } from '../../../core/documents';
2
3
  import type { SignatureHelpProvider } from '../../interfaces';
3
- import { Position, SignatureHelpContext, SignatureHelp, CancellationToken } from 'vscode-languageserver';
4
- import { AstroDocument } from '../../../core/documents';
4
+ import type { LanguageServiceManager } from '../LanguageServiceManager';
5
5
  export declare class SignatureHelpProviderImpl implements SignatureHelpProvider {
6
- private readonly languageServiceManager;
6
+ private languageServiceManager;
7
+ private ts;
7
8
  constructor(languageServiceManager: LanguageServiceManager);
8
9
  private static readonly triggerCharacters;
9
10
  private static readonly retriggerCharacters;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SignatureHelpProviderImpl = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
4
  const vscode_languageserver_1 = require("vscode-languageserver");
9
5
  const previewer_1 = require("../previewer");
10
6
  const utils_1 = require("../utils");
11
7
  class SignatureHelpProviderImpl {
12
8
  constructor(languageServiceManager) {
13
9
  this.languageServiceManager = languageServiceManager;
10
+ this.ts = languageServiceManager.docContext.ts;
14
11
  }
15
12
  async getSignatureHelp(document, position, context, cancellationToken) {
16
13
  const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
@@ -33,7 +30,7 @@ class SignatureHelpProviderImpl {
33
30
  if (!info) {
34
31
  return null;
35
32
  }
36
- const signatures = info.items.map(this.toSignatureHelpInformation);
33
+ const signatures = info.items.map((item) => this.toSignatureHelpInformation(item, this.ts));
37
34
  return {
38
35
  signatures,
39
36
  activeSignature: info.selectedItemIndex,
@@ -76,21 +73,21 @@ class SignatureHelpProviderImpl {
76
73
  /**
77
74
  * adopted from https://github.com/microsoft/vscode/blob/265a2f6424dfbd3a9788652c7d376a7991d049a3/extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts#L73
78
75
  */
79
- toSignatureHelpInformation(item) {
76
+ toSignatureHelpInformation(item, ts) {
80
77
  const [prefixLabel, separatorLabel, suffixLabel] = [
81
78
  item.prefixDisplayParts,
82
79
  item.separatorDisplayParts,
83
80
  item.suffixDisplayParts,
84
- ].map(typescript_1.default.displayPartsToString);
81
+ ].map(this.ts.displayPartsToString);
85
82
  let textIndex = prefixLabel.length;
86
83
  let signatureLabel = '';
87
84
  const parameters = [];
88
85
  const lastIndex = item.parameters.length - 1;
89
86
  item.parameters.forEach((parameter, index) => {
90
- const label = typescript_1.default.displayPartsToString(parameter.displayParts);
87
+ const label = ts.displayPartsToString(parameter.displayParts);
91
88
  const startIndex = textIndex;
92
89
  const endIndex = textIndex + label.length;
93
- const doc = typescript_1.default.displayPartsToString(parameter.documentation);
90
+ const doc = ts.displayPartsToString(parameter.documentation);
94
91
  signatureLabel += label;
95
92
  parameters.push(vscode_languageserver_1.ParameterInformation.create([startIndex, endIndex], doc));
96
93
  if (index < lastIndex) {
@@ -98,7 +95,7 @@ class SignatureHelpProviderImpl {
98
95
  signatureLabel += separatorLabel;
99
96
  }
100
97
  });
101
- const signatureDocumentation = (0, previewer_1.getMarkdownDocumentation)(item.documentation, item.tags.filter((tag) => tag.name !== 'param'));
98
+ const signatureDocumentation = (0, previewer_1.getMarkdownDocumentation)(item.documentation, item.tags.filter((tag) => tag.name !== 'param'), ts);
102
99
  return {
103
100
  label: prefixLabel + signatureLabel + suffixLabel,
104
101
  documentation: signatureDocumentation
@@ -1,7 +1,7 @@
1
- import { Position, Location } from 'vscode-languageserver-protocol';
1
+ import { Location, Position } from 'vscode-languageserver-protocol';
2
2
  import { AstroDocument } from '../../../core/documents';
3
- import { TypeDefinitionProvider } from '../../interfaces';
4
- import { LanguageServiceManager } from '../LanguageServiceManager';
3
+ import type { TypeDefinitionProvider } from '../../interfaces';
4
+ import type { LanguageServiceManager } from '../LanguageServiceManager';
5
5
  export declare class TypeDefinitionsProviderImpl implements TypeDefinitionProvider {
6
6
  private languageServiceManager;
7
7
  constructor(languageServiceManager: LanguageServiceManager);
@@ -1,7 +1,7 @@
1
- import type { SnapshotFragment, DocumentSnapshot } from '../snapshots/DocumentSnapshot';
1
+ import type ts from 'typescript';
2
+ import type { Position } from 'vscode-languageserver';
2
3
  import type { LanguageServiceManager } from '../LanguageServiceManager';
3
- import { Position } from 'vscode-languageserver';
4
- import ts from 'typescript';
4
+ import type { DocumentSnapshot, SnapshotFragment } from '../snapshots/DocumentSnapshot';
5
5
  export declare function isPartOfImportStatement(text: string, position: Position): boolean;
6
6
  export declare class SnapshotFragmentMap {
7
7
  private languageServiceManager;
@@ -1,9 +1,8 @@
1
- import { AstroDocument } from '../../core/documents';
2
- import ts from 'typescript';
3
- import { TextDocumentContentChangeEvent } from 'vscode-languageserver';
4
- import { GlobalSnapshotManager, SnapshotManager } from './snapshots/SnapshotManager';
1
+ import type { TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
+ import type { ConfigManager } from '../../core/config';
3
+ import type { AstroDocument } from '../../core/documents';
5
4
  import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
6
- import { ConfigManager } from '../../core/config';
5
+ import { GlobalSnapshotManager, SnapshotManager } from './snapshots/SnapshotManager';
7
6
  export interface LanguageServiceContainer {
8
7
  readonly tsconfigPath: string;
9
8
  readonly compilerOptions: ts.CompilerOptions;
@@ -12,7 +11,7 @@ export interface LanguageServiceContainer {
12
11
  */
13
12
  readonly snapshotManager: SnapshotManager;
14
13
  getService(): ts.LanguageService;
15
- updateSnapshot(documentOrFilePath: AstroDocument | string): DocumentSnapshot;
14
+ updateSnapshot(documentOrFilePath: AstroDocument | string, ts: typeof import('typescript/lib/tsserverlibrary')): DocumentSnapshot;
16
15
  deleteSnapshot(filePath: string): void;
17
16
  updateProjectFiles(): void;
18
17
  updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
@@ -30,6 +29,8 @@ export interface LanguageServiceDocumentContext {
30
29
  createDocument: (fileName: string, content: string) => AstroDocument;
31
30
  globalSnapshotManager: GlobalSnapshotManager;
32
31
  configManager: ConfigManager;
32
+ ts: typeof import('typescript/lib/tsserverlibrary');
33
+ tsLocalized: Record<string, string> | undefined;
33
34
  }
34
35
  export declare function getLanguageService(path: string, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<LanguageServiceContainer>;
35
36
  export declare function forAllLanguageServices(cb: (service: LanguageServiceContainer) => any): Promise<void>;
@@ -22,22 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.getLanguageServiceForTsconfig = exports.forAllLanguageServices = exports.getLanguageService = void 0;
30
27
  const path_1 = require("path");
31
- const typescript_1 = __importDefault(require("typescript"));
32
28
  const utils_1 = require("../../utils");
33
29
  const module_loader_1 = require("./module-loader");
34
- const SnapshotManager_1 = require("./snapshots/SnapshotManager");
35
- const utils_2 = require("./utils");
36
30
  const DocumentSnapshot_1 = require("./snapshots/DocumentSnapshot");
31
+ const SnapshotManager_1 = require("./snapshots/SnapshotManager");
37
32
  const DocumentSnapshotUtils = __importStar(require("./snapshots/utils"));
33
+ const utils_2 = require("./utils");
38
34
  const services = new Map();
39
35
  async function getLanguageService(path, workspaceUris, docContext) {
40
- const tsconfigPath = (0, utils_2.findTsConfigPath)(path, workspaceUris);
36
+ const tsconfigPath = (0, utils_2.findTsConfigPath)(path, workspaceUris, docContext.ts);
41
37
  return getLanguageServiceForTsconfig(tsconfigPath, docContext, workspaceUris);
42
38
  }
43
39
  exports.getLanguageService = getLanguageService;
@@ -78,11 +74,11 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
78
74
  // `raw` here represent the tsconfig merged with any extended config
79
75
  const { compilerOptions, fileNames: files, raw: fullConfig } = getParsedTSConfig();
80
76
  let projectVersion = 0;
81
- const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, tsconfigRoot || process.cwd());
82
- const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions);
77
+ const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, tsconfigRoot || process.cwd(), docContext.ts);
78
+ const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions, docContext.ts);
83
79
  const scriptFileNames = [];
84
80
  if (astroInstall) {
85
- scriptFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(astroInstall.path, f))));
81
+ scriptFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((f) => docContext.ts.sys.resolvePath((0, path_1.resolve)(astroInstall.path, f))));
86
82
  }
87
83
  let languageServerDirectory;
88
84
  try {
@@ -96,30 +92,33 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
96
92
  ((astroInstall.version.major === 0 || astroInstall.version.full === '1.0.0-beta.0') &&
97
93
  !astroInstall.version.full.startsWith('0.0.0-rc-')) // 1.0.0's RC is considered to be 0.0.0, so we have to check for it
98
94
  ) {
99
- scriptFileNames.push(...['../types/astro-jsx.d.ts', '../types/env.d.ts'].map((f) => typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, f))));
95
+ scriptFileNames.push(...['../types/astro-jsx.d.ts', '../types/env.d.ts'].map((f) => docContext.ts.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, f))));
100
96
  console.warn("Couldn't load types from Astro, using internal types instead");
101
97
  }
102
98
  if (allowArbitraryAttrs) {
103
- const arbitraryAttrsDTS = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/arbitrary-attrs.d.ts'));
99
+ const arbitraryAttrsDTS = docContext.ts.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/arbitrary-attrs.d.ts'));
104
100
  scriptFileNames.push(arbitraryAttrsDTS);
105
101
  }
106
102
  const host = {
107
- getNewLine: () => typescript_1.default.sys.newLine,
108
- useCaseSensitiveFileNames: () => typescript_1.default.sys.useCaseSensitiveFileNames,
109
- getDirectories: typescript_1.default.sys.getDirectories,
103
+ getNewLine: () => docContext.ts.sys.newLine,
104
+ useCaseSensitiveFileNames: () => docContext.ts.sys.useCaseSensitiveFileNames,
105
+ getDirectories: docContext.ts.sys.getDirectories,
110
106
  resolveModuleNames: astroModuleLoader.resolveModuleNames,
111
107
  readFile: astroModuleLoader.readFile,
112
108
  fileExists: astroModuleLoader.fileExists,
113
109
  readDirectory: astroModuleLoader.readDirectory,
114
110
  getCompilationSettings: () => compilerOptions,
115
111
  getCurrentDirectory: () => tsconfigRoot,
116
- getDefaultLibFileName: typescript_1.default.getDefaultLibFilePath,
112
+ getDefaultLibFileName: docContext.ts.getDefaultLibFilePath,
117
113
  getProjectVersion: () => projectVersion.toString(),
118
114
  getScriptFileNames: () => Array.from(new Set([...snapshotManager.getProjectFileNames(), ...snapshotManager.getFileNames(), ...scriptFileNames])),
119
115
  getScriptSnapshot,
120
116
  getScriptVersion: (fileName) => getScriptSnapshot(fileName).version.toString(),
121
117
  };
122
- let languageService = typescript_1.default.createLanguageService(host);
118
+ if (docContext.tsLocalized) {
119
+ host.getLocalizedDiagnosticMessages = () => docContext.tsLocalized;
120
+ }
121
+ let languageService = docContext.ts.createLanguageService(host);
123
122
  docContext.globalSnapshotManager.onChange(() => {
124
123
  projectVersion++;
125
124
  });
@@ -153,7 +152,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
153
152
  if (!prevSnapshot) {
154
153
  astroModuleLoader.deleteUnresolvedResolutionsFromCache(filePath);
155
154
  }
156
- const newSnapshot = DocumentSnapshotUtils.createFromDocument(document);
155
+ const newSnapshot = DocumentSnapshotUtils.createFromDocument(document, docContext.ts);
157
156
  snapshotManager.set(filePath, newSnapshot);
158
157
  const scriptTagSnapshots = createScriptTagsSnapshots(filePath, document);
159
158
  scriptTagSnapshots.forEach((snapshot) => {
@@ -163,7 +162,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
163
162
  if (prevSnapshot && prevSnapshot.scriptKind !== newSnapshot.scriptKind) {
164
163
  // Restart language service as it doesn't handle script kind changes.
165
164
  languageService.dispose();
166
- languageService = typescript_1.default.createLanguageService(host);
165
+ languageService = docContext.ts.createLanguageService(host);
167
166
  }
168
167
  return newSnapshot;
169
168
  }
@@ -173,7 +172,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
173
172
  return prevSnapshot;
174
173
  }
175
174
  astroModuleLoader.deleteUnresolvedResolutionsFromCache(filePath);
176
- const newSnapshot = DocumentSnapshotUtils.createFromFilePath(filePath, docContext.createDocument);
175
+ const newSnapshot = DocumentSnapshotUtils.createFromFilePath(filePath, docContext.createDocument, docContext.ts);
177
176
  snapshotManager.set(filePath, newSnapshot);
178
177
  return newSnapshot;
179
178
  }
@@ -184,7 +183,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
184
183
  return doc;
185
184
  }
186
185
  astroModuleLoader.deleteUnresolvedResolutionsFromCache(fileName);
187
- doc = DocumentSnapshotUtils.createFromFilePath(fileName, docContext.createDocument);
186
+ doc = DocumentSnapshotUtils.createFromFilePath(fileName, docContext.createDocument, docContext.ts);
188
187
  snapshotManager.set(fileName, doc);
189
188
  // If we needed to create an Astro snapshot, also create its script tags snapshots
190
189
  if ((0, utils_2.isAstroFilePath)(fileName)) {
@@ -223,7 +222,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
223
222
  });
224
223
  }
225
224
  function getParsedTSConfig() {
226
- let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {};
225
+ let configJson = (tsconfigPath && docContext.ts.readConfigFile(tsconfigPath, docContext.ts.sys.readFile).config) || {};
227
226
  // Delete include so that .astro files don't get mistakenly excluded by the user
228
227
  delete configJson.include;
229
228
  // If the user supplied exclude, let's use theirs otherwise, use ours
@@ -236,18 +235,18 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
236
235
  allowSyntheticDefaultImports: true,
237
236
  allowNonTsExtensions: true,
238
237
  allowJs: true,
239
- jsx: typescript_1.default.JsxEmit.Preserve,
238
+ jsx: docContext.ts.JsxEmit.Preserve,
240
239
  jsxImportSource: undefined,
241
240
  jsxFactory: 'astroHTML',
242
- module: typescript_1.default.ModuleKind.ESNext,
243
- target: typescript_1.default.ScriptTarget.ESNext,
241
+ module: docContext.ts.ModuleKind.ESNext,
242
+ target: docContext.ts.ScriptTarget.ESNext,
244
243
  isolatedModules: true,
245
- moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
244
+ moduleResolution: docContext.ts.ModuleResolutionKind.NodeJs,
246
245
  };
247
- const project = typescript_1.default.parseJsonConfigFileContent(configJson, typescript_1.default.sys, tsconfigRoot, forcedCompilerOptions, tsconfigPath, undefined, [
248
- { extension: '.vue', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
249
- { extension: '.svelte', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
250
- { extension: '.astro', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
246
+ const project = docContext.ts.parseJsonConfigFileContent(configJson, docContext.ts.sys, tsconfigRoot, forcedCompilerOptions, tsconfigPath, undefined, [
247
+ { extension: '.vue', isMixedContent: true, scriptKind: docContext.ts.ScriptKind.Deferred },
248
+ { extension: '.svelte', isMixedContent: true, scriptKind: docContext.ts.ScriptKind.Deferred },
249
+ { extension: '.astro', isMixedContent: true, scriptKind: docContext.ts.ScriptKind.Deferred },
251
250
  ]);
252
251
  return {
253
252
  ...project,
@@ -1,4 +1,4 @@
1
- import ts from 'typescript';
1
+ import type { ResolvedModule } from 'typescript';
2
2
  import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
3
3
  /**
4
4
  * Creates a module loader specifically for `.astro` and other frameworks files.
@@ -12,7 +12,7 @@ import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
12
12
  * @param getSnapshot A function which returns a (in case of astro file fully preprocessed) typescript/javascript snapshot
13
13
  * @param compilerOptions The typescript compiler options
14
14
  */
15
- export declare function createAstroModuleLoader(getSnapshot: (fileName: string) => DocumentSnapshot, compilerOptions: ts.CompilerOptions): {
15
+ export declare function createAstroModuleLoader(getSnapshot: (fileName: string) => DocumentSnapshot, compilerOptions: ts.CompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary')): {
16
16
  fileExists: (path: string) => boolean;
17
17
  readFile: (path: string, encoding?: string | undefined) => string | undefined;
18
18
  readDirectory: (path: string, extensions?: readonly string[] | undefined, exclude?: readonly string[] | undefined, include?: readonly string[] | undefined, depth?: number | undefined) => string[];
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.createAstroModuleLoader = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const utils_1 = require("./utils");
4
+ const utils_1 = require("../../utils");
9
5
  const astro_sys_1 = require("./astro-sys");
10
- const utils_2 = require("../../utils");
6
+ const utils_2 = require("./utils");
11
7
  /**
12
8
  * Caches resolved modules.
13
9
  */
@@ -49,7 +45,7 @@ class ModuleResolutionCache {
49
45
  * and which might match the path.
50
46
  */
51
47
  deleteUnresolvedResolutionsFromCache(path) {
52
- const fileNameWithoutEnding = (0, utils_2.getLastPartOfPath)(path).split('.').shift() || '';
48
+ const fileNameWithoutEnding = (0, utils_1.getLastPartOfPath)(path).split('.').shift() || '';
53
49
  this.cache.forEach((val, key) => {
54
50
  const moduleName = key.split(':::').pop() || '';
55
51
  if (!val && moduleName.includes(fileNameWithoutEnding)) {
@@ -58,7 +54,7 @@ class ModuleResolutionCache {
58
54
  });
59
55
  }
60
56
  getKey(moduleName, containingFile) {
61
- return containingFile + ':::' + (0, utils_1.ensureRealFilePath)(moduleName);
57
+ return containingFile + ':::' + (0, utils_2.ensureRealFilePath)(moduleName);
62
58
  }
63
59
  }
64
60
  /**
@@ -73,8 +69,8 @@ class ModuleResolutionCache {
73
69
  * @param getSnapshot A function which returns a (in case of astro file fully preprocessed) typescript/javascript snapshot
74
70
  * @param compilerOptions The typescript compiler options
75
71
  */
76
- function createAstroModuleLoader(getSnapshot, compilerOptions) {
77
- const astroSys = (0, astro_sys_1.createAstroSys)(getSnapshot);
72
+ function createAstroModuleLoader(getSnapshot, compilerOptions, ts) {
73
+ const astroSys = (0, astro_sys_1.createAstroSys)(getSnapshot, ts);
78
74
  const moduleCache = new ModuleResolutionCache();
79
75
  return {
80
76
  fileExists: astroSys.fileExists,
@@ -104,18 +100,18 @@ function createAstroModuleLoader(getSnapshot, compilerOptions) {
104
100
  // Delegate to the TS resolver first.
105
101
  // If that does not bring up anything, try the Astro Module loader
106
102
  // which is able to deal with .astro and other frameworks files.
107
- const tsResolvedModule = typescript_1.default.resolveModuleName(name, containingFile, compilerOptions, typescript_1.default.sys).resolvedModule;
108
- if (tsResolvedModule && !(0, utils_1.isVirtualFilePath)(tsResolvedModule.resolvedFileName)) {
103
+ const tsResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, ts.sys).resolvedModule;
104
+ if (tsResolvedModule && !(0, utils_2.isVirtualFilePath)(tsResolvedModule.resolvedFileName)) {
109
105
  return tsResolvedModule;
110
106
  }
111
- const astroResolvedModule = typescript_1.default.resolveModuleName(name, containingFile, compilerOptions, astroSys).resolvedModule;
112
- if (!astroResolvedModule || !(0, utils_1.isVirtualFilePath)(astroResolvedModule.resolvedFileName)) {
107
+ const astroResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, astroSys).resolvedModule;
108
+ if (!astroResolvedModule || !(0, utils_2.isVirtualFilePath)(astroResolvedModule.resolvedFileName)) {
113
109
  return astroResolvedModule;
114
110
  }
115
- const resolvedFileName = (0, utils_1.ensureRealFilePath)(astroResolvedModule.resolvedFileName);
111
+ const resolvedFileName = (0, utils_2.ensureRealFilePath)(astroResolvedModule.resolvedFileName);
116
112
  const snapshot = getSnapshot(resolvedFileName);
117
113
  const resolvedAstroModule = {
118
- extension: (0, utils_1.getExtensionFromScriptKind)(snapshot && snapshot.scriptKind),
114
+ extension: (0, utils_2.getExtensionFromScriptKind)(snapshot && snapshot.scriptKind, ts),
119
115
  resolvedFileName,
120
116
  isExternalLibraryImport: astroResolvedModule.isExternalLibraryImport,
121
117
  };
@@ -1,7 +1,3 @@
1
- /**
2
- * adopted from https://github.com/microsoft/vscode/blob/10722887b8629f90cc38ee7d90d54e8246dc895f/extensions/typescript-language-features/src/utils/previewer.ts
3
- */
4
- import ts from 'typescript';
5
- export declare function getTagDocumentation(tag: ts.JSDocTagInfo): string | undefined;
6
- export declare function plain(parts: ts.SymbolDisplayPart[] | string): string;
7
- export declare function getMarkdownDocumentation(documentation: ts.SymbolDisplayPart[] | undefined, tags: ts.JSDocTagInfo[] | undefined): string;
1
+ export declare function getTagDocumentation(tag: ts.JSDocTagInfo, ts: typeof import('typescript/lib/tsserverlibrary')): string | undefined;
2
+ export declare function plain(parts: ts.SymbolDisplayPart[] | string, ts: typeof import('typescript/lib/tsserverlibrary')): string;
3
+ export declare function getMarkdownDocumentation(documentation: ts.SymbolDisplayPart[] | undefined, tags: ts.JSDocTagInfo[] | undefined, ts: typeof import('typescript/lib/tsserverlibrary')): string;
@@ -3,15 +3,11 @@
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
6
  Object.defineProperty(exports, "__esModule", { value: true });
10
7
  exports.getMarkdownDocumentation = exports.plain = exports.getTagDocumentation = void 0;
11
8
  /**
12
9
  * adopted from https://github.com/microsoft/vscode/blob/10722887b8629f90cc38ee7d90d54e8246dc895f/extensions/typescript-language-features/src/utils/previewer.ts
13
10
  */
14
- const typescript_1 = __importDefault(require("typescript"));
15
11
  const utils_1 = require("../../utils");
16
12
  function replaceLinks(text) {
17
13
  return (text
@@ -28,7 +24,7 @@ function replaceLinks(text) {
28
24
  function processInlineTags(text) {
29
25
  return replaceLinks(text);
30
26
  }
31
- function getTagBodyText(tag) {
27
+ function getTagBodyText(tag, ts) {
32
28
  if (!tag.text) {
33
29
  return undefined;
34
30
  }
@@ -61,17 +57,17 @@ function getTagBodyText(tag) {
61
57
  }
62
58
  switch (tag.name) {
63
59
  case 'example':
64
- return makeExampleTag(typescript_1.default.displayPartsToString(tag.text));
60
+ return makeExampleTag(ts.displayPartsToString(tag.text));
65
61
  case 'author':
66
- return makeEmailTag(typescript_1.default.displayPartsToString(tag.text));
62
+ return makeEmailTag(ts.displayPartsToString(tag.text));
67
63
  case 'default':
68
- return makeCodeblock(typescript_1.default.displayPartsToString(tag.text));
64
+ return makeCodeblock(ts.displayPartsToString(tag.text));
69
65
  }
70
- return processInlineTags(typescript_1.default.displayPartsToString(tag.text));
66
+ return processInlineTags(ts.displayPartsToString(tag.text));
71
67
  }
72
- function getTagDocumentation(tag) {
68
+ function getTagDocumentation(tag, ts) {
73
69
  function getWithType() {
74
- const body = (typescript_1.default.displayPartsToString(tag.text) || '').split(/^(\S+)\s*-?\s*/);
70
+ const body = (ts.displayPartsToString(tag.text) || '').split(/^(\S+)\s*-?\s*/);
75
71
  if (body?.length === 3) {
76
72
  const param = body[1];
77
73
  const doc = body[2];
@@ -91,24 +87,24 @@ function getTagDocumentation(tag) {
91
87
  }
92
88
  // Generic tag
93
89
  const label = `*@${tag.name}*`;
94
- const text = getTagBodyText(tag);
90
+ const text = getTagBodyText(tag, ts);
95
91
  if (!text) {
96
92
  return label;
97
93
  }
98
94
  return label + (text.match(/\r\n|\n/g) ? ' \n' + text : ` — ${text}`);
99
95
  }
100
96
  exports.getTagDocumentation = getTagDocumentation;
101
- function plain(parts) {
102
- return processInlineTags(typeof parts === 'string' ? parts : typescript_1.default.displayPartsToString(parts));
97
+ function plain(parts, ts) {
98
+ return processInlineTags(typeof parts === 'string' ? parts : ts.displayPartsToString(parts));
103
99
  }
104
100
  exports.plain = plain;
105
- function getMarkdownDocumentation(documentation, tags) {
101
+ function getMarkdownDocumentation(documentation, tags, ts) {
106
102
  let result = [];
107
103
  if (documentation) {
108
- result.push(plain(documentation));
104
+ result.push(plain(documentation, ts));
109
105
  }
110
106
  if (tags) {
111
- result = result.concat(tags.map(getTagDocumentation));
107
+ result = result.concat(tags.map((tag) => getTagDocumentation(tag, ts)));
112
108
  }
113
109
  return result.filter(utils_1.isNotNullOrUndefined).join('\n\n');
114
110
  }
@@ -1,7 +1,6 @@
1
- import ts from 'typescript';
2
- import { Position, TextDocumentContentChangeEvent } from 'vscode-languageserver';
3
- import { AstroDocument, DocumentMapper, IdentityMapper, FragmentMapper, TagInformation } from '../../../core/documents';
4
- import { FrameworkExt } from '../utils';
1
+ import type { Position, TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
+ import { AstroDocument, DocumentMapper, FragmentMapper, IdentityMapper, TagInformation } from '../../../core/documents';
3
+ import type { FrameworkExt } from '../utils';
5
4
  export interface DocumentSnapshot extends ts.IScriptSnapshot {
6
5
  version: number;
7
6
  filePath: string;
@@ -96,7 +95,7 @@ export declare class TypeScriptDocumentSnapshot extends IdentityMapper implement
96
95
  readonly framework?: FrameworkExt | undefined;
97
96
  scriptKind: ts.ScriptKind;
98
97
  private lineOffsets?;
99
- constructor(version: number, filePath: string, text: string, scriptKind?: ts.ScriptKind, framework?: FrameworkExt | undefined);
98
+ constructor(version: number, filePath: string, text: string, scriptKind: ts.ScriptKind, framework?: FrameworkExt | undefined);
100
99
  getText(start: number, end: number): string;
101
100
  getLength(): number;
102
101
  getFullText(): string;
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TypeScriptDocumentSnapshot = exports.ScriptTagDocumentSnapshot = exports.AstroSnapshotFragment = exports.AstroSnapshot = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
4
  const documents_1 = require("../../../core/documents");
9
5
  const utils_1 = require("../../../utils");
10
- const utils_2 = require("../utils");
11
6
  /**
12
7
  * Snapshots used for Astro files
13
8
  */
@@ -85,7 +80,7 @@ class ScriptTagDocumentSnapshot extends documents_1.FragmentMapper {
85
80
  this.filePath = filePath;
86
81
  this.version = this.parent.version;
87
82
  this.text = this.parent.getText().slice(this.scriptTag.start, this.scriptTag.end) + '\nexport {}';
88
- this.scriptKind = typescript_1.default.ScriptKind.JS;
83
+ this.scriptKind = 1;
89
84
  }
90
85
  positionAt(offset) {
91
86
  return (0, documents_1.positionAt)(offset, this.text, this.getLineOffsets());
@@ -130,7 +125,7 @@ class TypeScriptDocumentSnapshot extends documents_1.IdentityMapper {
130
125
  this.filePath = filePath;
131
126
  this.text = text;
132
127
  this.framework = framework;
133
- scriptKind ? (this.scriptKind = scriptKind) : (this.scriptKind = (0, utils_2.getScriptKindFromFileName)(filePath));
128
+ this.scriptKind = scriptKind;
134
129
  }
135
130
  getText(start, end) {
136
131
  return this.text.substring(start, end);
@@ -1,13 +1,15 @@
1
+ import type { TextDocumentContentChangeEvent } from 'vscode-languageserver';
1
2
  import { DocumentSnapshot, TypeScriptDocumentSnapshot } from './DocumentSnapshot';
2
- import { TextDocumentContentChangeEvent } from 'vscode-languageserver';
3
3
  /**
4
4
  * Every snapshot corresponds to a unique file on disk.
5
5
  * A snapshot can be part of multiple projects, but for a given file path
6
6
  * there can be only one snapshot.
7
7
  */
8
8
  export declare class GlobalSnapshotManager {
9
+ private readonly ts;
9
10
  private emitter;
10
11
  private documents;
12
+ constructor(ts: typeof import('typescript/lib/tsserverlibrary'));
11
13
  get(fileName: string): DocumentSnapshot | undefined;
12
14
  set(fileName: string, document: DocumentSnapshot): void;
13
15
  delete(fileName: string): void;
@@ -26,10 +28,11 @@ export declare class SnapshotManager {
26
28
  private projectFiles;
27
29
  private fileSpec;
28
30
  private workspaceRoot;
31
+ private ts;
29
32
  private documents;
30
33
  private lastLogged;
31
34
  private readonly watchExtensions;
32
- constructor(globalSnapshotsManager: GlobalSnapshotManager, projectFiles: string[], fileSpec: TsFilesSpec, workspaceRoot: string);
35
+ constructor(globalSnapshotsManager: GlobalSnapshotManager, projectFiles: string[], fileSpec: TsFilesSpec, workspaceRoot: string, ts: typeof import('typescript/lib/tsserverlibrary'));
33
36
  updateProjectFiles(): void;
34
37
  updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
35
38
  has(fileName: string): boolean;