@astrojs/language-server 0.27.0 → 0.28.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.
@@ -33,8 +33,8 @@ export declare class PluginHost {
33
33
  getColorPresentations(textDocument: TextDocumentIdentifier, range: Range, color: Color): Promise<ColorPresentation[]>;
34
34
  getInlayHints(textDocument: TextDocumentIdentifier, range: Range, cancellationToken?: CancellationToken): Promise<InlayHint[]>;
35
35
  getSignatureHelp(textDocument: TextDocumentIdentifier, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
36
- onWatchFileChanges(onWatchFileChangesParams: any[]): void;
37
- updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
36
+ onWatchFileChanges(onWatchFileChangesParams: any[]): Promise<void>;
37
+ updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[], text?: string): void;
38
38
  private getDocument;
39
39
  private execute;
40
40
  private tryExecutePlugin;
@@ -151,14 +151,14 @@ class PluginHost {
151
151
  const document = this.getDocument(textDocument.uri);
152
152
  return await this.execute('getSignatureHelp', [document, position, context, cancellationToken], ExecuteMode.FirstNonNull);
153
153
  }
154
- onWatchFileChanges(onWatchFileChangesParams) {
154
+ async onWatchFileChanges(onWatchFileChangesParams) {
155
155
  for (const support of this.plugins) {
156
- support.onWatchFileChanges?.(onWatchFileChangesParams);
156
+ await support.onWatchFileChanges?.(onWatchFileChangesParams);
157
157
  }
158
158
  }
159
- updateNonAstroFile(fileName, changes) {
159
+ updateNonAstroFile(fileName, changes, text) {
160
160
  for (const support of this.plugins) {
161
- support.updateNonAstroFile?.(fileName, changes);
161
+ support.updateNonAstroFile?.(fileName, changes, text);
162
162
  }
163
163
  }
164
164
  getDocument(uri) {
@@ -157,7 +157,7 @@ class CompletionsProviderImpl {
157
157
  if (this.ts.isImportDeclaration(node)) {
158
158
  let clauses = node.importClause;
159
159
  if (!clauses)
160
- return null;
160
+ continue;
161
161
  let namedImport = clauses.getChildAt(0);
162
162
  if (this.ts.isNamedImports(namedImport)) {
163
163
  for (let imp of namedImport.elements) {
@@ -88,10 +88,10 @@ export interface OnWatchFileChangesParam {
88
88
  changeType: FileChangeType;
89
89
  }
90
90
  export interface OnWatchFileChangesProvider {
91
- onWatchFileChanges(onWatchFileChangesParams: OnWatchFileChangesParam[]): void;
91
+ onWatchFileChanges(onWatchFileChangesParams: OnWatchFileChangesParam[]): Promise<void>;
92
92
  }
93
93
  export interface UpdateNonAstroFile {
94
- updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
94
+ updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[], text?: string): void;
95
95
  }
96
96
  declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & FileReferencesProvider & DefinitionsProvider & TypeDefinitionsProvider & ImplementationProvider & FormattingProvider & FoldingRangesProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & InlayHintsProvider & UpdateNonAstroFile;
97
97
  export declare type LSProvider = ProviderBase;
@@ -3,6 +3,7 @@ import type { ConfigManager } from '../../core/config';
3
3
  import type { AstroDocument, DocumentManager } from '../../core/documents';
4
4
  import { LanguageServiceContainer, LanguageServiceDocumentContext } from './language-service';
5
5
  import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
6
+ import { SnapshotManager } from './snapshots/SnapshotManager';
6
7
  export declare class LanguageServiceManager {
7
8
  private readonly docManager;
8
9
  private readonly workspaceUris;
@@ -31,11 +32,15 @@ export declare class LanguageServiceManager {
31
32
  /**
32
33
  * Updates file in all ts services where it exists
33
34
  */
34
- updateExistingNonAstroFile(path: string, changes?: TextDocumentContentChangeEvent[]): Promise<void>;
35
+ updateExistingNonAstroFile(path: string, changes?: TextDocumentContentChangeEvent[], text?: string): Promise<void>;
35
36
  getLSAndTSDoc(document: AstroDocument): Promise<{
36
37
  tsDoc: DocumentSnapshot;
37
38
  lang: ts.LanguageService;
38
39
  }>;
39
40
  getLSForPath(path: string): Promise<import("typescript/lib/tsserverlibrary").LanguageService>;
40
41
  getTypeScriptLanguageService(filePath: string): Promise<LanguageServiceContainer>;
42
+ /**
43
+ * @internal Public for tests only
44
+ */
45
+ getSnapshotManager(filePath: string): Promise<SnapshotManager>;
41
46
  }
@@ -63,7 +63,7 @@ class LanguageServiceManager {
63
63
  /**
64
64
  * Updates file in all ts services where it exists
65
65
  */
66
- async updateExistingNonAstroFile(path, changes) {
66
+ async updateExistingNonAstroFile(path, changes, text) {
67
67
  path = (0, utils_1.normalizePath)(path);
68
68
  // Only update once because all snapshots are shared between
69
69
  // services. Since we don't have a current version of TS/JS
@@ -72,7 +72,7 @@ class LanguageServiceManager {
72
72
  await (0, language_service_1.forAllLanguageServices)((service) => {
73
73
  if (service.hasFile(path) && !didUpdate) {
74
74
  didUpdate = true;
75
- service.updateNonAstroFile(path, changes);
75
+ service.updateNonAstroFile(path, changes, text);
76
76
  }
77
77
  });
78
78
  }
@@ -87,5 +87,11 @@ class LanguageServiceManager {
87
87
  async getTypeScriptLanguageService(filePath) {
88
88
  return (0, language_service_1.getLanguageService)(filePath, this.workspaceUris, this.docContext);
89
89
  }
90
+ /**
91
+ * @internal Public for tests only
92
+ */
93
+ async getSnapshotManager(filePath) {
94
+ return (await this.getTypeScriptLanguageService(filePath)).snapshotManager;
95
+ }
90
96
  }
91
97
  exports.LanguageServiceManager = LanguageServiceManager;
@@ -41,8 +41,12 @@ export declare class TypeScriptPlugin implements Plugin {
41
41
  findReferences(document: AstroDocument, position: Position, context: ReferenceContext): Promise<Location[] | null>;
42
42
  getDiagnostics(document: AstroDocument, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
43
43
  onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
44
- updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
44
+ updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[], text?: string): Promise<void>;
45
45
  getSignatureHelp(document: AstroDocument, position: Position, context: SignatureHelpContext | undefined, cancellationToken?: CancellationToken): Promise<SignatureHelp | null>;
46
46
  getTSXForDocument(document: AstroDocument): Astro2TSXResult;
47
+ /**
48
+ * @internal Public for tests only
49
+ */
50
+ getSnapshotManager(fileName: string): Promise<import("./snapshots/SnapshotManager").SnapshotManager>;
47
51
  private featureEnabled;
48
52
  }
@@ -132,7 +132,7 @@ class TypeScriptPlugin {
132
132
  let doneUpdateProjectFiles = false;
133
133
  for (const { fileName, changeType } of onWatchFileChangesParas) {
134
134
  const scriptKind = (0, utils_2.getScriptKindFromFileName)(fileName, this.ts);
135
- if (scriptKind === this.ts.ScriptKind.Unknown) {
135
+ if (scriptKind === this.ts.ScriptKind.Unknown && !(0, utils_2.isFrameworkFilePath)(fileName) && !(0, utils_2.isAstroFilePath)(fileName)) {
136
136
  continue;
137
137
  }
138
138
  if (changeType === vscode_languageserver_1.FileChangeType.Created && !doneUpdateProjectFiles) {
@@ -142,13 +142,14 @@ class TypeScriptPlugin {
142
142
  else if (changeType === vscode_languageserver_1.FileChangeType.Deleted) {
143
143
  await this.languageServiceManager.deleteSnapshot(fileName);
144
144
  }
145
- else {
145
+ else if (!(0, utils_2.isAstroFilePath)(fileName)) {
146
+ // Content updates for Astro files are handled through the documentManager and the 'documentChange' event
146
147
  await this.languageServiceManager.updateExistingNonAstroFile(fileName);
147
148
  }
148
149
  }
149
150
  }
150
- async updateNonAstroFile(fileName, changes) {
151
- await this.languageServiceManager.updateExistingNonAstroFile(fileName, changes);
151
+ async updateNonAstroFile(fileName, changes, text) {
152
+ await this.languageServiceManager.updateExistingNonAstroFile(fileName, changes, text);
152
153
  }
153
154
  async getSignatureHelp(document, position, context, cancellationToken) {
154
155
  return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
@@ -156,6 +157,12 @@ class TypeScriptPlugin {
156
157
  getTSXForDocument(document) {
157
158
  return (0, astro2tsx_1.default)(document.getText(), (0, utils_1.classNameFromFilename)(document.getURL()));
158
159
  }
160
+ /**
161
+ * @internal Public for tests only
162
+ */
163
+ getSnapshotManager(fileName) {
164
+ return this.languageServiceManager.getSnapshotManager(fileName);
165
+ }
159
166
  async featureEnabled(document, feature) {
160
167
  return ((await this.configManager.isEnabled(document, 'typescript')) &&
161
168
  (await this.configManager.isEnabled(document, 'typescript', feature)));
@@ -20,7 +20,7 @@ function createAstroSys(getSnapshot, ts) {
20
20
  return snapshot.getText(0, snapshot.getLength());
21
21
  },
22
22
  readDirectory(path, extensions, exclude, include, depth) {
23
- const extensionsWithAstro = (extensions ?? []).concat(...['.astro', '.svelte', '.vue']);
23
+ const extensionsWithAstro = (extensions ?? []).concat(...['.astro', '.svelte', '.vue', '.md', '.mdx', '.html']);
24
24
  const result = ts.sys.readDirectory(path, extensionsWithAstro, exclude, include, depth);
25
25
  return result;
26
26
  },
@@ -166,7 +166,8 @@ class CodeActionsProviderImpl {
166
166
  // Since our last line is a (virtual) export, organize imports will try to rewrite it, so let's only take
167
167
  // changes that actually happens inside the script tag
168
168
  .filter((change) => {
169
- return scriptTagSnapshot.isInGenerated(document.positionAt(change.span.start));
169
+ return (scriptTagSnapshot.isInGenerated(document.positionAt(change.span.start)) &&
170
+ !change.newText.includes('export { }'));
170
171
  });
171
172
  return edit;
172
173
  });
@@ -14,7 +14,7 @@ export interface LanguageServiceContainer {
14
14
  updateSnapshot(documentOrFilePath: AstroDocument | string, ts: typeof import('typescript/lib/tsserverlibrary')): DocumentSnapshot;
15
15
  deleteSnapshot(filePath: string): void;
16
16
  updateProjectFiles(): void;
17
- updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
17
+ updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[], text?: string): void;
18
18
  /**
19
19
  * Checks if a file is present in the project.
20
20
  * Unlike `fileBelongsToProject`, this doesn't run a file search on disk.
@@ -214,11 +214,11 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
214
214
  filePath = (0, utils_1.normalizePath)(filePath);
215
215
  return hasFile(filePath) || getParsedTSConfig().fileNames.includes(filePath);
216
216
  }
217
- function updateNonAstroFile(fileName, changes) {
217
+ function updateNonAstroFile(fileName, changes, text) {
218
218
  if (!snapshotManager.has(fileName)) {
219
219
  astroModuleLoader.deleteUnresolvedResolutionsFromCache(fileName);
220
220
  }
221
- snapshotManager.updateNonAstroFile(fileName, changes);
221
+ snapshotManager.updateNonAstroFile(fileName, changes, text);
222
222
  }
223
223
  function createScriptTagsSnapshots(fileName, document) {
224
224
  return document.scriptTags.map((scriptTag, index) => {
@@ -229,7 +229,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
229
229
  });
230
230
  }
231
231
  function createDocumentSymbolSnapshot(doc) {
232
- return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(doc.version, doc.filePath, doc.parent.getText(), docContext.ts.ScriptKind.Unknown);
232
+ return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(doc.version, doc.filePath, doc.parent.getText(), docContext.ts.ScriptKind.Unknown, false);
233
233
  }
234
234
  function getParsedTSConfig() {
235
235
  let configJson = (tsconfigPath && docContext.ts.readConfigFile(tsconfigPath, docContext.ts.sys.readFile).config) || {};
@@ -1,6 +1,5 @@
1
1
  import type { Position, TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
2
  import { AstroDocument, DocumentMapper, FragmentMapper, IdentityMapper, TagInformation } from '../../../core/documents';
3
- import type { FrameworkExt } from '../utils';
4
3
  export interface DocumentSnapshot extends ts.IScriptSnapshot {
5
4
  version: number;
6
5
  filePath: string;
@@ -92,10 +91,10 @@ export declare class TypeScriptDocumentSnapshot extends IdentityMapper implement
92
91
  version: number;
93
92
  readonly filePath: string;
94
93
  private text;
95
- readonly framework?: FrameworkExt | undefined;
94
+ readonly supportPartialUpdate: boolean;
96
95
  scriptKind: ts.ScriptKind;
97
96
  private lineOffsets?;
98
- constructor(version: number, filePath: string, text: string, scriptKind: ts.ScriptKind, framework?: FrameworkExt | undefined);
97
+ constructor(version: number, filePath: string, text: string, scriptKind: ts.ScriptKind, supportPartialUpdate: boolean);
99
98
  getText(start: number, end: number): string;
100
99
  getLength(): number;
101
100
  getFullText(): string;
@@ -119,12 +119,12 @@ exports.ScriptTagDocumentSnapshot = ScriptTagDocumentSnapshot;
119
119
  * It's both used for .js(x)/.ts(x) files and .svelte/.vue files
120
120
  */
121
121
  class TypeScriptDocumentSnapshot extends documents_1.IdentityMapper {
122
- constructor(version, filePath, text, scriptKind, framework) {
122
+ constructor(version, filePath, text, scriptKind, supportPartialUpdate) {
123
123
  super((0, utils_1.pathToUrl)(filePath));
124
124
  this.version = version;
125
125
  this.filePath = filePath;
126
126
  this.text = text;
127
- this.framework = framework;
127
+ this.supportPartialUpdate = supportPartialUpdate;
128
128
  this.scriptKind = scriptKind;
129
129
  }
130
130
  getText(start, end) {
@@ -13,7 +13,7 @@ export declare class GlobalSnapshotManager {
13
13
  get(fileName: string): DocumentSnapshot | undefined;
14
14
  set(fileName: string, document: DocumentSnapshot): void;
15
15
  delete(fileName: string): void;
16
- updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): TypeScriptDocumentSnapshot | undefined;
16
+ updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[], newText?: string): TypeScriptDocumentSnapshot | undefined;
17
17
  onChange(listener: (fileName: string, newDocument: DocumentSnapshot | undefined) => void): void;
18
18
  }
19
19
  export interface TsFilesSpec {
@@ -31,10 +31,9 @@ export declare class SnapshotManager {
31
31
  private ts;
32
32
  private documents;
33
33
  private lastLogged;
34
- private readonly watchExtensions;
35
34
  constructor(globalSnapshotsManager: GlobalSnapshotManager, projectFiles: string[], fileSpec: TsFilesSpec, workspaceRoot: string, ts: typeof import('typescript/lib/tsserverlibrary'));
36
35
  updateProjectFiles(): void;
37
- updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
36
+ updateNonAstroFile(fileName: string, changes?: TextDocumentContentChangeEvent[], text?: string): void;
38
37
  has(fileName: string): boolean;
39
38
  set(fileName: string, snapshot: DocumentSnapshot): void;
40
39
  get(fileName: string): DocumentSnapshot | undefined;
@@ -26,7 +26,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.SnapshotManager = exports.GlobalSnapshotManager = void 0;
27
27
  const events_1 = require("events");
28
28
  const utils_1 = require("../../../utils");
29
- const utils_2 = require("../utils");
30
29
  const DocumentSnapshot_1 = require("./DocumentSnapshot");
31
30
  const DocumentSnapshotUtils = __importStar(require("./utils"));
32
31
  /**
@@ -58,20 +57,17 @@ class GlobalSnapshotManager {
58
57
  this.documents.delete(fileName);
59
58
  this.emitter.emit('change', fileName, undefined);
60
59
  }
61
- updateNonAstroFile(fileName, changes) {
60
+ updateNonAstroFile(fileName, changes, newText) {
62
61
  fileName = (0, utils_1.normalizePath)(fileName);
63
62
  const previousSnapshot = this.get(fileName);
64
- if (changes) {
65
- // We don't support incremental changes for Framework files, as they need to be rebuilt completely on every change
66
- if (!(previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot) || previousSnapshot.framework) {
67
- return;
68
- }
63
+ const canBePartiallyUpdated = changes && previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot && previousSnapshot.supportPartialUpdate;
64
+ if (canBePartiallyUpdated) {
69
65
  previousSnapshot.update(changes);
70
66
  this.emitter.emit('change', fileName, previousSnapshot);
71
67
  return previousSnapshot;
72
68
  }
73
69
  else {
74
- const newSnapshot = DocumentSnapshotUtils.createFromNonAstroFilePath(fileName, this.ts);
70
+ const newSnapshot = DocumentSnapshotUtils.createFromNonAstroFilePath(fileName, this.ts, newText);
75
71
  if (previousSnapshot) {
76
72
  newSnapshot.version = previousSnapshot.version + 1;
77
73
  }
@@ -81,6 +77,7 @@ class GlobalSnapshotManager {
81
77
  newSnapshot.version += 1;
82
78
  }
83
79
  this.set(fileName, newSnapshot);
80
+ this.emitter.emit('change', fileName, newSnapshot);
84
81
  return newSnapshot;
85
82
  }
86
83
  }
@@ -101,14 +98,6 @@ class SnapshotManager {
101
98
  this.ts = ts;
102
99
  this.documents = new Map();
103
100
  this.lastLogged = new Date(new Date().getTime() - 60001);
104
- this.watchExtensions = [
105
- this.ts.Extension.Dts,
106
- this.ts.Extension.Js,
107
- this.ts.Extension.Jsx,
108
- this.ts.Extension.Ts,
109
- this.ts.Extension.Tsx,
110
- this.ts.Extension.Json,
111
- ];
112
101
  this.globalSnapshotsManager.onChange((fileName, document) => {
113
102
  // Only delete/update snapshots, don't add new ones,
114
103
  // as they could be from another TS service and this
@@ -131,12 +120,12 @@ class SnapshotManager {
131
120
  return;
132
121
  }
133
122
  const projectFiles = this.ts.sys
134
- .readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include)
123
+ .readDirectory(this.workspaceRoot, [...Object.values(this.ts.Extension), '.astro', '.svelte', '.vue'], exclude, include)
135
124
  .map(utils_1.normalizePath);
136
125
  this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
137
126
  }
138
- updateNonAstroFile(fileName, changes) {
139
- const snapshot = this.globalSnapshotsManager.updateNonAstroFile(fileName, changes);
127
+ updateNonAstroFile(fileName, changes, text) {
128
+ const snapshot = this.globalSnapshotsManager.updateNonAstroFile(fileName, changes, text);
140
129
  // This isn't duplicated logic to the listener, because this could
141
130
  // be a new snapshot which the listener wouldn't add.
142
131
  if (snapshot) {
@@ -181,8 +170,7 @@ class SnapshotManager {
181
170
  if (date.getTime() - this.lastLogged.getTime() > 60000) {
182
171
  this.lastLogged = date;
183
172
  const projectFiles = this.getProjectFileNames();
184
- let allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
185
- allFiles = allFiles.map((file) => (0, utils_2.ensureRealFilePath)(file));
173
+ const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
186
174
  // eslint-disable-next-line no-console
187
175
  console.log('SnapshotManager File Statistics:\n' +
188
176
  `Project files: ${projectFiles.length}\n` +
@@ -12,18 +12,18 @@ export declare function createFromFilePath(filePath: string, createDocument: (fi
12
12
  * Return a Framework or a TS snapshot from a file path, depending on the file contents
13
13
  * Unlike createFromFilePath, this does not support creating an Astro snapshot
14
14
  */
15
- export declare function createFromNonAstroFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
15
+ export declare function createFromNonAstroFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
16
16
  /**
17
17
  * Returns a ts/js snapshot from a file path.
18
18
  * @param filePath path to the js/ts file
19
19
  * @param options options that apply in case it's a svelte file
20
20
  */
21
- export declare function createFromTSFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
21
+ export declare function createFromTSFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
22
22
  /**
23
23
  * Returns an Astro snapshot from a file path.
24
24
  * @param filePath path to the Astro file
25
25
  * @param createDocument function that is used to create a document
26
26
  */
27
27
  export declare function createFromAstroFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot;
28
- export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
28
+ export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt, ts: typeof import('typescript/lib/tsserverlibrary'), forceText?: string): TypeScriptDocumentSnapshot;
29
29
  export declare function classNameFromFilename(filename: string): string;
@@ -38,13 +38,13 @@ exports.createFromFilePath = createFromFilePath;
38
38
  * Return a Framework or a TS snapshot from a file path, depending on the file contents
39
39
  * Unlike createFromFilePath, this does not support creating an Astro snapshot
40
40
  */
41
- function createFromNonAstroFilePath(filePath, ts) {
41
+ function createFromNonAstroFilePath(filePath, ts, forceText) {
42
42
  if ((0, utils_2.isFrameworkFilePath)(filePath)) {
43
43
  const framework = (0, utils_2.getFrameworkFromFilePath)(filePath);
44
- return createFromFrameworkFilePath(filePath, framework, ts);
44
+ return createFromFrameworkFilePath(filePath, framework, ts, forceText);
45
45
  }
46
46
  else {
47
- return createFromTSFilePath(filePath, ts);
47
+ return createFromTSFilePath(filePath, ts, forceText);
48
48
  }
49
49
  }
50
50
  exports.createFromNonAstroFilePath = createFromNonAstroFilePath;
@@ -53,9 +53,9 @@ exports.createFromNonAstroFilePath = createFromNonAstroFilePath;
53
53
  * @param filePath path to the js/ts file
54
54
  * @param options options that apply in case it's a svelte file
55
55
  */
56
- function createFromTSFilePath(filePath, ts) {
57
- const originalText = ts.sys.readFile(filePath) ?? '';
58
- return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, originalText, (0, utils_2.getScriptKindFromFileName)(filePath, ts));
56
+ function createFromTSFilePath(filePath, ts, forceText) {
57
+ const originalText = forceText ?? ts.sys.readFile(filePath) ?? '';
58
+ return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, originalText, (0, utils_2.getScriptKindFromFileName)(filePath, ts), true);
59
59
  }
60
60
  exports.createFromTSFilePath = createFromTSFilePath;
61
61
  /**
@@ -68,9 +68,9 @@ function createFromAstroFilePath(filePath, createDocument, ts) {
68
68
  return createFromDocument(createDocument(filePath, originalText), ts);
69
69
  }
70
70
  exports.createFromAstroFilePath = createFromAstroFilePath;
71
- function createFromFrameworkFilePath(filePath, framework, ts) {
71
+ function createFromFrameworkFilePath(filePath, framework, ts, forceText) {
72
72
  const className = classNameFromFilename(filePath);
73
- const originalText = ts.sys.readFile(filePath) ?? '';
73
+ const originalText = forceText ?? ts.sys.readFile(filePath) ?? '';
74
74
  let code = '';
75
75
  if (framework === 'svelte') {
76
76
  const svelteIntegration = (0, importPackage_1.importSvelteIntegration)(filePath);
@@ -84,7 +84,7 @@ function createFromFrameworkFilePath(filePath, framework, ts) {
84
84
  code = vueIntegration.toTSX(originalText, className);
85
85
  }
86
86
  }
87
- return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, ts.ScriptKind.TSX);
87
+ return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, ts.ScriptKind.TSX, false);
88
88
  }
89
89
  exports.createFromFrameworkFilePath = createFromFrameworkFilePath;
90
90
  function classNameFromFilename(filename) {
package/dist/server.js CHANGED
@@ -186,14 +186,14 @@ function startLanguageServer(connection, env) {
186
186
  });
187
187
  const diagnosticsManager = new DiagnosticsManager_1.DiagnosticsManager(connection.sendDiagnostics, documentManager, pluginHost.getDiagnostics.bind(pluginHost));
188
188
  const updateAllDiagnostics = (0, utils_2.debounceThrottle)(() => diagnosticsManager.updateAll(), 1000);
189
- connection.onDidChangeWatchedFiles((evt) => {
189
+ connection.onDidChangeWatchedFiles(async (evt) => {
190
190
  const params = evt.changes
191
191
  .map((change) => ({
192
192
  fileName: (0, utils_2.urlToPath)(change.uri),
193
193
  changeType: change.type,
194
194
  }))
195
195
  .filter((change) => !!change.fileName);
196
- pluginHost.onWatchFileChanges(params);
196
+ await pluginHost.onWatchFileChanges(params);
197
197
  updateAllDiagnostics();
198
198
  });
199
199
  // Features
@@ -230,7 +230,7 @@ function startLanguageServer(connection, env) {
230
230
  connection.onNotification('$/onDidChangeNonAstroFile', async (e) => {
231
231
  const path = (0, utils_2.urlToPath)(e.uri);
232
232
  if (path) {
233
- pluginHost.updateNonAstroFile(path, e.changes);
233
+ pluginHost.updateNonAstroFile(path, e.changes, e.text);
234
234
  }
235
235
  updateAllDiagnostics();
236
236
  });
@@ -242,12 +242,12 @@ function startLanguageServer(connection, env) {
242
242
  if (!doc) {
243
243
  return undefined;
244
244
  }
245
- if (doc) {
245
+ if (doc && typescriptPlugin) {
246
246
  const tsxOutput = typescriptPlugin.getTSXForDocument(doc);
247
247
  return tsxOutput.code;
248
248
  }
249
249
  });
250
- documentManager.on('documentChange', (0, utils_2.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
250
+ documentManager.on('documentChange', updateAllDiagnostics);
251
251
  documentManager.on('documentClose', (document) => {
252
252
  diagnosticsManager.removeDiagnostics(document);
253
253
  configManager.removeDocument(document.uri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",