@astrojs/ts-plugin 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -5
- package/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/dist/astro-snapshots.d.ts +44 -0
- package/dist/astro-sys.d.ts +6 -0
- package/dist/astro2tsx.d.ts +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/language-service/completions.d.ts +3 -0
- package/dist/language-service/definition.d.ts +3 -0
- package/dist/language-service/diagnostics.d.ts +7 -0
- package/dist/language-service/file-references.d.ts +3 -0
- package/dist/language-service/find-references.d.ts +4 -0
- package/dist/language-service/implementation.d.ts +3 -0
- package/dist/language-service/index.d.ts +5 -0
- package/dist/language-service/line-column-offset.d.ts +3 -0
- package/dist/language-service/rename.d.ts +4 -0
- package/dist/logger.d.ts +8 -0
- package/dist/module-loader.d.ts +13 -0
- package/dist/project-astro-files.d.ts +28 -0
- package/dist/utils.d.ts +16 -0
- package/package.json +18 -19
- package/src/astro-snapshots.ts +12 -3
- package/src/astro-sys.ts +4 -1
- package/src/astro2tsx.ts +20 -2
- package/src/index.ts +19 -4
- package/src/language-service/completions.ts +9 -1
- package/src/language-service/definition.ts +4 -1
- package/src/language-service/diagnostics.ts +4 -1
- package/src/language-service/file-references.ts +4 -1
- package/src/language-service/find-references.ts +5 -1
- package/src/language-service/implementation.ts +4 -1
- package/src/language-service/line-column-offset.ts +4 -1
- package/src/language-service/rename.ts +7 -3
- package/src/logger.ts +5 -1
- package/src/module-loader.ts +21 -5
- package/src/project-astro-files.ts +11 -3
- package/test/runTest.js +3 -1
- package/test/suite/extension.test.js +15 -5
- package/test/utils.js +5 -1
- package/dist/astro-snapshots.js +0 -251
- package/dist/astro-sys.js +0 -51
- package/dist/astro2tsx.js +0 -33
- package/dist/index.js +0 -57
- package/dist/language-service/completions.js +0 -82
- package/dist/language-service/definition.js +0 -58
- package/dist/language-service/diagnostics.js +0 -75
- package/dist/language-service/file-references.js +0 -52
- package/dist/language-service/find-references.js +0 -84
- package/dist/language-service/implementation.js +0 -52
- package/dist/language-service/index.js +0 -70
- package/dist/language-service/line-column-offset.js +0 -44
- package/dist/language-service/rename.js +0 -60
- package/dist/logger.js +0 -61
- package/dist/module-loader.js +0 -151
- package/dist/project-astro-files.js +0 -125
- package/dist/utils.js +0 -87
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
@astrojs/ts-plugin
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@astrojs/ts-plugin:build:
|
|
1
|
+
|
|
2
|
+
> @astrojs/ts-plugin@1.0.9 build /home/runner/work/language-tools/language-tools/packages/ts-plugin
|
|
3
|
+
> tsc
|
|
4
|
+
|
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 The Astro Technology Company
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TraceMap } from '@jridgewell/trace-mapping';
|
|
2
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import type { Logger } from './logger.js';
|
|
4
|
+
export declare class AstroSnapshot {
|
|
5
|
+
private typescript;
|
|
6
|
+
private fileName;
|
|
7
|
+
private astroCode;
|
|
8
|
+
private traceMap;
|
|
9
|
+
private logger;
|
|
10
|
+
private scriptInfo?;
|
|
11
|
+
private lineOffsets?;
|
|
12
|
+
private convertInternalCodePositions;
|
|
13
|
+
constructor(typescript: typeof ts, fileName: string, astroCode: string, traceMap: TraceMap, logger: Logger);
|
|
14
|
+
update(astroCode: string, traceMap: TraceMap): void;
|
|
15
|
+
getOriginalTextSpan(textSpan: ts.TextSpan): ts.TextSpan | null;
|
|
16
|
+
getOriginalOffset(generatedOffset: number): number;
|
|
17
|
+
setAndPatchScriptInfo(scriptInfo: ts.server.ScriptInfo): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get the line and character based on the offset
|
|
20
|
+
* @param offset The index of the position
|
|
21
|
+
*/
|
|
22
|
+
positionAt(offset: number): ts.LineAndCharacter;
|
|
23
|
+
/**
|
|
24
|
+
* Get the index of the line and character position
|
|
25
|
+
* @param position Line and character position
|
|
26
|
+
*/
|
|
27
|
+
offsetAt(position: ts.LineAndCharacter): number;
|
|
28
|
+
private getLineOffsets;
|
|
29
|
+
private clamp;
|
|
30
|
+
private log;
|
|
31
|
+
private debug;
|
|
32
|
+
private toggleMappingMode;
|
|
33
|
+
private getText;
|
|
34
|
+
}
|
|
35
|
+
export declare class AstroSnapshotManager {
|
|
36
|
+
private typescript;
|
|
37
|
+
private projectService;
|
|
38
|
+
private logger;
|
|
39
|
+
private snapshots;
|
|
40
|
+
constructor(typescript: typeof ts, projectService: ts.server.ProjectService, logger: Logger);
|
|
41
|
+
get(fileName: string): AstroSnapshot | undefined;
|
|
42
|
+
create(fileName: string): AstroSnapshot | undefined;
|
|
43
|
+
private patchProjectServiceReadFile;
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { Logger } from './logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* This should only be accessed by TS astro module resolution.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createAstroSys(logger: Logger, typescript: typeof import('typescript/lib/tsserverlibrary')): ts.System;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
declare function init(modules: {
|
|
3
|
+
typescript: typeof import('typescript/lib/tsserverlibrary');
|
|
4
|
+
}): {
|
|
5
|
+
create: (info: ts.server.PluginCreateInfo) => ts.LanguageService;
|
|
6
|
+
getExternalFiles: (project: ts.server.ConfiguredProject) => string[];
|
|
7
|
+
};
|
|
8
|
+
export = init;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
3
|
+
import type { Logger } from '../logger';
|
|
4
|
+
export declare function decorateFindReferences(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager, logger: Logger): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
3
|
+
import type { Logger } from '../logger';
|
|
4
|
+
export declare function isPatched(ls: ts.LanguageService): boolean;
|
|
5
|
+
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager, ts: typeof import('typescript/lib/tsserverlibrary'), logger: Logger): ts.LanguageService;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
3
|
+
import type { Logger } from '../logger.js';
|
|
4
|
+
export declare function decorateRename(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager, logger: Logger): void;
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
export declare class Logger {
|
|
3
|
+
private tsLogService;
|
|
4
|
+
private logDebug;
|
|
5
|
+
constructor(tsLogService: ts.server.Logger, suppressNonAstroLogs?: boolean, logDebug?: boolean);
|
|
6
|
+
log(...args: any[]): void;
|
|
7
|
+
debug(...args: any[]): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { AstroSnapshotManager } from './astro-snapshots.js';
|
|
3
|
+
import type { Logger } from './logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a module loader than can also resolve `.astro` files.
|
|
6
|
+
*
|
|
7
|
+
* The typescript language service tries to look up other files that are referenced in the currently open astro file.
|
|
8
|
+
* For `.ts`/`.js` files this works, for `.astro` files it does not by default.
|
|
9
|
+
* Reason: The typescript language service does not know about the `.astro` file ending,
|
|
10
|
+
* so it assumes it's a normal typescript file and searches for files like `../Component.astro.ts`, which is wrong.
|
|
11
|
+
* In order to fix this, we need to wrap typescript's module resolution and reroute all `.astro.ts` file lookups to .astro.
|
|
12
|
+
*/
|
|
13
|
+
export declare function patchModuleLoader(logger: Logger, snapshotManager: AstroSnapshotManager, typescript: typeof ts, lsHost: ts.LanguageServiceHost, project: ts.server.Project): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { AstroSnapshotManager } from './astro-snapshots';
|
|
3
|
+
export declare class ProjectAstroFilesManager {
|
|
4
|
+
private readonly typescript;
|
|
5
|
+
private readonly project;
|
|
6
|
+
private readonly serverHost;
|
|
7
|
+
private readonly snapshotManager;
|
|
8
|
+
private parsedCommandLine;
|
|
9
|
+
private files;
|
|
10
|
+
private directoryWatchers;
|
|
11
|
+
private static instances;
|
|
12
|
+
static getInstance(projectName: string): ProjectAstroFilesManager | undefined;
|
|
13
|
+
constructor(typescript: typeof ts, project: ts.server.Project, serverHost: ts.server.ServerHost, snapshotManager: AstroSnapshotManager, parsedCommandLine: ts.ParsedCommandLine);
|
|
14
|
+
updateProjectConfig(serviceHost: ts.LanguageServiceHost): void;
|
|
15
|
+
getFiles(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Create directory watcher for include and exclude
|
|
18
|
+
* The watcher in tsserver doesn't support astro file
|
|
19
|
+
* It won't add new created astro file to root
|
|
20
|
+
*/
|
|
21
|
+
private setupWatchers;
|
|
22
|
+
private watcherCallback;
|
|
23
|
+
private updateProjectAstroFiles;
|
|
24
|
+
private addFileToProject;
|
|
25
|
+
private removeFileFromProject;
|
|
26
|
+
private disposeWatchersAndFiles;
|
|
27
|
+
dispose(): void;
|
|
28
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
export declare function isAstroFilePath(filePath: string): boolean;
|
|
3
|
+
export declare function isVirtualAstroFilePath(filePath: string): boolean;
|
|
4
|
+
export declare function toRealAstroFilePath(filePath: string): string;
|
|
5
|
+
export declare function ensureRealAstroFilePath(filePath: string): string;
|
|
6
|
+
export declare function isNotNullOrUndefined<T>(val: T | undefined | null): val is T;
|
|
7
|
+
/**
|
|
8
|
+
* Replace all occurrences of a string within an object with another string,
|
|
9
|
+
*/
|
|
10
|
+
export declare function replaceDeep<T extends Record<string, any>>(obj: T, searchStr: string | RegExp, replacementStr: string): T;
|
|
11
|
+
export declare function getConfigPathForProject(project: ts.server.Project): ts.server.NormalizedPath;
|
|
12
|
+
export declare function readProjectAstroFilesFromFs(ts: typeof import('typescript/lib/tsserverlibrary'), project: ts.server.Project, parsedCommandLine: ts.ParsedCommandLine): ts.server.NormalizedPath[];
|
|
13
|
+
export interface TsFilesSpec {
|
|
14
|
+
include?: readonly string[];
|
|
15
|
+
exclude?: readonly string[];
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/ts-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A TypeScript Plugin providing Astro intellisense",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/withastro/language-tools",
|
|
10
|
+
"directory": "packages/ts-plugin"
|
|
11
|
+
},
|
|
7
12
|
"keywords": [
|
|
8
13
|
"astro",
|
|
9
14
|
"typescript",
|
|
@@ -13,29 +18,23 @@
|
|
|
13
18
|
"author": "withastro",
|
|
14
19
|
"license": "MIT",
|
|
15
20
|
"dependencies": {
|
|
16
|
-
"@astrojs/compiler": "^1.
|
|
17
|
-
"@jridgewell/trace-mapping": "^0.3.
|
|
21
|
+
"@astrojs/compiler": "^1.5.1",
|
|
22
|
+
"@jridgewell/trace-mapping": "^0.3.18"
|
|
18
23
|
},
|
|
19
24
|
"devDependencies": {
|
|
20
|
-
"@types/chai": "^4.3.
|
|
21
|
-
"@types/mocha": "^
|
|
22
|
-
"@types/node": "^16.
|
|
23
|
-
"@types/vscode": "
|
|
24
|
-
"@vscode/test-electron": "^2.
|
|
25
|
-
"
|
|
26
|
-
"chai": "^4.3.6",
|
|
25
|
+
"@types/chai": "^4.3.5",
|
|
26
|
+
"@types/mocha": "^10.0.1",
|
|
27
|
+
"@types/node": "^16.18.26",
|
|
28
|
+
"@types/vscode": "1.67.0",
|
|
29
|
+
"@vscode/test-electron": "^2.3.2",
|
|
30
|
+
"chai": "^4.3.7",
|
|
27
31
|
"glob": "^8.0.3",
|
|
28
|
-
"mocha": "^
|
|
29
|
-
"typescript": "~5.
|
|
30
|
-
},
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "https://github.com/withastro/language-tools",
|
|
34
|
-
"directory": "packages/ts-plugin"
|
|
32
|
+
"mocha": "^10.2.0",
|
|
33
|
+
"typescript": "~5.1.3"
|
|
35
34
|
},
|
|
36
35
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
"dev": "
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"dev": "tsc --watch",
|
|
39
38
|
"test": "node ./test/runTest.js"
|
|
40
39
|
}
|
|
41
40
|
}
|
package/src/astro-snapshots.ts
CHANGED
|
@@ -139,7 +139,9 @@ export class AstroSnapshot {
|
|
|
139
139
|
|
|
140
140
|
const lineOffset = lineOffsets[position.line];
|
|
141
141
|
const nextLineOffset =
|
|
142
|
-
position.line + 1 < lineOffsets.length
|
|
142
|
+
position.line + 1 < lineOffsets.length
|
|
143
|
+
? lineOffsets[position.line + 1]
|
|
144
|
+
: this.astroCode.length;
|
|
143
145
|
|
|
144
146
|
return this.clamp(nextLineOffset, lineOffset, lineOffset + position.character);
|
|
145
147
|
}
|
|
@@ -201,7 +203,11 @@ export class AstroSnapshot {
|
|
|
201
203
|
export class AstroSnapshotManager {
|
|
202
204
|
private snapshots = new Map<string, AstroSnapshot>();
|
|
203
205
|
|
|
204
|
-
constructor(
|
|
206
|
+
constructor(
|
|
207
|
+
private typescript: typeof ts,
|
|
208
|
+
private projectService: ts.server.ProjectService,
|
|
209
|
+
private logger: Logger
|
|
210
|
+
) {
|
|
205
211
|
this.patchProjectServiceReadFile();
|
|
206
212
|
}
|
|
207
213
|
|
|
@@ -231,7 +237,10 @@ export class AstroSnapshotManager {
|
|
|
231
237
|
}
|
|
232
238
|
const snapshot = this.snapshots.get(fileName);
|
|
233
239
|
if (!snapshot) {
|
|
234
|
-
this.logger.log(
|
|
240
|
+
this.logger.log(
|
|
241
|
+
'Astro snapshot was not found after trying to load script snapshot for',
|
|
242
|
+
fileName
|
|
243
|
+
);
|
|
235
244
|
return; // should never get here
|
|
236
245
|
}
|
|
237
246
|
snapshot.setAndPatchScriptInfo(scriptInfo);
|
package/src/astro-sys.ts
CHANGED
|
@@ -5,7 +5,10 @@ import { ensureRealAstroFilePath, isVirtualAstroFilePath, toRealAstroFilePath }
|
|
|
5
5
|
/**
|
|
6
6
|
* This should only be accessed by TS astro module resolution.
|
|
7
7
|
*/
|
|
8
|
-
export function createAstroSys(
|
|
8
|
+
export function createAstroSys(
|
|
9
|
+
logger: Logger,
|
|
10
|
+
typescript: typeof import('typescript/lib/tsserverlibrary')
|
|
11
|
+
) {
|
|
9
12
|
const astroSys: ts.System = {
|
|
10
13
|
...typescript.sys,
|
|
11
14
|
fileExists(path: string) {
|
package/src/astro2tsx.ts
CHANGED
|
@@ -2,7 +2,25 @@ import { convertToTSX } from '@astrojs/compiler/sync';
|
|
|
2
2
|
import type { TSXResult } from '@astrojs/compiler/types';
|
|
3
3
|
|
|
4
4
|
export function astro2tsx(content: string, fileName: string): TSXResult {
|
|
5
|
-
|
|
5
|
+
try {
|
|
6
|
+
const tsx = convertToTSX(content, { filename: fileName });
|
|
7
|
+
return tsx;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
console.error(
|
|
10
|
+
`There was an error transforming ${fileName} to TSX. An empty file will be returned instead. Please create an issue: https://github.com/withastro/language-tools/issues\nError: ${e}.`
|
|
11
|
+
);
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
return {
|
|
14
|
+
code: '',
|
|
15
|
+
map: {
|
|
16
|
+
file: fileName,
|
|
17
|
+
sources: [],
|
|
18
|
+
sourcesContent: [],
|
|
19
|
+
names: [],
|
|
20
|
+
mappings: '',
|
|
21
|
+
version: 0,
|
|
22
|
+
},
|
|
23
|
+
diagnostics: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
8
26
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,9 @@ function init(modules: { typescript: typeof import('typescript/lib/tsserverlibra
|
|
|
11
11
|
|
|
12
12
|
function create(info: ts.server.PluginCreateInfo): ts.LanguageService {
|
|
13
13
|
const logger = new Logger(info.project.projectService.logger);
|
|
14
|
-
const parsedCommandLine = info.languageServiceHost.getParsedCommandLine?.(
|
|
14
|
+
const parsedCommandLine = info.languageServiceHost.getParsedCommandLine?.(
|
|
15
|
+
getConfigPathForProject(info.project)
|
|
16
|
+
);
|
|
15
17
|
|
|
16
18
|
if (!isAstroProject(info.project, parsedCommandLine)) {
|
|
17
19
|
logger.log('Detected that this is not an Astro project, abort patching TypeScript');
|
|
@@ -24,7 +26,11 @@ function init(modules: { typescript: typeof import('typescript/lib/tsserverlibra
|
|
|
24
26
|
|
|
25
27
|
logger.log('Starting Astro plugin');
|
|
26
28
|
|
|
27
|
-
const snapshotManager = new AstroSnapshotManager(
|
|
29
|
+
const snapshotManager = new AstroSnapshotManager(
|
|
30
|
+
modules.typescript,
|
|
31
|
+
info.project.projectService,
|
|
32
|
+
logger
|
|
33
|
+
);
|
|
28
34
|
if (parsedCommandLine) {
|
|
29
35
|
new ProjectAstroFilesManager(
|
|
30
36
|
modules.typescript,
|
|
@@ -35,7 +41,13 @@ function init(modules: { typescript: typeof import('typescript/lib/tsserverlibra
|
|
|
35
41
|
);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
patchModuleLoader(
|
|
44
|
+
patchModuleLoader(
|
|
45
|
+
logger,
|
|
46
|
+
snapshotManager,
|
|
47
|
+
modules.typescript,
|
|
48
|
+
info.languageServiceHost,
|
|
49
|
+
info.project
|
|
50
|
+
);
|
|
39
51
|
return decorateLanguageService(info.languageService, snapshotManager, ts, logger);
|
|
40
52
|
}
|
|
41
53
|
|
|
@@ -43,7 +55,10 @@ function init(modules: { typescript: typeof import('typescript/lib/tsserverlibra
|
|
|
43
55
|
return ProjectAstroFilesManager.getInstance(project.getProjectName())?.getFiles() ?? [];
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
function isAstroProject(
|
|
58
|
+
function isAstroProject(
|
|
59
|
+
project: ts.server.Project,
|
|
60
|
+
parsedCommandLine: ts.ParsedCommandLine | undefined
|
|
61
|
+
) {
|
|
47
62
|
if (parsedCommandLine) {
|
|
48
63
|
const astroFiles = readProjectAstroFilesFromFs(ts, project, parsedCommandLine);
|
|
49
64
|
|
|
@@ -26,7 +26,15 @@ export function decorateCompletions(ls: ts.LanguageService, logger: Logger): voi
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
29
|
-
ls.getCompletionEntryDetails = (
|
|
29
|
+
ls.getCompletionEntryDetails = (
|
|
30
|
+
fileName,
|
|
31
|
+
position,
|
|
32
|
+
entryName,
|
|
33
|
+
formatOptions,
|
|
34
|
+
source,
|
|
35
|
+
preferences,
|
|
36
|
+
data
|
|
37
|
+
) => {
|
|
30
38
|
if (!isAstroFilePath(source || '')) {
|
|
31
39
|
const details = getCompletionEntryDetails(
|
|
32
40
|
fileName,
|
|
@@ -2,7 +2,10 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import type { AstroSnapshotManager } from '../astro-snapshots';
|
|
3
3
|
import { isAstroFilePath, isNotNullOrUndefined } from '../utils';
|
|
4
4
|
|
|
5
|
-
export function decorateGetDefinition(
|
|
5
|
+
export function decorateGetDefinition(
|
|
6
|
+
ls: ts.LanguageService,
|
|
7
|
+
snapshotManager: AstroSnapshotManager
|
|
8
|
+
): void {
|
|
6
9
|
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan;
|
|
7
10
|
ls.getDefinitionAndBoundSpan = (fileName, position) => {
|
|
8
11
|
const definition = getDefinitionAndBoundSpan(fileName, position);
|
|
@@ -36,7 +36,10 @@ function decorateSemanticDiagnostics(ls: ts.LanguageService, typescript: _ts): v
|
|
|
36
36
|
|
|
37
37
|
let diagnostics = getSemanticDiagnostics(fileName);
|
|
38
38
|
diagnostics = diagnostics.map((diag) => {
|
|
39
|
-
const message = typescript.flattenDiagnosticMessageText(
|
|
39
|
+
const message = typescript.flattenDiagnosticMessageText(
|
|
40
|
+
diag.messageText,
|
|
41
|
+
typescript.sys.newLine
|
|
42
|
+
);
|
|
40
43
|
if (
|
|
41
44
|
diag.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
|
|
42
45
|
message.includes('astro:content') &&
|
|
@@ -2,7 +2,10 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
3
3
|
import { isAstroFilePath, isNotNullOrUndefined } from '../utils.js';
|
|
4
4
|
|
|
5
|
-
export function decorateGetFileReferences(
|
|
5
|
+
export function decorateGetFileReferences(
|
|
6
|
+
ls: ts.LanguageService,
|
|
7
|
+
snapshotManager: AstroSnapshotManager
|
|
8
|
+
): void {
|
|
6
9
|
const getFileReferences = ls.getFileReferences;
|
|
7
10
|
ls.getFileReferences = (fileName) => {
|
|
8
11
|
const references = getFileReferences(fileName);
|
|
@@ -12,7 +12,11 @@ export function decorateFindReferences(
|
|
|
12
12
|
_decorateFindReferences(ls, snapshotManager, logger);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function _decorateFindReferences(
|
|
15
|
+
function _decorateFindReferences(
|
|
16
|
+
ls: ts.LanguageService,
|
|
17
|
+
snapshotManager: AstroSnapshotManager,
|
|
18
|
+
logger: Logger
|
|
19
|
+
) {
|
|
16
20
|
const findReferences = ls.findReferences;
|
|
17
21
|
ls.findReferences = (fileName, position) => {
|
|
18
22
|
const references = findReferences(fileName, position);
|
|
@@ -2,7 +2,10 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
3
3
|
import { isAstroFilePath, isNotNullOrUndefined } from '../utils.js';
|
|
4
4
|
|
|
5
|
-
export function decorateGetImplementation(
|
|
5
|
+
export function decorateGetImplementation(
|
|
6
|
+
ls: ts.LanguageService,
|
|
7
|
+
snapshotManager: AstroSnapshotManager
|
|
8
|
+
): void {
|
|
6
9
|
const getImplementationAtPosition = ls.getImplementationAtPosition;
|
|
7
10
|
ls.getImplementationAtPosition = (fileName, position) => {
|
|
8
11
|
const implementation = getImplementationAtPosition(fileName, position);
|
|
@@ -2,7 +2,10 @@ import type ts from 'typescript/lib/tsserverlibrary';
|
|
|
2
2
|
import type { AstroSnapshotManager } from '../astro-snapshots';
|
|
3
3
|
import { isAstroFilePath } from '../utils';
|
|
4
4
|
|
|
5
|
-
export function decorateLineColumnOffset(
|
|
5
|
+
export function decorateLineColumnOffset(
|
|
6
|
+
ls: ts.LanguageService,
|
|
7
|
+
snapshotManager: AstroSnapshotManager
|
|
8
|
+
) {
|
|
6
9
|
if (!ls.toLineColumnOffset) {
|
|
7
10
|
return;
|
|
8
11
|
}
|
|
@@ -3,15 +3,19 @@ import type { AstroSnapshotManager } from '../astro-snapshots.js';
|
|
|
3
3
|
import type { Logger } from '../logger.js';
|
|
4
4
|
import { isAstroFilePath, isNotNullOrUndefined } from '../utils.js';
|
|
5
5
|
|
|
6
|
-
export function decorateRename(
|
|
6
|
+
export function decorateRename(
|
|
7
|
+
ls: ts.LanguageService,
|
|
8
|
+
snapshotManager: AstroSnapshotManager,
|
|
9
|
+
logger: Logger
|
|
10
|
+
): void {
|
|
7
11
|
const findRenameLocations = ls.findRenameLocations;
|
|
8
|
-
ls.findRenameLocations = (fileName, position, findInStrings, findInComments,
|
|
12
|
+
ls.findRenameLocations = (fileName, position, findInStrings, findInComments, preferences) => {
|
|
9
13
|
const renameLocations = findRenameLocations(
|
|
10
14
|
fileName,
|
|
11
15
|
position,
|
|
12
16
|
findInStrings,
|
|
13
17
|
findInComments,
|
|
14
|
-
|
|
18
|
+
preferences as ts.UserPreferences
|
|
15
19
|
);
|
|
16
20
|
return renameLocations
|
|
17
21
|
?.map((renameLocation) => {
|
package/src/logger.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
|
|
3
3
|
export class Logger {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(
|
|
5
|
+
private tsLogService: ts.server.Logger,
|
|
6
|
+
suppressNonAstroLogs = false,
|
|
7
|
+
private logDebug = false
|
|
8
|
+
) {
|
|
5
9
|
if (suppressNonAstroLogs) {
|
|
6
10
|
const log = this.tsLogService.info.bind(this.tsLogService);
|
|
7
11
|
this.tsLogService.info = (s: string) => {
|
package/src/module-loader.ts
CHANGED
|
@@ -20,7 +20,11 @@ class ModuleResolutionCache {
|
|
|
20
20
|
/**
|
|
21
21
|
* Caches resolved module, if it is not undefined.
|
|
22
22
|
*/
|
|
23
|
-
set(
|
|
23
|
+
set(
|
|
24
|
+
moduleName: string,
|
|
25
|
+
containingFile: string,
|
|
26
|
+
resolvedModule: ts.ResolvedModuleFull | undefined
|
|
27
|
+
) {
|
|
24
28
|
if (!resolvedModule) {
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
@@ -99,8 +103,13 @@ export function patchModuleLoader(
|
|
|
99
103
|
// astro file and if so, are resolved, too. This way we can defer
|
|
100
104
|
// all module resolving logic except for astro files to TypeScript.
|
|
101
105
|
const resolved =
|
|
102
|
-
origResolveModuleNames?.(
|
|
103
|
-
|
|
106
|
+
origResolveModuleNames?.(
|
|
107
|
+
moduleNames,
|
|
108
|
+
containingFile,
|
|
109
|
+
reusedNames,
|
|
110
|
+
redirectedReference,
|
|
111
|
+
compilerOptions
|
|
112
|
+
) || Array.from<undefined>(Array(moduleNames.length));
|
|
104
113
|
|
|
105
114
|
return resolved.map((moduleName, idx) => {
|
|
106
115
|
const fileName = moduleNames[idx];
|
|
@@ -178,7 +187,10 @@ export function patchModuleLoader(
|
|
|
178
187
|
|
|
179
188
|
return resolved.map((tsResolvedModule, idx) => {
|
|
180
189
|
const moduleName = moduleLiterals[idx].text;
|
|
181
|
-
if (
|
|
190
|
+
if (
|
|
191
|
+
tsResolvedModule.resolvedModule ||
|
|
192
|
+
!ensureRealAstroFilePath(moduleName).endsWith('.astro')
|
|
193
|
+
) {
|
|
182
194
|
return tsResolvedModule;
|
|
183
195
|
}
|
|
184
196
|
|
|
@@ -186,7 +198,11 @@ export function patchModuleLoader(
|
|
|
186
198
|
});
|
|
187
199
|
}
|
|
188
200
|
|
|
189
|
-
function resolveAstroModuleNameFromCache(
|
|
201
|
+
function resolveAstroModuleNameFromCache(
|
|
202
|
+
moduleName: string,
|
|
203
|
+
containingFile: string,
|
|
204
|
+
options: ts.CompilerOptions
|
|
205
|
+
) {
|
|
190
206
|
const cachedModule = moduleCache.get(moduleName, containingFile);
|
|
191
207
|
if (cachedModule) {
|
|
192
208
|
return {
|
|
@@ -26,7 +26,9 @@ export class ProjectAstroFilesManager {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
updateProjectConfig(serviceHost: ts.LanguageServiceHost) {
|
|
29
|
-
const parsedCommandLine = serviceHost.getParsedCommandLine?.(
|
|
29
|
+
const parsedCommandLine = serviceHost.getParsedCommandLine?.(
|
|
30
|
+
getConfigPathForProject(this.project)
|
|
31
|
+
);
|
|
30
32
|
|
|
31
33
|
if (!parsedCommandLine) {
|
|
32
34
|
return;
|
|
@@ -49,7 +51,9 @@ export class ProjectAstroFilesManager {
|
|
|
49
51
|
*/
|
|
50
52
|
private setupWatchers() {
|
|
51
53
|
for (const directory in this.parsedCommandLine.wildcardDirectories) {
|
|
52
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
!Object.prototype.hasOwnProperty.call(this.parsedCommandLine.wildcardDirectories, directory)
|
|
56
|
+
) {
|
|
53
57
|
continue;
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -77,7 +81,11 @@ export class ProjectAstroFilesManager {
|
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
private updateProjectAstroFiles() {
|
|
80
|
-
const fileNamesAfter = readProjectAstroFilesFromFs(
|
|
84
|
+
const fileNamesAfter = readProjectAstroFilesFromFs(
|
|
85
|
+
this.typescript,
|
|
86
|
+
this.project,
|
|
87
|
+
this.parsedCommandLine
|
|
88
|
+
);
|
|
81
89
|
const removedFiles = new Set(...this.files);
|
|
82
90
|
const newFiles = fileNamesAfter.filter((fileName) => {
|
|
83
91
|
const has = this.files.has(fileName);
|