@astrojs/language-server 0.9.3 → 0.12.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 (97) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/browserServer.js +3 -0
  3. package/bin/nodeServer.js +3 -0
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.js +8 -0
  6. package/dist/check.js +2 -5
  7. package/dist/core/DiagnosticsManager.d.ts +3 -3
  8. package/dist/core/DiagnosticsManager.js +2 -2
  9. package/dist/core/config/ConfigManager.d.ts +19 -164
  10. package/dist/core/config/ConfigManager.js +62 -101
  11. package/dist/core/config/index.d.ts +1 -0
  12. package/dist/core/config/index.js +6 -1
  13. package/dist/core/config/interfaces.d.ts +123 -0
  14. package/dist/core/config/interfaces.js +2 -0
  15. package/dist/core/documents/AstroDocument.d.ts +18 -0
  16. package/dist/core/documents/AstroDocument.js +37 -0
  17. package/dist/core/documents/DocumentBase.d.ts +10 -2
  18. package/dist/core/documents/DocumentBase.js +15 -50
  19. package/dist/core/documents/DocumentManager.d.ts +12 -16
  20. package/dist/core/documents/DocumentManager.js +32 -26
  21. package/dist/core/documents/DocumentMapper.js +3 -1
  22. package/dist/core/documents/index.d.ts +1 -1
  23. package/dist/core/documents/index.js +6 -2
  24. package/dist/core/documents/parseAstro.d.ts +2 -2
  25. package/dist/core/documents/parseHtml.d.ts +2 -2
  26. package/dist/core/documents/parseHtml.js +4 -1
  27. package/dist/core/documents/utils.d.ts +22 -26
  28. package/dist/core/documents/utils.js +96 -134
  29. package/dist/index.d.ts +0 -1
  30. package/dist/index.js +1 -3
  31. package/dist/node.d.ts +1 -0
  32. package/dist/node.js +29 -0
  33. package/dist/plugins/PluginHost.d.ts +10 -9
  34. package/dist/plugins/PluginHost.js +30 -36
  35. package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
  36. package/dist/plugins/astro/AstroPlugin.js +17 -38
  37. package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
  38. package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
  39. package/dist/plugins/css/CSSDocument.d.ts +3 -3
  40. package/dist/plugins/css/CSSDocument.js +7 -16
  41. package/dist/plugins/css/CSSPlugin.d.ts +22 -12
  42. package/dist/plugins/css/CSSPlugin.js +112 -41
  43. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  44. package/dist/plugins/css/StyleAttributeDocument.js +2 -2
  45. package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
  46. package/dist/plugins/css/features/astro-selectors.js +16 -0
  47. package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
  48. package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
  49. package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
  50. package/dist/plugins/css/{service.js → language-service.js} +2 -1
  51. package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
  52. package/dist/plugins/html/HTMLPlugin.js +33 -41
  53. package/dist/plugins/index.d.ts +2 -2
  54. package/dist/plugins/index.js +7 -3
  55. package/dist/plugins/interfaces.d.ts +35 -48
  56. package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
  57. package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
  58. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
  59. package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
  60. package/dist/plugins/typescript/astro-sys.d.ts +5 -3
  61. package/dist/plugins/typescript/astro-sys.js +24 -41
  62. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
  63. package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
  64. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
  65. package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
  66. package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
  67. package/dist/plugins/typescript/features/HoverProvider.js +9 -10
  68. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
  69. package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
  70. package/dist/plugins/typescript/features/utils.d.ts +1 -12
  71. package/dist/plugins/typescript/features/utils.js +2 -22
  72. package/dist/plugins/typescript/language-service.d.ts +38 -0
  73. package/dist/plugins/typescript/language-service.js +222 -0
  74. package/dist/plugins/typescript/module-loader.d.ts +5 -8
  75. package/dist/plugins/typescript/module-loader.js +43 -23
  76. package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
  77. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
  78. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
  79. package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
  80. package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
  81. package/dist/plugins/typescript/snapshots/utils.js +84 -0
  82. package/dist/plugins/typescript/utils.d.ts +10 -11
  83. package/dist/plugins/typescript/utils.js +122 -151
  84. package/dist/server.d.ts +2 -4
  85. package/dist/server.js +91 -54
  86. package/dist/utils.d.ts +16 -8
  87. package/dist/utils.js +29 -14
  88. package/package.json +19 -13
  89. package/bin/server.js +0 -7
  90. package/dist/core/documents/Document.d.ts +0 -51
  91. package/dist/core/documents/Document.js +0 -135
  92. package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
  93. package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
  94. package/dist/plugins/typescript/SnapshotManager.js +0 -97
  95. package/dist/plugins/typescript/languageService.d.ts +0 -17
  96. package/dist/plugins/typescript/languageService.js +0 -169
  97. package/types/index.d.ts +0 -4
@@ -1,33 +1,26 @@
1
- import type { ConfigManager } from '../../core/config';
2
- import type { CompletionsProvider, AppCompletionItem, AppCompletionList } from '../interfaces';
3
- import type { CancellationToken, Diagnostic, Hover, SignatureHelp, SignatureHelpContext, WorkspaceEdit } from 'vscode-languageserver';
4
- import { Document, DocumentManager } from '../../core/documents';
5
- import { CompletionContext, DefinitionLink, Position } from 'vscode-languageserver';
6
- import { SnapshotManager } from './SnapshotManager';
1
+ import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, Hover, Position, SignatureHelp, SignatureHelpContext, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
2
+ import { ConfigManager } from '../../core/config';
3
+ import { AstroDocument, DocumentManager } from '../../core/documents';
4
+ import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
7
5
  import { CompletionEntryWithIdentifer } from './features/CompletionsProvider';
8
- export declare class TypeScriptPlugin implements CompletionsProvider {
9
- private readonly docManager;
10
- private readonly configManager;
6
+ export declare class TypeScriptPlugin implements Plugin {
7
+ __name: string;
8
+ private configManager;
11
9
  private readonly languageServiceManager;
12
- pluginName: string;
13
10
  private readonly completionProvider;
14
11
  private readonly hoverProvider;
15
12
  private readonly signatureHelpProvider;
16
13
  private readonly diagnosticsProvider;
17
14
  constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
18
- doHover(document: Document, position: Position): Promise<Hover | null>;
19
- rename(document: Document, position: Position, newName: string): Promise<WorkspaceEdit | null>;
20
- getCompletions(document: Document, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
21
- resolveCompletion(document: Document, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
22
- getDefinitions(document: Document, position: Position): Promise<DefinitionLink[]>;
23
- getDiagnostics(document: Document, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
24
- onWatchFileChanges(onWatchFileChangesParams: any[]): Promise<void>;
25
- getSignatureHelp(document: Document, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
26
- /**
27
- *
28
- * @internal
29
- */
30
- getSnapshotManager(fileName: string): Promise<SnapshotManager>;
15
+ doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
16
+ rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
17
+ getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
18
+ resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
19
+ getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
20
+ getDiagnostics(document: AstroDocument, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
21
+ onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
22
+ updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
23
+ getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
31
24
  private goToDefinitionFoundOnlyAlias;
32
25
  private getGoToDefinitionRefsForImportSpecifier;
33
26
  private featureEnabled;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,24 +24,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
26
  exports.TypeScriptPlugin = void 0;
23
- const path_1 = require("path");
24
- const typescript_1 = require("typescript");
27
+ const typescript_1 = __importStar(require("typescript"));
25
28
  const vscode_languageserver_1 = require("vscode-languageserver");
26
- const ts = __importStar(require("typescript"));
27
- const LanguageServiceManager_1 = require("./LanguageServiceManager");
28
- const utils_1 = require("./utils");
29
- const utils_2 = require("../../utils");
29
+ const path_1 = require("path");
30
+ const utils_1 = require("../../utils");
30
31
  const CompletionsProvider_1 = require("./features/CompletionsProvider");
31
- const HoverProvider_1 = require("./features/HoverProvider");
32
32
  const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
33
- const utils_3 = require("./features/utils");
33
+ const HoverProvider_1 = require("./features/HoverProvider");
34
34
  const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
35
+ const utils_2 = require("./features/utils");
36
+ const LanguageServiceManager_1 = require("./LanguageServiceManager");
37
+ const utils_3 = require("./utils");
35
38
  class TypeScriptPlugin {
36
39
  constructor(docManager, configManager, workspaceUris) {
37
- this.pluginName = 'TypeScript';
38
- this.docManager = docManager;
40
+ this.__name = 'typescript';
39
41
  this.configManager = configManager;
40
- this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, configManager, workspaceUris);
42
+ this.languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(docManager, workspaceUris, configManager);
41
43
  this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
42
44
  this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
43
45
  this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
@@ -47,24 +49,24 @@ class TypeScriptPlugin {
47
49
  return this.hoverProvider.doHover(document, position);
48
50
  }
49
51
  async rename(document, position, newName) {
50
- const { lang, tsDoc } = await this.languageServiceManager.getTypeScriptDoc(document);
51
- const fragment = await tsDoc.getFragment();
52
+ const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
53
+ const fragment = await tsDoc.createFragment();
52
54
  const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
53
- let renames = lang.findRenameLocations((0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
55
+ let renames = lang.findRenameLocations((0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath), offset, false, false, true);
54
56
  if (!renames) {
55
57
  return null;
56
58
  }
57
59
  let edit = {
58
- changes: {}
60
+ changes: {},
59
61
  };
60
- renames.forEach(rename => {
61
- const filePath = (0, utils_1.ensureRealAstroFilePath)(rename.fileName);
62
+ renames.forEach((rename) => {
63
+ const filePath = (0, utils_3.ensureRealFilePath)(rename.fileName);
62
64
  if (!(filePath in edit.changes)) {
63
65
  edit.changes[filePath] = [];
64
66
  }
65
67
  edit.changes[filePath].push({
66
68
  newText: newName,
67
- range: (0, utils_1.convertToLocationRange)(fragment, rename.textSpan)
69
+ range: (0, utils_3.convertToLocationRange)(fragment, rename.textSpan),
68
70
  });
69
71
  });
70
72
  return edit;
@@ -77,10 +79,10 @@ class TypeScriptPlugin {
77
79
  return this.completionProvider.resolveCompletion(document, completionItem);
78
80
  }
79
81
  async getDefinitions(document, position) {
80
- const { lang, tsDoc } = await this.languageServiceManager.getTypeScriptDoc(document);
81
- const mainFragment = await tsDoc.getFragment();
82
+ const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
83
+ const mainFragment = await tsDoc.createFragment();
82
84
  const filePath = tsDoc.filePath;
83
- const tsFilePath = (0, utils_1.toVirtualAstroFilePath)(filePath);
85
+ const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
84
86
  const fragmentPosition = mainFragment.getGeneratedPosition(position);
85
87
  const fragmentOffset = mainFragment.offsetAt(fragmentPosition);
86
88
  let defs = lang.getDefinitionAndBoundSpan(tsFilePath, fragmentOffset);
@@ -94,17 +96,16 @@ class TypeScriptPlugin {
94
96
  defs = importDef;
95
97
  }
96
98
  }
97
- const docs = new utils_3.SnapshotFragmentMap(this.languageServiceManager);
99
+ const docs = new utils_2.SnapshotFragmentMap(this.languageServiceManager);
98
100
  docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
99
101
  const result = await Promise.all(defs.definitions.map(async (def) => {
100
102
  const { fragment, snapshot } = await docs.retrieve(def.fileName);
101
- if ((0, utils_3.isNoTextSpanInGeneratedCode)(snapshot.getFullText(), def.textSpan)) {
102
- const fileName = (0, utils_1.ensureRealAstroFilePath)(def.fileName);
103
- const textSpan = (0, utils_1.isVirtualAstroFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
104
- return vscode_languageserver_1.LocationLink.create((0, utils_2.pathToUrl)(fileName), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(mainFragment, defs.textSpan));
105
- }
103
+ const fileName = (0, utils_3.ensureRealFilePath)(def.fileName);
104
+ // Since we converted our files to TSX and we don't have sourcemaps, we don't know where the function is, unfortunate
105
+ const textSpan = (0, utils_3.isVirtualFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
106
+ return vscode_languageserver_1.LocationLink.create((0, utils_1.pathToUrl)(fileName), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(fragment, textSpan), (0, utils_3.convertToLocationRange)(mainFragment, defs.textSpan));
106
107
  }));
107
- return result.filter(utils_2.isNotNullOrUndefined);
108
+ return result.filter(utils_1.isNotNullOrUndefined);
108
109
  }
109
110
  async getDiagnostics(document, cancellationToken) {
110
111
  if (!this.featureEnabled('diagnostics')) {
@@ -112,38 +113,31 @@ class TypeScriptPlugin {
112
113
  }
113
114
  return this.diagnosticsProvider.getDiagnostics(document, cancellationToken);
114
115
  }
115
- async onWatchFileChanges(onWatchFileChangesParams) {
116
- const doneUpdateProjectFiles = new Set();
117
- for (const { fileName, changeType } of onWatchFileChangesParams) {
118
- const scriptKind = (0, utils_1.getScriptKindFromFileName)(fileName);
119
- if (scriptKind === ts.ScriptKind.Unknown) {
120
- // We don't deal with svelte files here
116
+ async onWatchFileChanges(onWatchFileChangesParas) {
117
+ let doneUpdateProjectFiles = false;
118
+ for (const { fileName, changeType } of onWatchFileChangesParas) {
119
+ const scriptKind = (0, utils_3.getScriptKindFromFileName)(fileName);
120
+ if (scriptKind === typescript_1.default.ScriptKind.Unknown) {
121
121
  continue;
122
122
  }
123
- const snapshotManager = await this.getSnapshotManager(fileName);
124
- if (changeType === vscode_languageserver_1.FileChangeType.Created) {
125
- if (!doneUpdateProjectFiles.has(snapshotManager)) {
126
- snapshotManager.updateProjectFiles();
127
- doneUpdateProjectFiles.add(snapshotManager);
128
- }
123
+ if (changeType === vscode_languageserver_1.FileChangeType.Created && !doneUpdateProjectFiles) {
124
+ doneUpdateProjectFiles = true;
125
+ await this.languageServiceManager.updateProjectFiles();
129
126
  }
130
127
  else if (changeType === vscode_languageserver_1.FileChangeType.Deleted) {
131
- snapshotManager.delete(fileName);
132
- return;
128
+ await this.languageServiceManager.deleteSnapshot(fileName);
129
+ }
130
+ else {
131
+ await this.languageServiceManager.updateExistingNonAstroFile(fileName);
133
132
  }
134
- snapshotManager.updateProjectFile(fileName);
135
133
  }
136
134
  }
135
+ async updateNonAstroFile(fileName, changes) {
136
+ await this.languageServiceManager.updateExistingNonAstroFile(fileName, changes);
137
+ }
137
138
  async getSignatureHelp(document, position, context, cancellationToken) {
138
139
  return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
139
140
  }
140
- /**
141
- *
142
- * @internal
143
- */
144
- async getSnapshotManager(fileName) {
145
- return this.languageServiceManager.getSnapshotManager(fileName);
146
- }
147
141
  goToDefinitionFoundOnlyAlias(tsFileName, defs) {
148
142
  return !!(defs.length === 1 && defs[0].kind === 'alias' && defs[0].fileName === tsFileName);
149
143
  }
@@ -151,11 +145,11 @@ class TypeScriptPlugin {
151
145
  const program = lang.getProgram();
152
146
  const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(tsFilePath);
153
147
  if (sourceFile) {
154
- let node = ts.getTouchingPropertyName(sourceFile, offset);
148
+ let node = typescript_1.default.getTouchingPropertyName(sourceFile, offset);
155
149
  if (node && node.kind === typescript_1.SyntaxKind.Identifier) {
156
150
  if (node.parent.kind === typescript_1.SyntaxKind.ImportClause) {
157
151
  let decl = node.parent.parent;
158
- let spec = ts.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
152
+ let spec = typescript_1.default.isStringLiteral(decl.moduleSpecifier) && decl.moduleSpecifier.text;
159
153
  if (spec) {
160
154
  let fileName = (0, path_1.join)((0, path_1.dirname)(tsFilePath), spec);
161
155
  let start = node.pos + 1;
@@ -184,10 +178,8 @@ class TypeScriptPlugin {
184
178
  }
185
179
  }
186
180
  }
187
- // This exists so we can make features toggleable in the future.
188
181
  featureEnabled(feature) {
189
- return (this.configManager.enabled('typescript.enable') &&
190
- this.configManager.enabled(`typescript.${feature}.enable`));
182
+ return (this.configManager.enabled('typescript.enabled') && this.configManager.enabled(`typescript.${feature}.enabled`));
191
183
  }
192
184
  }
193
185
  exports.TypeScriptPlugin = TypeScriptPlugin;
@@ -1,6 +1,8 @@
1
- import * as ts from 'typescript';
2
- import { DocumentSnapshot } from './DocumentSnapshot';
1
+ import ts from 'typescript';
2
+ import { DocumentSnapshot } from './snapshots/DocumentSnapshot';
3
3
  /**
4
4
  * This should only be accessed by TS Astro module resolution.
5
5
  */
6
- export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot): ts.System;
6
+ export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot): ts.System & {
7
+ deleteFromCache: (path: string) => void;
8
+ };
@@ -1,65 +1,48 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.createAstroSys = void 0;
23
- const ts = __importStar(require("typescript"));
7
+ const typescript_1 = __importDefault(require("typescript"));
24
8
  const utils_1 = require("./utils");
25
- const ignoredDirectories = [
26
- "node_modules/@types/react"
27
- ];
28
- const ignoredDirectoriesExp = new RegExp("(" + ignoredDirectories.map(n => n + "$").join("|") + ")");
29
9
  /**
30
10
  * This should only be accessed by TS Astro module resolution.
31
11
  */
32
12
  function createAstroSys(getSnapshot) {
13
+ const fileExistsCache = new Map();
33
14
  const AstroSys = {
34
- ...ts.sys,
15
+ ...typescript_1.default.sys,
35
16
  fileExists(path) {
36
- let doesExist = ts.sys.fileExists((0, utils_1.ensureRealAstroFilePath)(path));
37
- return doesExist;
38
- },
39
- directoryExists(path) {
40
- if (ignoredDirectoriesExp.test(path)) {
41
- return false;
42
- }
43
- return ts.sys.directoryExists(path);
17
+ var _a;
18
+ path = (0, utils_1.ensureRealFilePath)(path);
19
+ const exists = (_a = fileExistsCache.get(path)) !== null && _a !== void 0 ? _a : typescript_1.default.sys.fileExists(path);
20
+ fileExistsCache.set(path, exists);
21
+ return exists;
44
22
  },
45
23
  readFile(path) {
46
- if ((0, utils_1.isAstroFilePath)(path) || (0, utils_1.isVirtualAstroFilePath)(path)) {
47
- console.log('readFile', path);
48
- }
49
24
  const snapshot = getSnapshot(path);
50
- return snapshot.getFullText();
25
+ return snapshot.getText(0, snapshot.getLength());
51
26
  },
52
27
  readDirectory(path, extensions, exclude, include, depth) {
53
28
  const extensionsWithAstro = (extensions !== null && extensions !== void 0 ? extensions : []).concat(...['.astro', '.svelte', '.vue']);
54
- const result = ts.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
29
+ const result = typescript_1.default.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
55
30
  return result;
56
31
  },
32
+ deleteFile(path) {
33
+ var _a, _b;
34
+ fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
35
+ return (_b = (_a = typescript_1.default.sys).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, path);
36
+ },
37
+ deleteFromCache(path) {
38
+ fileExistsCache.delete((0, utils_1.ensureRealFilePath)(path));
39
+ },
57
40
  };
58
- if (ts.sys.realpath) {
59
- const realpath = ts.sys.realpath;
41
+ if (typescript_1.default.sys.realpath) {
42
+ const realpath = typescript_1.default.sys.realpath;
60
43
  AstroSys.realpath = function (path) {
61
- if ((0, utils_1.isVirtualAstroFilePath)(path)) {
62
- return realpath((0, utils_1.toRealAstroFilePath)(path)) + '.ts';
44
+ if ((0, utils_1.isVirtualFilePath)(path)) {
45
+ return realpath((0, utils_1.ensureRealFilePath)(path)) + '.tsx';
63
46
  }
64
47
  return realpath(path);
65
48
  };
@@ -1,16 +1,16 @@
1
1
  import type { CompletionContext, Position, TextDocumentIdentifier } from 'vscode-languageserver';
2
2
  import type { LanguageServiceManager } from '../LanguageServiceManager';
3
- import { Document } from '../../../core/documents';
4
- import * as ts from 'typescript';
3
+ import { AstroDocument } from '../../../core/documents';
4
+ import ts from 'typescript';
5
5
  import { AppCompletionItem, AppCompletionList, CompletionsProvider } from '../../interfaces';
6
6
  export interface CompletionEntryWithIdentifer extends ts.CompletionEntry, TextDocumentIdentifier {
7
7
  position: Position;
8
8
  }
9
9
  export declare class CompletionsProviderImpl implements CompletionsProvider<CompletionEntryWithIdentifer> {
10
- private lang;
11
- constructor(lang: LanguageServiceManager);
12
- getCompletions(document: Document, position: Position, _completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
13
- resolveCompletion(document: Document, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
10
+ private languageServiceManager;
11
+ constructor(languageServiceManager: LanguageServiceManager);
12
+ getCompletions(document: AstroDocument, position: Position, _completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
13
+ resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
14
14
  private toCompletionItem;
15
15
  private getCompletionDocument;
16
16
  }
@@ -1,37 +1,21 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.CompletionsProviderImpl = void 0;
23
7
  const utils_1 = require("../../../core/documents/utils");
24
- const ts = __importStar(require("typescript"));
8
+ const typescript_1 = __importDefault(require("typescript"));
25
9
  const vscode_languageserver_1 = require("vscode-languageserver");
26
10
  const utils_2 = require("../utils");
27
11
  const completionOptions = Object.freeze({
28
12
  importModuleSpecifierPreference: 'relative',
29
- importModuleSpecifierEnding: 'js',
13
+ importModuleSpecifierEnding: 'auto',
30
14
  quotePreference: 'single',
31
15
  });
32
16
  class CompletionsProviderImpl {
33
- constructor(lang) {
34
- this.lang = lang;
17
+ constructor(languageServiceManager) {
18
+ this.languageServiceManager = languageServiceManager;
35
19
  }
36
20
  async getCompletions(document, position, _completionContext) {
37
21
  var _a;
@@ -39,13 +23,11 @@ class CompletionsProviderImpl {
39
23
  if (!(0, utils_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
40
24
  return null;
41
25
  }
42
- const filePath = document.getFilePath();
43
- if (!filePath)
44
- throw new Error();
45
- const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
46
- const fragment = await tsDoc.getFragment();
26
+ const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
27
+ const filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
28
+ const fragment = await tsDoc.createFragment();
47
29
  const offset = document.offsetAt(position);
48
- const entries = ((_a = lang.getCompletionsAtPosition(fragment.filePath, offset, completionOptions)) === null || _a === void 0 ? void 0 : _a.entries) || [];
30
+ const entries = ((_a = lang.getCompletionsAtPosition(filePath, offset, completionOptions)) === null || _a === void 0 ? void 0 : _a.entries) || [];
49
31
  const completionItems = entries
50
32
  .map((entry) => this.toCompletionItem(fragment, entry, document.uri, position, new Set()))
51
33
  .filter((i) => i);
@@ -53,12 +35,12 @@ class CompletionsProviderImpl {
53
35
  }
54
36
  async resolveCompletion(document, completionItem) {
55
37
  const { data: comp } = completionItem;
56
- const { tsDoc, lang } = await this.lang.getTypeScriptDoc(document);
38
+ const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
57
39
  let filePath = (0, utils_2.toVirtualAstroFilePath)(tsDoc.filePath);
58
40
  if (!comp || !filePath) {
59
41
  return completionItem;
60
42
  }
61
- const fragment = await tsDoc.getFragment();
43
+ const fragment = await tsDoc.createFragment();
62
44
  const detail = lang.getCompletionEntryDetails(filePath, // fileName
63
45
  fragment.offsetAt(comp.position), // position
64
46
  comp.name, // entryName
@@ -93,12 +75,14 @@ class CompletionsProviderImpl {
93
75
  }
94
76
  getCompletionDocument(compDetail) {
95
77
  const { source, documentation: tsDocumentation, displayParts, tags } = compDetail;
96
- let detail = ts.displayPartsToString(displayParts);
78
+ let detail = typescript_1.default.displayPartsToString(displayParts);
97
79
  if (source) {
98
- const importPath = ts.displayPartsToString(source);
80
+ const importPath = typescript_1.default.displayPartsToString(source);
99
81
  detail = `Auto import from ${importPath}\n${detail}`;
100
82
  }
101
- const documentation = tsDocumentation ? { value: tsDocumentation.join('\n'), kind: vscode_languageserver_1.MarkupKind.Markdown } : undefined;
83
+ const documentation = tsDocumentation
84
+ ? { value: tsDocumentation.join('\n'), kind: vscode_languageserver_1.MarkupKind.Markdown }
85
+ : undefined;
102
86
  return {
103
87
  documentation,
104
88
  detail,
@@ -1,11 +1,11 @@
1
- import { CancellationToken, Diagnostic } from 'vscode-languageserver';
2
- import { Document } from '../../../core/documents';
1
+ import { CancellationToken } from 'vscode-languageserver';
2
+ import { Diagnostic } from 'vscode-languageserver-types';
3
+ import { AstroDocument } from '../../../core/documents';
3
4
  import { DiagnosticsProvider } from '../../interfaces';
4
5
  import { LanguageServiceManager } from '../LanguageServiceManager';
5
6
  export declare class DiagnosticsProviderImpl implements DiagnosticsProvider {
6
7
  private readonly languageServiceManager;
7
8
  constructor(languageServiceManager: LanguageServiceManager);
8
- getDiagnostics(document: Document, _cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
9
- private getLSAndTSDoc;
9
+ getDiagnostics(document: AstroDocument, _cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
10
10
  private getTagBoundaries;
11
11
  }